Skip to content

Commit f741b39

Browse files
committed
Don’t exit when stdin closes if using --watch=always
1 parent 4e31d6d commit f741b39

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

src/cli.js

+10-7
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ let commands = {
6262
args: {
6363
'--input': { type: String, description: 'Input file' },
6464
'--output': { type: String, description: 'Output file' },
65-
'--watch': { type: Boolean, description: 'Watch for changes and rebuild as needed' },
65+
'--watch': {
66+
type: oneOf(String, Boolean),
67+
description: 'Watch for changes and rebuild as needed',
68+
},
6669
'--poll': {
6770
type: Boolean,
6871
description: 'Use polling instead of filesystem events when watching',
@@ -175,13 +178,13 @@ let args = (() => {
175178

176179
// --flag value syntax was used so we need to pull `value` from `args`
177180
if (flagValue === undefined) {
178-
// Parse args for current flag
179-
while (result['_'][offset] && !result['_'][offset].startsWith('-')) {
180-
args.push(result['_'][offset++])
181-
}
181+
// Parse args for current flag
182+
while (result['_'][offset] && !result['_'][offset].startsWith('-')) {
183+
args.push(result['_'][offset++])
184+
}
182185

183-
// Cleanup manually parsed flags + args
184-
result['_'].splice(i, 1 + args.length)
186+
// Cleanup manually parsed flags + args
187+
result['_'].splice(i, 1 + args.length)
185188

186189
// No args were provided, use default value defined in handler
187190
// One arg was provided, use that directly

src/cli/build/index.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,12 @@ export async function build(args, configs) {
3434
let processor = await createProcessor(args, configPath)
3535

3636
if (shouldWatch) {
37-
/* Abort the watcher if stdin is closed to avoid zombie processes */
38-
process.stdin.on('end', () => process.exit(0))
37+
// Abort the watcher if stdin is closed to avoid zombie processes
38+
// You can disable this behavior with --watch=always
39+
if (args['--watch'] !== 'always') {
40+
process.stdin.on('end', () => process.exit(0))
41+
}
42+
3943
process.stdin.resume()
4044

4145
await processor.watch()

0 commit comments

Comments
 (0)