From 355bc57d6f6b1f84b2c6f2f7b3d39e8185ca492d Mon Sep 17 00:00:00 2001 From: Anton Golub Date: Sun, 27 Jul 2025 14:16:22 +0300 Subject: [PATCH] fix: handle `_snapshot.killSignal` value on `kill()` --- .size-limit.json | 4 ++-- build/core.cjs | 4 ++-- build/core.d.ts | 2 +- src/core.ts | 4 ++-- test/core.test.js | 14 +++++++++++++- 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/.size-limit.json b/.size-limit.json index 4f9d16c840..e3c6af50c1 100644 --- a/.size-limit.json +++ b/.size-limit.json @@ -15,7 +15,7 @@ "README.md", "LICENSE" ], - "limit": "121.40 kB", + "limit": "121.45 kB", "brotli": false, "gzip": false }, @@ -29,7 +29,7 @@ "build/globals.js", "build/deno.js" ], - "limit": "812.46 kB", + "limit": "812.50 kB", "brotli": false, "gzip": false }, diff --git a/build/core.cjs b/build/core.cjs index 9d890c3bf4..8b92947d33 100644 --- a/build/core.cjs +++ b/build/core.cjs @@ -646,12 +646,12 @@ var _ProcessPromise = class _ProcessPromise extends Promise { throw new Fail("Trying to abort a process without creating one."); this.ac.abort(reason); } - kill(signal = $.killSignal) { + kill(signal) { if (this.isSettled()) throw new Fail("Too late to kill the process."); if (!this.child) throw new Fail("Trying to kill a process without creating one."); if (!this.pid) throw new Fail("The process pid is undefined."); - return $.kill(this.pid, signal); + return $.kill(this.pid, signal || this._snapshot.killSignal || $.killSignal); } /** * @deprecated Use $({halt: true})`cmd` instead. diff --git a/build/core.d.ts b/build/core.d.ts index 16a18139d7..980640ee7c 100644 --- a/build/core.d.ts +++ b/build/core.d.ts @@ -90,7 +90,7 @@ export declare class ProcessPromise extends Promise { }; private _pipe; abort(reason?: string): void; - kill(signal?: NodeJS.Signals | undefined): Promise; + kill(signal?: NodeJS.Signals): Promise; /** * @deprecated Use $({halt: true})`cmd` instead. */ diff --git a/src/core.ts b/src/core.ts index 400df291a2..431bee385b 100644 --- a/src/core.ts +++ b/src/core.ts @@ -445,13 +445,13 @@ export class ProcessPromise extends Promise { this.ac.abort(reason) } - kill(signal = $.killSignal): Promise { + kill(signal?: NodeJS.Signals): Promise { if (this.isSettled()) throw new Fail('Too late to kill the process.') if (!this.child) throw new Fail('Trying to kill a process without creating one.') if (!this.pid) throw new Fail('The process pid is undefined.') - return $.kill(this.pid, signal) + return $.kill(this.pid, signal || this._snapshot.killSignal || $.killSignal) } /** diff --git a/test/core.test.js b/test/core.test.js index d9ef3dd170..e72d6d51de 100644 --- a/test/core.test.js +++ b/test/core.test.js @@ -1010,7 +1010,7 @@ describe('core', () => { assert.ok(o.duration >= 100 && o.duration < 1000) }) - test('a signal is passed with kill() method', async () => { + test('applies custom signal if passed', async () => { const p = $`while true; do :; done` setTimeout(() => p.kill('SIGKILL'), 100) let signal @@ -1022,6 +1022,18 @@ describe('core', () => { assert.equal(signal, 'SIGKILL') }) + test('applies `$.killSignal` if defined', async () => { + const p = $({ killSignal: 'SIGKILL' })`while true; do :; done` + setTimeout(() => p.kill(), 100) + let signal + try { + await p + } catch (p) { + signal = p.signal + } + assert.equal(signal, 'SIGKILL') + }) + test('throws if too late', async () => { const p = $`echo foo` await p