Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion scripts/dev.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,22 @@ export function developmentServiceEnvironment(prepared, base = process.env) {
return environment;
}

export function usesWindowsCmdShell(command, platform = process.platform) {
return platform === "win32" && /\.(cmd|bat)$/i.test(command);
}

export function run(
command,
args,
{ cwd = repoRoot, label = [command, ...args].join(" "), environment = process.env } = {},
) {
return new Promise((resolve, reject) => {
const child = spawn(command, args, { cwd, env: environment, stdio: "inherit" });
const child = spawn(command, args, {
cwd,
env: environment,
stdio: "inherit",
shell: usesWindowsCmdShell(command),
});
child.once("error", (error) => {
const hint =
error.code === "ENOENT"
Expand Down
9 changes: 9 additions & 0 deletions scripts/dev.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
prepareDevEnv,
setEnvIfBlank,
usesLocalStorage,
usesWindowsCmdShell,
} from "./dev.mjs";

const example = [
Expand Down Expand Up @@ -280,3 +281,11 @@ test("an exported development origin overrides the env file, and a blank one is
});
assert.equal(blank.devOrigins, "from-file.example.dev");
});

test("Windows .cmd/.bat spawns use a shell so Node does not throw EINVAL", () => {
assert.equal(usesWindowsCmdShell("pnpm.cmd", "win32"), true);
assert.equal(usesWindowsCmdShell("pnpm.bat", "win32"), true);
assert.equal(usesWindowsCmdShell("pnpm", "win32"), false);
assert.equal(usesWindowsCmdShell("docker", "win32"), false);
assert.equal(usesWindowsCmdShell("pnpm.cmd", "linux"), false);
});