Skip to content

Commit 33fa6f4

Browse files
committed
fix: wrongly normalizing slashes in windows
This change takes code from npm's cli to change the way the arguments passed to nodemon are interpreted. Removes path.normalize and replaces with windowsVerbatimArguments Fixes #1236
1 parent 4cfd0b9 commit 33fa6f4

File tree

1 file changed

+10
-24
lines changed

1 file changed

+10
-24
lines changed

lib/monitor/run.js

+10-24
Original file line numberDiff line numberDiff line change
@@ -42,36 +42,22 @@ function run(options) {
4242
var sh = 'sh';
4343
var shFlag = '-c';
4444

45-
if (utils.isWindows) {
46-
sh = 'cmd';
47-
shFlag = '/c';
48-
}
4945

50-
var executable = cmd.executable;
46+
const spawnOptions = {
47+
env: utils.merge(options.execOptions.env, process.env),
48+
stdio: stdio,
49+
}
5150

5251
if (utils.isWindows) {
53-
// under windows if the executable path contains a forward slash, that will
54-
// fail with cmd.exe, so we need to normalize it
55-
if (executable.indexOf('/') !== -1) {
56-
executable = path.normalize(executable);
57-
}
58-
59-
// if the executable path contains a space the whole string must be quoted
60-
// to get windows treat it as 1 argument for cmd.exe
61-
if (executable.indexOf(' ') !== -1 && executable[0] !== '\"'
62-
&& executable[executable.length - 1] !== '\"') {
63-
// remove all quotes from executable (possible backward compat hacks)
64-
executable = executable.replace(/\"/g, '');
65-
}
52+
// taken from npm's cli: https://git.io/vNFD4
53+
sh = process.env.comspec || 'cmd';
54+
shFlag = '/d /s /c';
55+
spawnOptions.windowsVerbatimArguments = true;
6656
}
6757

58+
var executable = cmd.executable;
6859
var args = runCmd ? utils.stringify(executable, cmd.args) : ':';
69-
var spawnArgs = [sh, [shFlag, args]];
70-
71-
spawnArgs.push({
72-
env: utils.merge(options.execOptions.env, process.env),
73-
stdio: stdio,
74-
});
60+
var spawnArgs = [sh, [shFlag, args], spawnOptions];
7561

7662
const firstArg = cmd.args[0] || '';
7763

0 commit comments

Comments
 (0)