Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow non-TTY stdin watch mode #448

Merged
merged 1 commit into from Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion index.js
Expand Up @@ -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()
}
Expand Down
5 changes: 5 additions & 0 deletions test/watch.js
Expand Up @@ -205,13 +205,18 @@ 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)
cp.on('exit', (code) => {
t.is(code, 0)
t.end()
})

cp.stdin.end()
})

Expand Down