Skip to content

Commit f6227e4

Browse files
committed
fix: add .cmd to commands on windows
1 parent c695ca7 commit f6227e4

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/install-peerdeps.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,18 @@ function encodePackageName(packageName) {
3030
* @returns {Promise} - a Promise which resolves when the install process is finished
3131
*/
3232
const spawnCommand = (command, args) => {
33+
const isWindows = process.platform === "win32";
34+
let extra = "";
35+
if (isWindows && !command.endsWith(".cmd")) {
36+
// Spawn doesn't work without this extra stuff in Windows
37+
// See https://github.com/nodejs/node/issues/3675
38+
extra = ".cmd";
39+
}
40+
3341
return new Promise((resolve, reject) => {
3442
let stdout = "";
3543
let stderr = "";
36-
const cmdProcess = spawn(command, args, {
44+
const cmdProcess = spawn(command + extra, args, {
3745
cwd: process.cwd()
3846
});
3947
cmdProcess.stdout.on("data", chunk => {
@@ -229,13 +237,6 @@ function installPeerDeps(
229237
if (!dev) {
230238
devFlag = "";
231239
}
232-
const isWindows = process.platform === "win32";
233-
let extra = "";
234-
if (isWindows) {
235-
// Spawn doesn't work without this extra stuff in Windows
236-
// See https://github.com/nodejs/node/issues/3675
237-
extra = ".cmd";
238-
}
239240

240241
let args = [];
241242
// I know I can push it, but I'll just
@@ -301,7 +302,7 @@ function installPeerDeps(
301302
} else {
302303
console.log(`Installing peerdeps for ${packageName}@${version}.`);
303304
console.log(commandString);
304-
spawnCommand(packageManager + extra, args)
305+
spawnCommand(packageManager, args)
305306
.then(() => cb(null))
306307
.catch(err => cb(err));
307308
}

0 commit comments

Comments
 (0)