diff --git a/index.js b/index.js index 615638c..da052ce 100755 --- a/index.js +++ b/index.js @@ -61,7 +61,13 @@ let configFile if (argv.env) process.env.NODE_ENV = argv.env if (argv.config) argv.config = path.resolve(argv.config) -if (argv.watch) { +let { isTTY } = process.stdin + +if (process.env.FORCE_IS_TTY === 'true') { + isTTY = true +} + +if (argv.watch && isTTY) { process.stdin.on('end', () => process.exit(0)) process.stdin.resume() } diff --git a/test/watch.js b/test/watch.js index 4cd5391..625df1b 100644 --- a/test/watch.js +++ b/test/watch.js @@ -205,6 +205,10 @@ testCb('--watch does exit on closing stdin (Ctrl-D/EOF)', (t) => { const cp = spawn(`./index.js test/fixtures/a.css -o ${tmp()} -w --no-map`, { shell: true, + env: { + ...process.env, + FORCE_IS_TTY: true, + }, }) cp.on('error', t.end) @@ -212,6 +216,7 @@ testCb('--watch does exit on closing stdin (Ctrl-D/EOF)', (t) => { t.is(code, 0) t.end() }) + cp.stdin.end() })