Skip to content

Commit

Permalink
fix: add .cmd to commands on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanhleung committed Jan 27, 2021
1 parent c695ca7 commit f6227e4
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/install-peerdeps.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,18 @@ function encodePackageName(packageName) {
* @returns {Promise} - a Promise which resolves when the install process is finished
*/
const spawnCommand = (command, args) => {
const isWindows = process.platform === "win32";
let extra = "";
if (isWindows && !command.endsWith(".cmd")) {
// Spawn doesn't work without this extra stuff in Windows
// See https://github.com/nodejs/node/issues/3675
extra = ".cmd";
}

return new Promise((resolve, reject) => {
let stdout = "";
let stderr = "";
const cmdProcess = spawn(command, args, {
const cmdProcess = spawn(command + extra, args, {
cwd: process.cwd()
});
cmdProcess.stdout.on("data", chunk => {
Expand Down Expand Up @@ -229,13 +237,6 @@ function installPeerDeps(
if (!dev) {
devFlag = "";
}
const isWindows = process.platform === "win32";
let extra = "";
if (isWindows) {
// Spawn doesn't work without this extra stuff in Windows
// See https://github.com/nodejs/node/issues/3675
extra = ".cmd";
}

let args = [];
// I know I can push it, but I'll just
Expand Down Expand Up @@ -301,7 +302,7 @@ function installPeerDeps(
} else {
console.log(`Installing peerdeps for ${packageName}@${version}.`);
console.log(commandString);
spawnCommand(packageManager + extra, args)
spawnCommand(packageManager, args)
.then(() => cb(null))
.catch(err => cb(err));
}
Expand Down

0 comments on commit f6227e4

Please sign in to comment.