Skip to content

Commit 4175e6c

Browse files
committed
fix: quote paths in npm command execution to handle spaces in Windows file paths
1 parent 23a215d commit 4175e6c

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

adminforth/commands/createApp/utils.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,11 +289,15 @@ async function installDependencies(ctx, cwd) {
289289

290290
const nodeBinary = process.execPath;
291291
const npmPath = path.join(path.dirname(nodeBinary), npmCmd);
292-
console.log("npmPath",`${nodeBinary} ${npmPath} install`);
292+
293+
// Quote paths if they contain spaces to handle paths like "C:\Program Files\nodejs\"
294+
const quotedNodeBinary = nodeBinary.includes(' ') ? `"${nodeBinary}"` : nodeBinary;
295+
const quotedNpmPath = npmPath.includes(' ') ? `"${npmPath}"` : npmPath;
296+
293297
const customDir = ctx.customDir;
294298
const res = await Promise.all([
295-
await execAsync(`${nodeBinary} ${npmPath} install`, { cwd, env: { PATH: process.env.PATH } }),
296-
await execAsync(`${nodeBinary} ${npmPath} install`, { cwd: customDir, env: { PATH: process.env.PATH } }),
299+
await execAsync(`${quotedNodeBinary} ${quotedNpmPath} install`, { cwd, env: { PATH: process.env.PATH } }),
300+
await execAsync(`${quotedNodeBinary} ${quotedNpmPath} install`, { cwd: customDir, env: { PATH: process.env.PATH } }),
297301
]);
298302
// console.log(chalk.dim(`Dependencies installed in ${cwd} and ${customDir}: \n${res[0].stdout}${res[1].stdout}`));
299303
}

0 commit comments

Comments
 (0)