Commit f1b9ed7

Anton Golub <antongolub@antongolub.com>
2025-09-20 13:39:46
refactor: strengthen `kill` input check (#1341) tag: 8.8.3
* refactor: strengthen `kill` input check continues #1339 * ci: check tag with pkg version
1 parent 6d611de
.github/workflows/publish.yml
@@ -22,6 +22,17 @@ jobs:
         with:
           node-version: 24
           cache: 'npm'
+      - name: Compare release tag with package.json
+        if: github.event_name == 'release'
+        run: |
+          RELEASE_VERSION=${GITHUB_REF#refs/tags/v}
+          PKG_VERSION=$(node -p "require('./package.json').version")
+
+          echo "Release tag: $RELEASE_VERSION"
+          echo "package.json: $PKG_VERSION"
+
+          [ "$RELEASE_VERSION" = "$PKG_VERSION" ] || { echo "❌ Mismatch"; exit 1; }
+
       - run: npm ci
       - run: npm test
         env:
build/core.cjs
@@ -1109,8 +1109,8 @@ function cd(dir) {
 }
 function kill(_0) {
   return __async(this, arguments, function* (pid, signal = $.killSignal || SIGTERM) {
-    if (!/^\d+$/.test(pid)) throw new Fail(`Invalid pid: ${pid}`);
-    pid = pid + "";
+    if (typeof pid !== "number" && typeof pid !== "string" || !/^\d+$/.test(pid))
+      throw new Fail(`Invalid pid: ${pid}`);
     $.log({ kind: "kill", pid, signal, verbose: !$.quiet && $.verbose });
     if (import_node_process2.default.platform === "win32" && (yield new Promise((resolve) => {
       import_node_child_process.default.exec(`taskkill /pid ${pid} /t /f`, (err) => resolve(!err));
build/index.cjs
@@ -54,7 +54,7 @@ var import_vendor = require("./vendor.cjs");
 
 // src/versions.ts
 var versions = {
-  zx: "8.8.1",
+  zx: "8.8.3",
   chalk: "5.6.2",
   depseek: "0.4.3",
   dotenv: "0.2.3",
src/core.ts
@@ -1041,8 +1041,11 @@ export async function kill(
   pid: number | `${number}`,
   signal = $.killSignal || SIGTERM
 ) {
-  if (!/^\d+$/.test(pid as string)) throw new Fail(`Invalid pid: ${pid}`)
-  pid = (pid + '') as `${number}`
+  if (
+    (typeof pid !== 'number' && typeof pid !== 'string') ||
+    !/^\d+$/.test(pid as string)
+  )
+    throw new Fail(`Invalid pid: ${pid}`)
 
   $.log({ kind: 'kill', pid, signal, verbose: !$.quiet && $.verbose })
   if (
src/versions.ts
@@ -13,7 +13,7 @@
 // limitations under the License.
 
 export const versions: Record<string, string> = {
-  zx: '8.8.1',
+  zx: '8.8.3',
   chalk: '5.6.2',
   depseek: '0.4.3',
   dotenv: '0.2.3',
test/core.test.js
@@ -1651,6 +1651,15 @@ describe('core', () => {
       await assert.rejects(() => kill(100.1), /Invalid/)
       await assert.rejects(() => kill(null), /Invalid/)
       await assert.rejects(() => kill({}), /Invalid/)
+      await assert.rejects(
+        () =>
+          kill({
+            toString() {
+              return '12345'
+            },
+          }),
+        /Invalid/
+      )
     })
   })
 
.size-limit.json
@@ -19,7 +19,7 @@
       "README.md",
       "LICENSE"
     ],
-    "limit": "128.25 kB",
+    "limit": "128.30 kB",
     "brotli": false,
     "gzip": false
   },
@@ -33,7 +33,7 @@
       "build/globals.js",
       "build/deno.js"
     ],
-    "limit": "816.05 kB",
+    "limit": "816.10 kB",
     "brotli": false,
     "gzip": false
   },
@@ -66,7 +66,7 @@
       "README.md",
       "LICENSE"
     ],
-    "limit": "873.60 kB",
+    "limit": "873.65 kB",
     "brotli": false,
     "gzip": false
   }
package-lock.json
@@ -1,12 +1,12 @@
 {
   "name": "zx",
-  "version": "8.8.2",
+  "version": "8.8.3",
   "lockfileVersion": 3,
   "requires": true,
   "packages": {
     "": {
       "name": "zx",
-      "version": "8.8.2",
+      "version": "8.8.3",
       "license": "Apache-2.0",
       "bin": {
         "zx": "build/cli.js"
package.json
@@ -1,6 +1,6 @@
 {
   "name": "zx",
-  "version": "8.8.2",
+  "version": "8.8.3",
   "description": "A tool for writing better scripts",
   "type": "module",
   "main": "./build/index.cjs",