Skip to content

Commit fb0df18

Browse files
committed
fix: enhance cross-platform command execution in CodeInjector by refining npm execution logic
1 parent 6f5a65e commit fb0df18

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

adminforth/modules/codeInjector.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,30 @@ class CodeInjector implements ICodeInjector {
130130
process.env.HEAVY_DEBUG && console.log(`🪲 npm ${command} cwd:`, cwd);
131131
process.env.HEAVY_DEBUG && console.time(`npm ${command} done in`);
132132

133-
// Quote paths that contain spaces (especially important on Windows)
134-
const quotedNodeBinary = nodeBinary.includes(' ') ? `"${nodeBinary}"` : nodeBinary;
135-
const quotedNpmPath = npmPath.includes(' ') ? `"${npmPath}"` : npmPath;
133+
// On Windows, execute npm.cmd directly; on Unix, use node + npm
134+
let execCommand: string;
135+
if (process.platform === 'win32') {
136+
// Quote path if it contains spaces
137+
const quotedNpmPath = npmPath.includes(' ') ? `"${npmPath}"` : npmPath;
138+
execCommand = `${quotedNpmPath} ${command}`;
139+
} else {
140+
// Quote paths that contain spaces (for Unix systems)
141+
const quotedNodeBinary = nodeBinary.includes(' ') ? `"${nodeBinary}"` : nodeBinary;
142+
const quotedNpmPath = npmPath.includes(' ') ? `"${npmPath}"` : npmPath;
143+
execCommand = `${quotedNodeBinary} ${quotedNpmPath} ${command}`;
144+
}
136145

137-
const { stdout: out, stderr: err } = await execAsync(`${quotedNodeBinary} ${quotedNpmPath} ${command}`, {
146+
const execOptions: any = {
138147
cwd,
139148
env,
140-
});
149+
};
150+
151+
// On Windows, use shell to execute .cmd files
152+
if (process.platform === 'win32') {
153+
execOptions.shell = true;
154+
}
155+
156+
const { stdout: out, stderr: err } = await execAsync(execCommand, execOptions);
141157
process.env.HEAVY_DEBUG && console.timeEnd(`npm ${command} done in`);
142158

143159
// process.env.HEAVY_DEBUG && console.log(`🪲 npm ${command} output:`, out);

0 commit comments

Comments
 (0)