Commit 5e4b543

Anton Golub <antongolub@antongolub.com>
2025-07-27 13:19:34
fix: handle `_snapshot.killSignal` value on `kill()` (#1287)
1 parent 7cc6136
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.
build/core.d.ts
@@ -90,7 +90,7 @@ export declare class ProcessPromise extends Promise<ProcessOutput> {
     };
     private _pipe;
     abort(reason?: string): void;
-    kill(signal?: NodeJS.Signals | undefined): Promise<void>;
+    kill(signal?: NodeJS.Signals): Promise<void>;
     /**
      *  @deprecated Use $({halt: true})`cmd` instead.
      */
src/core.ts
@@ -445,13 +445,13 @@ export class ProcessPromise extends Promise<ProcessOutput> {
     this.ac.abort(reason)
   }
 
-  kill(signal = $.killSignal): Promise<void> {
+  kill(signal?: NodeJS.Signals): Promise<void> {
     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)
   }
 
   /**
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
.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
   },