Skip to content

Commit

Permalink
Pass signals to child process (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrJohz committed May 7, 2024
1 parent ed62fc7 commit 5845b5a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,17 @@ if (!command) {
process.exit(1)
}

spawn(command, argv._.slice(1), { stdio: 'inherit' })
const child = spawn(command, argv._.slice(1), { stdio: 'inherit' })
.on('exit', function (exitCode, signal) {
if (typeof exitCode === 'number') {
process.exit(exitCode)
} else {
process.kill(process.pid, signal)
}
})

for (const signal of ['SIGINT', 'SIGTERM', 'SIGPIPE', 'SIGHUP', 'SIGBREAK', 'SIGWINCH', 'SIGUSR1', 'SIGUSR2']) {
process.on(signal, function () {
child.kill(signal)
})
}

0 comments on commit 5845b5a

Please sign in to comment.