Skip to content

Commit 159e7e9

Browse files
authored
fix: detect path key based on correct environment (#133)
1 parent 7501971 commit 159e7e9

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

lib/util/resolveCommand.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
const path = require('path');
44
const which = require('which');
5-
const pathKey = require('path-key')();
5+
const getPathKey = require('path-key');
66

77
function resolveCommandAttempt(parsed, withoutPathExt) {
8+
const env = parsed.options.env || process.env;
89
const cwd = process.cwd();
910
const hasCustomCwd = parsed.options.cwd != null;
1011
// Worker threads do not have process.chdir()
@@ -24,7 +25,7 @@ function resolveCommandAttempt(parsed, withoutPathExt) {
2425

2526
try {
2627
resolved = which.sync(parsed.command, {
27-
path: (parsed.options.env || process.env)[pathKey],
28+
path: env[getPathKey({ env })],
2829
pathExt: withoutPathExt ? path.delimiter : undefined,
2930
});
3031
} catch (e) {

test/fixtures/whoami.cmd

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@echo off
2+
echo you sure are someone

test/index.test.js

+17
Original file line numberDiff line numberDiff line change
@@ -434,5 +434,22 @@ run.methods.forEach((method) => {
434434
expect(Number(stdout.trim())).toBe(process.pid);
435435
});
436436
}
437+
438+
if (isWin) {
439+
const differentPathKey = pathKey.startsWith('p') ? 'PATH' : 'path';
440+
441+
it('should work if the path key is different in options.env', async () => {
442+
const env = {
443+
...process.env,
444+
[differentPathKey]: `${__dirname}\\fixtures;${process.env[pathKey]}`,
445+
};
446+
447+
delete env[pathKey];
448+
449+
const { stdout } = await run(method, 'whoami', { env });
450+
451+
expect(stdout.trim()).toBe('you sure are someone');
452+
});
453+
}
437454
});
438455
});

0 commit comments

Comments
 (0)