From 1764f1e3166ae2c48f008a8f686824a4dd397b64 Mon Sep 17 00:00:00 2001 From: wll8 Date: Fri, 17 Jun 2022 14:56:09 +0800 Subject: [PATCH] fix: ctrl+c does not end the child process --- lib/spawnify.js | 10 +++++++++- package.json | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/spawnify.js b/lib/spawnify.js index 44492c7..5bdc768 100644 --- a/lib/spawnify.js +++ b/lib/spawnify.js @@ -158,7 +158,15 @@ Spawnify.prototype._set = function set(type, command, options) { this._setListeners(child); this.on('kill', (code) => { - child.kill(code); + // Can only end the first process + // child.kill(code); + + // Can end subprocess, but at the expense of `code` + import('fkill').then(fkill => fkill.default(child.pid, { + force: true, + })).catch(err => { + console.log(`Process has been terminated, or other errors.`) + }); }); this.on('write', (data) => { diff --git a/package.json b/package.json index e8afdfa..4592113 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "node": ">=14" }, "dependencies": { + "fkill": "^8.0.1", "glob": "^7.1.0", "tildify": "^2.0.0", "try-catch": "^3.0.0",