From 1d9485fa3bd707fa59cd5ca5b291abe656b682e2 Mon Sep 17 00:00:00 2001 From: Nate Fischer Date: Thu, 10 Apr 2025 01:19:14 -0700 Subject: [PATCH] fix: cmd is compatible with node 22.10 Starting in node >= 22.10.0, a commandNotFound error will have `undefined` values for stdout/stderr, whereas in earlier versions these values were `null`. Fixes #1180 --- .github/workflows/main.yml | 2 +- scripts/check-node-support.js | 3 ++- src/cmd.js | 9 ++++++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7cede0ec..3ed26651 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,7 +12,7 @@ jobs: node-version: - 18 - 20 - - '22.9.0' + - 22 os: - ubuntu-latest - macos-latest diff --git a/scripts/check-node-support.js b/scripts/check-node-support.js index e33574f8..8ea89d80 100755 --- a/scripts/check-node-support.js +++ b/scripts/check-node-support.js @@ -18,7 +18,8 @@ var MAX_NODE_VERSION = 22; var pinnedNodeVersions = { // Format: // majorVersionInt: 'full.node.version', - 22: '22.9.0', + // Example: + // 22: '22.9.0', }; function checkReadme(minNodeVersion) { diff --git a/src/cmd.js b/src/cmd.js index 455fb3a6..e1023cd5 100644 --- a/src/cmd.js +++ b/src/cmd.js @@ -11,13 +11,20 @@ common.register('cmd', _cmd, { wrapOutput: true, }); +function isNullOrUndefined(val) { + return val === null || val === undefined; +} + function commandNotFound(execaResult) { if (process.platform === 'win32') { var str = 'is not recognized as an internal or external command'; return execaResult.code && execaResult.stderr.includes(str); } else { + // On node <= 22.9.0, stdout/stderr are 'null'. + // On node >= 22.10, stdout/stderr are 'undefined'. return execaResult.code && - execaResult.stdout === null && execaResult.stderr === null; + isNullOrUndefined(execaResult.stdout) && + isNullOrUndefined(execaResult.stderr); } }