foreground-child
Advanced tools
Comparing version 1.1.0 to 1.2.0
80
index.js
@@ -0,1 +1,4 @@ | ||
var signalExit = require('signal-exit') | ||
var spawn = require('child_process').spawn | ||
module.exports = function (program, args) { | ||
@@ -9,33 +12,21 @@ if (Array.isArray(program)) { | ||
var child = require('child_process').spawn( | ||
program, | ||
args, | ||
{ stdio: 'inherit' } | ||
) | ||
var child = spawn(program, args, { stdio: 'inherit' }) | ||
signals.forEach(function (sig) { | ||
try { | ||
process.on(sig, function () { | ||
child.kill(sig) | ||
}) | ||
} catch (er) {} | ||
var childExited = false | ||
signalExit(function (code, signal) { | ||
child.kill(signal || 'SIGHUP') | ||
}) | ||
process.once('exit', function (code) { | ||
emittedExit = true | ||
child.kill('SIGHUP') | ||
}) | ||
var emittedExit = false | ||
child.on('close', function (code, signal) { | ||
childExited = true | ||
if (signal) { | ||
process.removeAllListeners(signal) | ||
if (!emittedExit) { | ||
process.emit('exit', code) | ||
} | ||
// If there is nothing else keeping the event loop alive, | ||
// then there's a race between a graceful exit and getting | ||
// the signal to this process. Put this timeout here to | ||
// make sure we're still alive to get the signal, and thus | ||
// exit with the intended signal code. | ||
setTimeout(function () {}, 200) | ||
process.kill(process.pid, signal) | ||
} else { | ||
} else | ||
process.exit(code) | ||
} | ||
}) | ||
@@ -45,42 +36,1 @@ | ||
} | ||
var signals = [ | ||
'SIGABRT', | ||
'SIGALRM', | ||
'SIGBUS', | ||
'SIGCHLD', | ||
'SIGCLD', | ||
'SIGCONT', | ||
'SIGEMT', | ||
'SIGFPE', | ||
'SIGHUP', | ||
'SIGILL', | ||
'SIGINFO', | ||
'SIGINT', | ||
'SIGIO', | ||
'SIGIOT', | ||
'SIGKILL', | ||
'SIGLOST', | ||
'SIGPIPE', | ||
'SIGPOLL', | ||
'SIGPROF', | ||
'SIGPWR', | ||
'SIGQUIT', | ||
'SIGSEGV', | ||
'SIGSTKFLT', | ||
'SIGSTOP', | ||
'SIGSYS', | ||
'SIGTERM', | ||
'SIGTRAP', | ||
'SIGTSTP', | ||
'SIGTTIN', | ||
'SIGTTOU', | ||
'SIGUNUSED', | ||
'SIGURG', | ||
'SIGUSR1', | ||
'SIGUSR2', | ||
'SIGVTALRM', | ||
'SIGWINCH', | ||
'SIGXCPU', | ||
'SIGXFSZ' | ||
] |
{ | ||
"name": "foreground-child", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Run a child as if it's the foreground process. Give it stdio. Exit when it exits.", | ||
@@ -9,3 +9,5 @@ "main": "index.js", | ||
}, | ||
"dependencies": {}, | ||
"dependencies": { | ||
"signal-exit": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
@@ -12,0 +14,0 @@ "tap": "^1.0.4" |
var fg = require('../index.js') | ||
var spawn = require('child_process').spawn | ||
var signalExit = require('signal-exit') | ||
@@ -29,3 +30,3 @@ if (process.argv[2] === 'child') { | ||
if (process.argv[3] === 'signalexit') { | ||
process.on('exit', function () { | ||
signalExit(function (code, signal) { | ||
console.log('parent exit') | ||
@@ -32,0 +33,0 @@ }) |
5637
1
134
+ Addedsignal-exit@^2.0.0
+ Addedsignal-exit@2.1.2(transitive)