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 #446

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "postcss-cli",
"name": "@0xradical/postcss-cli",
"version": "10.0.0",
"description": "CLI for PostCSS",
"type": "module",
Expand Down Expand Up @@ -75,4 +75,4 @@
},
"homepage": "https://github.com/postcss/postcss-cli#readme",
"license": "MIT"
}
}
5 changes: 5 additions & 0 deletions test/watch.js
Original file line number Diff line number Diff line change
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