Skip to content
Merged
33 changes: 20 additions & 13 deletions packages/shared/src/shell.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -558,19 +558,26 @@ effectIt.layer(NodeServices.layer)("resolveCommandPath", (it) => {
const executable = path.join(cwd, "audit-command.cmd");
yield* fs.writeFileString(executable, "@echo off\n");

const resolved = yield* resolveCommandPath(command, {
env: { PATH: cwd, PATHEXT: ".CMD" },
}).pipe(
Effect.provideService(HostProcess.Platform, "win32"),
Effect.provideService(CommandResolutionCache, new Map()),
Effect.provideService(FileSystem.FileSystem, {
...fs,
stat: (filePath) =>
fs.stat(filePath === executable ? filePath : path.join(cwd, "missing")),
}),
);

expect(resolved).toBe(executable);
const decoy = path.join(cwd, "audit-command.exe");
yield* fs.writeFileString(decoy, "");
for (const key of ["PATHEXT", "PathExt", "pathext"]) {
const resolved = yield* resolveCommandPath(command, {
env: { PATH: cwd, [key]: ".CMD" },
}).pipe(
Effect.provideService(HostProcess.Platform, "win32"),
Effect.provideService(CommandResolutionCache, new Map()),
Effect.provideService(FileSystem.FileSystem, {
...fs,
stat: (filePath) =>
fs.stat(
filePath === executable || filePath === decoy
? filePath
: path.join(cwd, "missing"),
),
}),
);
expect(resolved).toBe(executable);
}
}),
);

Expand Down
6 changes: 5 additions & 1 deletion packages/shared/src/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,11 @@ function resolvePathEnvironmentVariable(env: NodeJS.ProcessEnv): string {
}

function resolveWindowsPathExtensions(env: NodeJS.ProcessEnv): ReadonlyArray<string> {
const rawValue = env.PATHEXT;
const rawValue =
env.PATHEXT ??
Object.entries(env).find(
([key, value]) => key.toUpperCase() === "PATHEXT" && value !== undefined,
)?.[1];
const fallback = [".COM", ".EXE", ".BAT", ".CMD"];
if (!rawValue) return fallback;

Expand Down
Loading