mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-26 02:05:31 +00:00
fix(plugins): start a Windows bare name directly when the caller passes shell: false
The PATH lookup that finds a .cmd shim ran statSync for every bare name, including git with shell: false, so a daemon Git refresh did synchronous IO on Windows. An explicit shell: false now starts the name directly, as on main, and Windows searches PATH itself. The daemon's git --version probe passes shell: false like its other git commands.
This commit is contained in:
@@ -140,6 +140,26 @@ test("a Windows launch quotes for cmd.exe only when cmd.exe parses the command l
|
||||
});
|
||||
});
|
||||
|
||||
// The daemon runs git with `shell: false` on hot paths that must not block on synchronous IO, so
|
||||
// an explicit `shell: false` starts a bare name directly and leaves the PATH search to Windows.
|
||||
test("a Windows bare name searches PATH for a script only when the caller allows a shell", async () => {
|
||||
const directory = await mkdtemp(path.join(os.tmpdir(), "plugin-path-shim-"));
|
||||
roots.push(directory);
|
||||
await writeFile(path.join(directory, "tool.CMD"), "");
|
||||
const env = { ...windowsEnv, PATH: directory };
|
||||
expect(resolveSpawnInvocation("tool", ["a & b"], false, "win32", env)).toEqual({
|
||||
command: "tool",
|
||||
args: ["a & b"],
|
||||
shell: false,
|
||||
});
|
||||
expect(resolveSpawnInvocation("tool", ["a & b"], undefined, "win32", env)).toEqual({
|
||||
command: windowsEnv.ComSpec,
|
||||
args: ["/d", "/s", "/c", `"${path.join(directory, "tool.CMD")} ^"a^ ^&^ b^""`],
|
||||
shell: false,
|
||||
windowsVerbatimArguments: true,
|
||||
});
|
||||
});
|
||||
|
||||
// Real Git Bash on Windows: the arguments reach Bash as given, without cmd.exe escapes.
|
||||
test.runIf(process.platform === "win32")(
|
||||
"execCommand passes arguments as given to a Windows shell other than cmd.exe",
|
||||
|
||||
@@ -51,8 +51,8 @@ function namesCmd(shell: boolean | string | undefined): boolean {
|
||||
/**
|
||||
* How `spawnProcess` and `execCommand` start `command` on `platform`.
|
||||
*
|
||||
* On Windows a bare name is first found on `PATH`, as cmd.exe would find it. A program then starts
|
||||
* directly. A `.cmd` or `.bat` script, a name that is not on `PATH` (a cmd.exe builtin), or a
|
||||
* On Windows a bare name is first found on `PATH`, as cmd.exe would find it, unless the caller
|
||||
* passes `shell: false`. A program then starts directly. A `.cmd` or `.bat` script, a name that is not on `PATH` (a cmd.exe builtin), or a
|
||||
* `shell: true` launch runs as `cmd.exe /d /s /c "..."`, quoted by `windowsCommandLine`. A shell
|
||||
* the caller names other than cmd.exe gets the command and arguments as given.
|
||||
*/
|
||||
@@ -68,7 +68,8 @@ export function resolveSpawnInvocation(
|
||||
return { command, args: [...args], shell: requestedShell };
|
||||
}
|
||||
const bareName = !/[\\/]/u.test(command) && !extname(command);
|
||||
const found = bareName ? findWindowsCommand(command, env) : undefined;
|
||||
// `shell: false` starts a bare name directly, and Windows searches PATH without blocking Node.
|
||||
const found = bareName && requestedShell !== false ? findWindowsCommand(command, env) : undefined;
|
||||
const target = found ?? command;
|
||||
const commandScript = isWindowsCommandScript(target, platform);
|
||||
// Only cmd.exe knows a builtin, so a bare name off `PATH` goes to it unless the caller said no shell.
|
||||
|
||||
@@ -113,7 +113,8 @@ let safeBareRepositorySupport: Promise<boolean> | null = null;
|
||||
|
||||
/** Reads `git --version` once per process. */
|
||||
export function readSafeBareRepositorySupport(): Promise<boolean> {
|
||||
safeBareRepositorySupport ??= execCommand("git", ["--version"]).then(
|
||||
// Started like every daemon git command, directly and without a PATH lookup in Node.
|
||||
safeBareRepositorySupport ??= execCommand("git", ["--version"], { shell: false }).then(
|
||||
({ stdout }) => parseSafeBareRepositorySupport(stdout),
|
||||
() => false,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user