Skip to content

Commit 18b9918

Browse files
committed
fix: improve npm execution logic for better Windows compatibility in CodeInjector
1 parent c7b9201 commit 18b9918

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

adminforth/modules/codeInjector.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -894,18 +894,21 @@ class CodeInjector implements ICodeInjector {
894894

895895
const command = 'run dev';
896896
console.log(`⚙️ spawn: npm ${command}...`);
897-
const nodeBinary = process.execPath;
898-
// On Windows, npm is npm.cmd, on Unix systems it's npm
899-
const npmExecutable = process.platform === 'win32' ? 'npm.cmd' : 'npm';
900-
const npmPath = path.join(path.dirname(nodeBinary), npmExecutable);
901897
const env = {
902898
VITE_ADMINFORTH_PUBLIC_PATH: this.adminforth.config.baseUrl,
903899
FORCE_COLOR: '1',
904900
...process.env,
905901
};
906902

907-
// Execute npm directly (npm.cmd on Windows, npm on Unix)
908-
const devServer = spawn(npmPath, command.split(' '), { cwd, env });
903+
// Execute npm with proper Windows compatibility
904+
let devServer;
905+
if (process.platform === 'win32') {
906+
// On Windows, use shell to execute npm.cmd
907+
devServer = spawn('npm', command.split(' '), { cwd, env, shell: true });
908+
} else {
909+
// On Unix systems, execute npm directly
910+
devServer = spawn('npm', command.split(' '), { cwd, env });
911+
}
909912
devServer.stdout.on('data', (data) => {
910913
if (data.includes('➜')) {
911914
// TODO: maybe better use our string "App port: 5174. HMR port: 5274", it is more reliable because vue might change their output

0 commit comments

Comments
 (0)