Skip to content

Commit 75d26de

Browse files
committed
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
1 parent 8bc5833 commit 75d26de

3 files changed

Lines changed: 11 additions & 3 deletions

File tree

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
node-version:
1313
- 18
1414
- 20
15-
- '22.9.0'
15+
- 22
1616
os:
1717
- ubuntu-latest
1818
- macos-latest

scripts/check-node-support.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ var MAX_NODE_VERSION = 22;
1818
var pinnedNodeVersions = {
1919
// Format:
2020
// majorVersionInt: 'full.node.version',
21-
22: '22.9.0',
21+
// Example:
22+
// 22: '22.9.0',
2223
};
2324

2425
function checkReadme(minNodeVersion) {

src/cmd.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,20 @@ common.register('cmd', _cmd, {
1111
wrapOutput: true,
1212
});
1313

14+
function isNullOrUndefined(val) {
15+
return val === null || val === undefined;
16+
}
17+
1418
function commandNotFound(execaResult) {
1519
if (process.platform === 'win32') {
1620
var str = 'is not recognized as an internal or external command';
1721
return execaResult.code && execaResult.stderr.includes(str);
1822
} else {
23+
// On node <= 22.9.0, stdout/stderr are 'null'.
24+
// On node >= 22.10, stdout/stderr are 'undefined'.
1925
return execaResult.code &&
20-
execaResult.stdout === null && execaResult.stderr === null;
26+
isNullOrUndefined(execaResult.stdout) &&
27+
isNullOrUndefined(execaResult.stderr);
2128
}
2229
}
2330

0 commit comments

Comments
 (0)