From 470285eb95ab8b07014284fac03fbfa8b6eabee4 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Tue, 29 Nov 2022 14:42:04 -0500 Subject: [PATCH 1/3] Support `--flag=value` syntax for manually-parsed CLI args --- src/cli.js | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/cli.js b/src/cli.js index b2199e00c707..05429d159527 100644 --- a/src/cli.js +++ b/src/cli.js @@ -159,8 +159,8 @@ let args = (() => { let flag = result['_'][i] if (!flag.startsWith('-')) continue - let flagName = flag - let handler = flags[flag] + let [flagName, flagValue] = flag.split('=') + let handler = flags[flagName] // Resolve flagName & handler while (typeof handler === 'string') { @@ -173,19 +173,27 @@ let args = (() => { let args = [] let offset = i + 1 - // Parse args for current flag - while (result['_'][offset] && !result['_'][offset].startsWith('-')) { - args.push(result['_'][offset++]) - } + // --flag value syntax was used so we need to pull `value` from `args` + if (flagValue === undefined) { + // Parse args for current flag + while (result['_'][offset] && !result['_'][offset].startsWith('-')) { + args.push(result['_'][offset++]) + } - // Cleanup manually parsed flags + args - result['_'].splice(i, 1 + args.length) + // Cleanup manually parsed flags + args + result['_'].splice(i, 1 + args.length) + + // No args were provided, use default value defined in handler + // One arg was provided, use that directly + // Multiple args were provided so pass them all in an array + flagValue = args.length === 0 ? undefined : args.length === 1 ? args[0] : args + } else { + // Remove the whole flag from the args array + result['_'].splice(i, 1) + } // Set the resolved value in the `result` object - result[flagName] = handler.type( - args.length === 0 ? undefined : args.length === 1 ? args[0] : args, - flagName - ) + result[flagName] = handler.type(flagValue, flagName) } // Ensure that the `command` is always the first argument in the `args`. From 8a7432624ef27fb4297376577e395c9421878496 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Tue, 29 Nov 2022 14:50:54 -0500 Subject: [PATCH 2/3] =?UTF-8?q?Don=E2=80=99t=20exit=20when=20stdin=20close?= =?UTF-8?q?s=20if=20using=20`--watch=3Dalways`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cli.js | 5 ++++- src/cli/build/index.js | 8 ++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/cli.js b/src/cli.js index 05429d159527..fbc2d20853bb 100644 --- a/src/cli.js +++ b/src/cli.js @@ -62,7 +62,10 @@ let commands = { args: { '--input': { type: String, description: 'Input file' }, '--output': { type: String, description: 'Output file' }, - '--watch': { type: Boolean, description: 'Watch for changes and rebuild as needed' }, + '--watch': { + type: oneOf(String, Boolean), + description: 'Watch for changes and rebuild as needed', + }, '--poll': { type: Boolean, description: 'Use polling instead of filesystem events when watching', diff --git a/src/cli/build/index.js b/src/cli/build/index.js index 763b3d56b75a..c75b719da8eb 100644 --- a/src/cli/build/index.js +++ b/src/cli/build/index.js @@ -34,8 +34,12 @@ export async function build(args, configs) { let processor = await createProcessor(args, configPath) if (shouldWatch) { - /* Abort the watcher if stdin is closed to avoid zombie processes */ - process.stdin.on('end', () => process.exit(0)) + // Abort the watcher if stdin is closed to avoid zombie processes + // You can disable this behavior with --watch=always + if (args['--watch'] !== 'always') { + process.stdin.on('end', () => process.exit(0)) + } + process.stdin.resume() await processor.watch() From 057f2d4ab9a077a6805d71eb591eee8dd8edf252 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Tue, 29 Nov 2022 14:48:41 -0500 Subject: [PATCH 3/3] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 71e59f1c2719..afeecbb539ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add `line-height` modifier support to `font-size` utilities ([#9875](https://github.com/tailwindlabs/tailwindcss/pull/9875)) - Support using variables as arbitrary values without `var(...)` ([#9880](https://github.com/tailwindlabs/tailwindcss/pull/9880)) +- Add `--watch=always` option to prevent exit when stdin closes ([#9966](https://github.com/tailwindlabs/tailwindcss/pull/9966)) ### Fixed