The Trans Directory
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>.

authored by

Sohum and committed by
GitHub
1dc20835 3d0ba320

+19 -1
+19 -1
quartz/cli/handlers.js
··· 457 457 458 458 await popContentFolder(contentFolder) 459 459 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) 461 479 if (res.status === 0) { 462 480 console.log(chalk.green("Done!")) 463 481 } else {