diff --git a/lib/spawn-posix.js b/lib/spawn-posix.js index 84f6a03..604bfef 100644 --- a/lib/spawn-posix.js +++ b/lib/spawn-posix.js @@ -11,6 +11,7 @@ //------------------------------------------------------------------------------ const crossSpawn = require("cross-spawn") +const getDescendentProcessInfo = require("pidtree") //------------------------------------------------------------------------------ // Helpers @@ -21,22 +22,22 @@ const crossSpawn = require("cross-spawn") * @this ChildProcess * @returns {void} */ -// function kill() { -// getDescendentProcessInfo(this.pid, (err, descendent) => { -// if (err) { -// return -// } - -// for (const child of descendent) { -// try { -// process.kill(child.PID) -// } -// catch (_err) { -// // ignore. -// } -// } -// }) -// } +function kill() { + getDescendentProcessInfo(this.pid, { root: true }, (err, pids) => { + if (err) { + return + } + + for (const pid of pids) { + try { + process.kill(pid) + } + catch (_err) { + // ignore. + } + } + }) +} //------------------------------------------------------------------------------ // Public Interface @@ -57,7 +58,7 @@ const crossSpawn = require("cross-spawn") */ module.exports = function spawn(command, args, options) { const child = crossSpawn(command, args, options) - // child.kill = kill + child.kill = kill return child } diff --git a/package.json b/package.json index f498522..2121f28 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "cross-spawn": "^6.0.5", "memorystream": "^0.3.1", "minimatch": "^3.0.4", + "pidtree": "^0.3.0", "read-pkg": "^3.0.0", "shell-quote": "^1.6.1", "string.prototype.padend": "^3.0.0"