Commit e010f23

Anton Golub <antongolub@antongolub.com>
2024-04-06 10:37:58
feat: support `signal` opt (#769)
closes #768 relates #734
1 parent 7fa9bfc
src/core.ts
@@ -57,6 +57,7 @@ export interface Options {
   [syncExec]: boolean
   cwd?: string
   ac?: AbortController
+  signal?: AbortSignal
   input?: string | Buffer | Readable | ProcessOutput | ProcessPromise
   verbose: boolean
   sync: boolean
@@ -247,6 +248,7 @@ export class ProcessPromise extends Promise<ProcessOutput> {
       cmd: $.prefix + this._command + $.postfix,
       cwd: $.cwd ?? $[processCwd],
       ac: $.ac,
+      signal: $.signal,
       shell: typeof $.shell === 'string' ? $.shell : true,
       env: $.env,
       spawn: $.spawn,
test/fixtures/js-project/package-lock.json
@@ -9,7 +9,7 @@
       }
     },
     "../../..": {
-      "version": "7.2.3",
+      "version": "8.0.0",
       "license": "Apache-2.0",
       "bin": {
         "zx": "build/cli.js"
@@ -39,7 +39,7 @@
         "typescript": "^5.4.4",
         "which": "^4.0.0",
         "yaml": "^2.4.1",
-        "zurk": "^0.0.32"
+        "zurk": "^0.1.0"
       },
       "engines": {
         "node": ">= 16.0.0"
test/core.test.js
@@ -342,6 +342,20 @@ describe('core', () => {
     }
   })
 
+  test('accepts AbortController `signal` separately', async () => {
+    const ac = new AbortController()
+    const signal = ac.signal
+    const p = $({ signal })`sleep 9999`
+    setTimeout(() => ac.abort(), 100)
+
+    try {
+      await p
+      assert.unreachable('should have thrown')
+    } catch ({ message }) {
+      assert.match(message, /The operation was aborted/)
+    }
+  })
+
   test('kill() method works', async () => {
     let p = $`sleep 9999`.nothrow()
     setTimeout(() => {
package-lock.json
@@ -1,12 +1,12 @@
 {
   "name": "zx",
-  "version": "7.2.3",
+  "version": "8.0.0",
   "lockfileVersion": 3,
   "requires": true,
   "packages": {
     "": {
       "name": "zx",
-      "version": "7.2.3",
+      "version": "8.0.0",
       "license": "Apache-2.0",
       "bin": {
         "zx": "build/cli.js"
@@ -36,7 +36,7 @@
         "typescript": "^5.4.4",
         "which": "^4.0.0",
         "yaml": "^2.4.1",
-        "zurk": "^0.0.32"
+        "zurk": "^0.1.0"
       },
       "engines": {
         "node": ">= 16.0.0"
@@ -518,6 +518,12 @@
         "zurk": "^0.0.32"
       }
     },
+    "node_modules/@webpod/ps/node_modules/zurk": {
+      "version": "0.0.32",
+      "resolved": "https://registry.npmjs.org/zurk/-/zurk-0.0.32.tgz",
+      "integrity": "sha512-KouorYeuxuZORUiDoOMUCgpjgHgMP+ks9MpEPOT/JE5/df9bIr6DjqIiaQGhzH9ZLG00bWBZJazCpwO0zSqq7g==",
+      "dev": true
+    },
     "node_modules/any-promise": {
       "version": "1.3.0",
       "resolved": "https://registry.npmjs.org/any-promise/-/any-promise-1.3.0.tgz",
@@ -4378,9 +4384,9 @@
       }
     },
     "node_modules/zurk": {
-      "version": "0.0.32",
-      "resolved": "https://registry.npmjs.org/zurk/-/zurk-0.0.32.tgz",
-      "integrity": "sha512-KouorYeuxuZORUiDoOMUCgpjgHgMP+ks9MpEPOT/JE5/df9bIr6DjqIiaQGhzH9ZLG00bWBZJazCpwO0zSqq7g==",
+      "version": "0.1.0",
+      "resolved": "https://registry.npmjs.org/zurk/-/zurk-0.1.0.tgz",
+      "integrity": "sha512-lJPh6OG7eBAkAw1zlB15U0tRSb7Cq/nZhcW1/gfNYB+HUTwzlK1PvKDp6zV6jyix8xYiTnIfiHGPMVav8x3YuQ==",
       "dev": true
     }
   }
package.json
@@ -80,7 +80,7 @@
     "typescript": "^5.4.4",
     "which": "^4.0.0",
     "yaml": "^2.4.1",
-    "zurk": "^0.0.32"
+    "zurk": "^0.1.0"
   },
   "publishConfig": {
     "registry": "https://wombat-dressing-room.appspot.com"