Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add .cmd to commands on windows #124

Merged
merged 2 commits into from
Jan 29, 2021
Merged
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
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,7 @@
"@babel/polyfill": "^7.7.0",
"cli-color": "^2.0.0",
"commander": "^4.0.1",
"https-proxy-agent": "^4.0.0",
"promptly": "^3.0.3",
"request": "^2.83.0",
"request-promise-native": "^1.0.5",
"semver": "^6.3.0"
},
"devDependencies": {
Expand Down
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