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

Proxy exit signals from foreground processes #16

Merged
merged 4 commits into from
Nov 6, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion lib/run-script-pkg.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ const runScriptPkg = async options => {
stdioString = false,
// note: only used when stdio:inherit
banner = true,
// how long to wait for a process.kill signal
// only exposed here so that we can make the test go a bit faster.
signalTimeout = 500,
} = options

const {scripts = {}, gypfile} = pkg
Expand Down Expand Up @@ -68,7 +71,17 @@ const runScriptPkg = async options => {
if (p.stdin)
p.stdin.end()

return p
return p.catch(er => {
const { signal } = er
if (stdio === 'inherit' && signal) {
process.kill(process.pid, signal)
// just in case we don't die, reject after 500ms
// this also keeps the node process open long enough to actually
// get the signal, rather than terminating gracefully.
return new Promise((res, rej) => setTimeout(() => rej(er), signalTimeout))
} else
throw er
})
}

module.exports = runScriptPkg
3 changes: 2 additions & 1 deletion lib/run-script.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const rpj = require('read-package-json-fast')
const runScriptPkg = require('./run-script-pkg.js')
const validateOptions = require('./validate-options.js')
const isServerPackage = require('./is-server-package.js')

const runScript = options => {
validateOptions(options)
Expand All @@ -9,4 +10,4 @@ const runScript = options => {
: rpj(path + '/package.json').then(pkg => runScriptPkg({...options, pkg}))
}

module.exports = runScript
module.exports = Object.assign(runScript, { isServerPackage })
Loading