Skip to content

Commit 10497ed

Browse files
committed
do not set process.exitCode based on child exit
The child process's exit code should be ignored for the purpose of the signal manager, and is not emitted by node's child_process.spawn in the same way that @npmcli/promise-spawn returns it. Fix: #11 PR-URL: #12 Credit: @isaacs Close: #12 Reviewed-by: @nlf
1 parent 8b5720f commit 10497ed

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

lib/signal-manager.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ const add = proc => {
3333
if (!handlersInstalled)
3434
setupListeners()
3535

36-
proc.once('exit', ({ code }) => {
37-
process.exitCode = process.exitCode || code
36+
proc.once('exit', () => {
3837
runningProcs.delete(proc)
3938
cleanupListeners()
4039
})

test/signal-manager.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ test('adds only one handler for each signal, removes handlers when children have
2222
t.equal(handlers.length, 1, 'only has one handler')
2323
}
2424

25-
procOne.emit('exit', { code: 0 })
25+
procOne.emit('exit', 0)
2626

2727
for (const signal of signalManager.forwardedSignals) {
2828
t.equal(process.listeners(signal).includes(signalManager.handleSignal), true, 'did not remove listeners yet')
2929
}
3030

31-
procTwo.emit('exit', { code: 0 })
31+
procTwo.emit('exit', 0)
3232

3333
for (const signal of signalManager.forwardedSignals) {
3434
t.equal(process.listeners(signal).includes(signalManager.handleSignal), false, 'listener has been removed')
@@ -41,7 +41,7 @@ test('forwards signals to child process', t => {
4141
const proc = new EventEmitter()
4242
proc.kill = (signal) => {
4343
t.equal(signal, signalManager.forwardedSignals[0], 'child receives correct signal')
44-
proc.emit('exit', { code: 0 })
44+
proc.emit('exit', 0)
4545
for (const signal of signalManager.forwardedSignals) {
4646
t.equal(process.listeners(signal).includes(signalManager.handleSignal), false, 'listener has been removed')
4747
}

0 commit comments

Comments
 (0)