Skip to content

Commit 1dc2083

Browse files
authored
fix(cli): use shell on win32 for update (#1503) (#1504)
If there is no `npm.exe` on the system, but instead an `npm.cmd`, then node won't find the `npm` executable when calling `spawnSync`. This occurs frequently when using node package managers on Windows. See the node documentation for `.bat` and `.cmd` files here. <https://nodejs.org/api/child_process.html#spawning-bat-and-cmd-files-on-windows>.
1 parent 3d0ba32 commit 1dc2083

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

quartz/cli/handlers.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,25 @@ export async function handleUpdate(argv) {
457457

458458
await popContentFolder(contentFolder)
459459
console.log("Ensuring dependencies are up to date")
460-
const res = spawnSync("npm", ["i"], { stdio: "inherit" })
460+
461+
/*
462+
On Windows, if the command `npm` is really `npm.cmd', this call fails
463+
as it will be unable to find `npm`. This is often the case on systems
464+
where `npm` is installed via a package manager.
465+
466+
This means `npx quartz update` will not actually update dependencies
467+
on Windows, without a manual `npm i` from the caller.
468+
469+
However, by spawning a shell, we are able to call `npm.cmd`.
470+
See: https://nodejs.org/api/child_process.html#spawning-bat-and-cmd-files-on-windows
471+
*/
472+
473+
const opts = { stdio: "inherit" }
474+
if (process.platform === "win32") {
475+
opts.shell = true
476+
}
477+
478+
const res = spawnSync("npm", ["i"], opts)
461479
if (res.status === 0) {
462480
console.log(chalk.green("Done!"))
463481
} else {

0 commit comments

Comments
 (0)