@j-o-r/sh 1.0.6 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/SHDispatch.js +4 -4
- package/lib/SHExecute.js +12 -3
- package/package.json +1 -1
- package/types/SHDispatch.d.ts +1 -1
- package/types/SHExecute.d.ts +1 -0
package/lib/SHDispatch.js
CHANGED
|
@@ -140,11 +140,11 @@ class SHDispatch {
|
|
|
140
140
|
// @ts-ignore
|
|
141
141
|
return new SHExec(this.#cmd, this.#options).runSync(payload);
|
|
142
142
|
}
|
|
143
|
-
async kill() {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
} catch (_e) { }
|
|
143
|
+
async kill(signal = 'SIGTERM') {
|
|
144
|
+
let res = [];
|
|
145
|
+
res = await this.#proc.kill(signal);
|
|
147
146
|
this.#proc = undefined;
|
|
147
|
+
return res;
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
150
|
|
package/lib/SHExecute.js
CHANGED
|
@@ -20,7 +20,7 @@ const killProcesses = (processPid, signal) => {
|
|
|
20
20
|
reject(new Error(stderr));
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
23
|
-
const pids = stdout.split(/\r?\n/).filter(pid => pid);
|
|
23
|
+
const pids = stdout.split(/\r?\n/).filter(pid => pid) || [];
|
|
24
24
|
// Kill each child process
|
|
25
25
|
try {
|
|
26
26
|
for (const pid of pids) {
|
|
@@ -48,6 +48,7 @@ class SHExecute {
|
|
|
48
48
|
/**
|
|
49
49
|
* @type {import('child_process').ChildProcess}
|
|
50
50
|
*/
|
|
51
|
+
#forcedKill = false;
|
|
51
52
|
#proc;
|
|
52
53
|
#command = '';
|
|
53
54
|
#options = {};
|
|
@@ -127,6 +128,11 @@ class SHExecute {
|
|
|
127
128
|
}
|
|
128
129
|
this.#proc.on('close', (code) => {
|
|
129
130
|
if (timeout) clearTimeout(timeout);
|
|
131
|
+
if (this.#forcedKill) {
|
|
132
|
+
// Resolve without content
|
|
133
|
+
resolve();
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
130
136
|
if (code === 0) {
|
|
131
137
|
resolve(this.#stdout.trim());
|
|
132
138
|
} else {
|
|
@@ -140,13 +146,16 @@ class SHExecute {
|
|
|
140
146
|
});
|
|
141
147
|
}
|
|
142
148
|
/**
|
|
149
|
+
* @param {string} signal - kill signal
|
|
143
150
|
* @returns {Promise<number[]>}
|
|
144
151
|
*/
|
|
145
152
|
async kill(signal = 'SIGTERM') {
|
|
146
153
|
if (!this.#proc) throw new Error('Trying to kill a process without creating one.');
|
|
147
154
|
if (!this.#proc.pid) throw new Error('The process pid is undefined.');
|
|
148
|
-
|
|
149
|
-
|
|
155
|
+
this.#forcedKill = true;
|
|
156
|
+
const res = killProcesses(this.#proc.pid, signal);
|
|
157
|
+
this.#proc = undefined;
|
|
158
|
+
return res;
|
|
150
159
|
}
|
|
151
160
|
}
|
|
152
161
|
|
package/package.json
CHANGED
package/types/SHDispatch.d.ts
CHANGED