Skip to content

Commit

Permalink
fix: put windows drive letter tweak in right place
Browse files Browse the repository at this point in the history
Ref #1263
  • Loading branch information
remy committed Feb 26, 2018
1 parent 1cda8fa commit 392a31e
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 42 deletions.
47 changes: 13 additions & 34 deletions lib/monitor/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,51 +14,30 @@ var restart = null;
var psTree = require('pstree.remy');
var path = require('path');
var signals = require('./signals');
const getSpawnArgs = require('./spawn-args');

function run(options) {
var cmd = config.command.raw;

var runCmd = !options.runOnChangeOnly || config.lastStarted !== 0;
if (runCmd) {
utils.log.status('starting `' + config.command.string + '`');
}

/*jshint validthis:true*/
restart = run.bind(this, options);
run.restart = restart;

config.lastStarted = Date.now();

var stdio = ['pipe', 'pipe', 'pipe'];

if (config.options.stdout) {
stdio = ['pipe', process.stdout, process.stderr];
}

if (config.options.stdin === false) {
stdio = [process.stdin, process.stdout, process.stderr];
}
const {
args,
cmd,
executable,
runCmd,
sh,
shFlag,
spawnArgs,
stdio,
} = getSpawnArgs({ options, config });

var sh = 'sh';
var shFlag = '-c';


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

if (utils.isWindows) {
// taken from npm's cli: https://git.io/vNFD4
sh = process.env.comspec || 'cmd';
shFlag = '/d /s /c';
spawnOptions.windowsVerbatimArguments = true;
if (runCmd) {
utils.log.status('starting `' + config.command.string + '`');
}

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

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

// hasStdio allows us to correctly handle stdin piping
Expand Down
46 changes: 46 additions & 0 deletions lib/monitor/spawn-args.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const utils = require('../utils');

module.exports = ({ options, config }) => {

var stdio = ['pipe', 'pipe', 'pipe'];

if (config.options.stdout) {
stdio = ['pipe', process.stdout, process.stderr];
}

if (config.options.stdin === false) {
stdio = [process.stdin, process.stdout, process.stderr];
}

var sh = 'sh';
var shFlag = '-c';

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

if (utils.isWindows) {
// taken from npm's cli: https://git.io/vNFD4
sh = process.env.comspec || 'cmd';
shFlag = '/d /s /c';
spawnOptions.windowsVerbatimArguments = true;
}

var runCmd = !options.runOnChangeOnly || config.lastStarted !== 0;
var cmd = config.command.raw;
var executable = cmd.executable;
var args = runCmd ? utils.stringify(executable, cmd.args) : ':';
var spawnArgs = [sh, [shFlag, args], spawnOptions];

return {
args,
cmd,
executable,
runCmd,
sh,
shFlag,
spawnArgs,
stdio,
};
}
15 changes: 8 additions & 7 deletions lib/monitor/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,6 @@ function filterAndRestart(files) {
files = [files];
}
if (files.length) {
if (utils.isWindows) {
// ensure the drive letter is in uppercase (c:\foo -> C:\foo)
files = files.map(function (f) {
return f[0].toUpperCase() + f.slice(1);
});
}

var cwd = this.options ? this.options.cwd : process.cwd();
utils.log.detail(
'files triggering change check: ' +
Expand All @@ -150,6 +143,14 @@ function filterAndRestart(files) {
return path.relative(process.cwd(), path.join(cwd, file));
});

if (utils.isWindows) {
// ensure the drive letter is in uppercase (c:\foo -> C:\foo)
files = files.map(function (f) {
return f[0].toUpperCase() + f.slice(1);
});
}


debug('filterAndRestart on', files);

var matched = match(
Expand Down
39 changes: 39 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"istanbul": "^0.4.5",
"jscs": "^3.0.7",
"mocha": "^2.3.3",
"proxyquire": "^1.8.0",
"semantic-release": "^8.2.0",
"should": "~4.0.0"
},
Expand All @@ -64,5 +65,5 @@
"undefsafe": "^2.0.1",
"update-notifier": "^2.3.0"
},
"version": "0.0.0-development"
"version": "1.15.2-alpha.1"
}
31 changes: 31 additions & 0 deletions test/monitor/spawn-args.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*global describe:true, it: true, after: true, beforeEach */
const assert = require('assert');
const merge = require('../../lib/utils/merge');
const proxyquire = require('proxyquire').noPreserveCache();

describe('spawn args', () => {
it('handles windows urls correctly', () => {
const getSpawnArgs = proxyquire('../../lib/monitor/spawn-args', {
merge,
isWindows: true,
});

const res = getSpawnArgs({
options: {
execOptions: { env: [] },
},
config: {
options: {},
command: {
raw: 'touch'
}
},
});

console.log(res);

assert('ok');


});
});

0 comments on commit 392a31e

Please sign in to comment.