Skip to content

Commit

Permalink
fix: wrongly normalizing slashes in windows
Browse files Browse the repository at this point in the history
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
  • Loading branch information
remy committed Feb 1, 2018
1 parent 4cfd0b9 commit 33fa6f4
Showing 1 changed file with 10 additions and 24 deletions.
34 changes: 10 additions & 24 deletions lib/monitor/run.js
Expand Up @@ -42,36 +42,22 @@ function run(options) {
var sh = 'sh';
var shFlag = '-c';

if (utils.isWindows) {
sh = 'cmd';
shFlag = '/c';
}

var executable = cmd.executable;
const spawnOptions = {
env: utils.merge(options.execOptions.env, process.env),
stdio: stdio,
}

if (utils.isWindows) {
// under windows if the executable path contains a forward slash, that will
// fail with cmd.exe, so we need to normalize it
if (executable.indexOf('/') !== -1) {
executable = path.normalize(executable);
}

// if the executable path contains a space the whole string must be quoted
// to get windows treat it as 1 argument for cmd.exe
if (executable.indexOf(' ') !== -1 && executable[0] !== '\"'
&& executable[executable.length - 1] !== '\"') {
// remove all quotes from executable (possible backward compat hacks)
executable = executable.replace(/\"/g, '');
}
// taken from npm's cli: https://git.io/vNFD4
sh = process.env.comspec || 'cmd';
shFlag = '/d /s /c';
spawnOptions.windowsVerbatimArguments = true;
}

var executable = cmd.executable;
var args = runCmd ? utils.stringify(executable, cmd.args) : ':';
var spawnArgs = [sh, [shFlag, args]];

spawnArgs.push({
env: utils.merge(options.execOptions.env, process.env),
stdio: stdio,
});
var spawnArgs = [sh, [shFlag, args], spawnOptions];

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

Expand Down

0 comments on commit 33fa6f4

Please sign in to comment.