From 191140e90ffd5c27413707964f4736f153cd63b1 Mon Sep 17 00:00:00 2001 From: amtbsl <147152854+amtbsl@users.noreply.github.com> Date: Sat, 29 Aug 2026 13:37:06 +0800 Subject: [PATCH 1/2] fix: fall back to PATH on Windows --- lib/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index 2fd358b..4ffbb11 100644 --- a/lib/index.js +++ b/lib/index.js @@ -20,12 +20,13 @@ const getPathInfo = (cmd, { pathExt: optPathExt = process.env.PATHEXT, delimiter: optDelimiter = delimiter, }) => { + const pathEnvValue = optPath === undefined && isWindows ? process.env.Path : optPath // If it has a slash, then we don't bother searching the pathenv. // just check the file itself, and that's it. const pathEnv = cmd.match(rSlash) ? [''] : [ // windows always checks the cwd first ...(isWindows ? [process.cwd()] : []), - ...(optPath || /* istanbul ignore next: very unusual */ '').split(optDelimiter), + ...(pathEnvValue || /* istanbul ignore next: very unusual */ '').split(optDelimiter), ] if (isWindows) { From b5cf664ced61f45f6e9d16edaaf54be2124ecc49 Mon Sep 17 00:00:00 2001 From: amtbsl <147152854+amtbsl@users.noreply.github.com> Date: Sat, 29 Aug 2026 13:37:13 +0800 Subject: [PATCH 2/2] test: cover Windows Path fallback --- test/index.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/test/index.js b/test/index.js index c77fed5..0fea714 100644 --- a/test/index.js +++ b/test/index.js @@ -4,7 +4,7 @@ const fs = require('fs') const { basename, join, relative, sep, delimiter } = require('path') const isWindows = process.platform === 'win32' -const ENV_VARS = { PATH: process.env.PATH, PATHEXT: process.env.PATHEXT } +const ENV_VARS = { PATH: process.env.PATH, Path: process.env.Path, PATHEXT: process.env.PATHEXT } const PLATFORM = Object.getOwnPropertyDescriptor(process, 'platform') const runTest = async (t, exec, expect, { platforms = ['posix', 'win32'], ..._opt } = {}) => { @@ -114,6 +114,19 @@ t.test('find when executable', async t => { }) }) +t.test('falls back to process.env.Path on Windows', async t => { + const fixture = t.testdir({ 'foo.sh': 'echo foo\n' }) + const foo = join(fixture, 'foo.sh') + fs.chmodSync(foo, 0o755) + delete process.env.PATH + process.env.Path = fixture + + await runTest(t, basename(foo), foo, { + platforms: ['win32'], + pathExt: '.sh', + }) +}) + t.test('find all', async t => { const cmdName = 'x.cmd' const fixture = t.testdir({