From f96206047778271bf76e84581d28bc93a083d5d8 Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Mon, 12 Dec 2016 22:54:09 -0800 Subject: [PATCH] proxy sub-commands' exit codes and signals (#48) This code mostly comes from `mocha` so credit to them. --- src/index.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/index.js b/src/index.js index 31d51cb..27a1b01 100644 --- a/src/index.js +++ b/src/index.js @@ -328,6 +328,25 @@ class Args { this.child.on('error', err => { throw err }) + + this.child.on('exit', (code, signal) => { + process.on('exit', () => { + this.child = null + if (signal) { + process.kill(process.pid, signal) + } else { + process.exit(code) + } + }) + }) + + // proxy SIGINT to child process + process.on('SIGINT', () => { + if (this.child) { + this.child.kill('SIGINT') + this.child.kill('SIGTERM') // if that didn't work, we're probably in an infinite loop, so make it die + } + }) } checkVersion() {