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

exit watch process on EOF / Ctrl-D #358

Merged
merged 4 commits into from Nov 17, 2020
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
5 changes: 5 additions & 0 deletions index.js
Expand Up @@ -51,6 +51,11 @@ let configFile
if (argv.env) process.env.NODE_ENV = argv.env
if (argv.config) argv.config = path.resolve(argv.config)

if (argv.watch) {
process.stdin.on('end', () => process.exit(0))
process.stdin.resume()
}

Promise.resolve()
.then(() => {
if (argv.watch && !(argv.output || argv.replace || argv.dir)) {
Expand Down
19 changes: 18 additions & 1 deletion test/watch.js
Expand Up @@ -3,11 +3,12 @@ const test = require('ava')

const fs = require('fs-extra')
const path = require('path')
const { exec } = require('child_process')
const { exec, spawn } = require('child_process')
const chokidar = require('chokidar')

const ENV = require('./helpers/env.js')
const read = require('./helpers/read.js')
const tmp = require('./helpers/tmp.js')

// XXX: All the tests in this file are skipped on the CI; too flacky there
const testCb = process.env.CI ? test.cb.skip : test.cb
Expand Down Expand Up @@ -285,3 +286,19 @@ testCb("--watch doesn't exit on CssSyntaxError", (t) => {
// Timeout:
setTimeout(() => t.end('test timeout'), 50000)
})

testCb('--watch does exit on closing stdin (Ctrl-D/EOF)', (t) => {
t.plan(1)

const cp = spawn(
`./bin/postcss test/fixtures/a.css -o ${tmp()} -w --no-map`,
{ shell: true }
)

cp.on('error', t.end)
cp.on('exit', (code) => {
t.is(code, 0)
t.end()
})
cp.stdin.end()
})