diff --git a/lib/util/resolveCommand.js b/lib/util/resolveCommand.js index 6825a8b..7972455 100644 --- a/lib/util/resolveCommand.js +++ b/lib/util/resolveCommand.js @@ -2,9 +2,10 @@ const path = require('path'); const which = require('which'); -const pathKey = require('path-key')(); +const getPathKey = require('path-key'); function resolveCommandAttempt(parsed, withoutPathExt) { + const env = parsed.options.env || process.env; const cwd = process.cwd(); const hasCustomCwd = parsed.options.cwd != null; // Worker threads do not have process.chdir() @@ -24,7 +25,7 @@ function resolveCommandAttempt(parsed, withoutPathExt) { try { resolved = which.sync(parsed.command, { - path: (parsed.options.env || process.env)[pathKey], + path: env[getPathKey({ env })], pathExt: withoutPathExt ? path.delimiter : undefined, }); } catch (e) { diff --git a/test/fixtures/whoami.cmd b/test/fixtures/whoami.cmd new file mode 100644 index 0000000..4ffec34 --- /dev/null +++ b/test/fixtures/whoami.cmd @@ -0,0 +1,2 @@ +@echo off +echo you sure are someone diff --git a/test/index.test.js b/test/index.test.js index 2217d9c..5373627 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -434,5 +434,22 @@ run.methods.forEach((method) => { expect(Number(stdout.trim())).toBe(process.pid); }); } + + if (isWin) { + const differentPathKey = pathKey.startsWith('p') ? 'PATH' : 'path'; + + it('should work if the path key is different in options.env', async () => { + const env = { + ...process.env, + [differentPathKey]: `${__dirname}\\fixtures;${process.env[pathKey]}`, + }; + + delete env[pathKey]; + + const { stdout } = await run(method, 'whoami', { env }); + + expect(stdout.trim()).toBe('you sure are someone'); + }); + } }); });