Skip to content

Commit

Permalink
feat: try to resolve exec in node_modules/.bin (#1275)
Browse files Browse the repository at this point in the history
Fixes #1268
  • Loading branch information
remy committed Feb 27, 2018
1 parent 7ffd545 commit 7fb365d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 26 deletions.
25 changes: 19 additions & 6 deletions lib/monitor/run.js
@@ -1,4 +1,5 @@
var debug = require('debug')('nodemon');
const statSync = require('fs').statSync;
var utils = require('../utils');
var bus = utils.bus;
var childProcess = require('child_process');
Expand Down Expand Up @@ -39,12 +40,15 @@ function run(options) {
stdio = [process.stdin, process.stdout, process.stderr];
}

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

const binPath = process.cwd() + '/node_modules/.bin';

const spawnOptions = {
env: utils.merge(options.execOptions.env, process.env),
env: Object.assign({}, process.env, options.execOptions.env, {
PATH: binPath + ':' + process.env.PATH,
}),
stdio: stdio,
}

Expand Down Expand Up @@ -73,17 +77,26 @@ function run(options) {

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

var inBinPath = false;
try {
inBinPath = statSync(`${binPath}/${executable}`).isFile();
} catch (e) {}

// hasStdio allows us to correctly handle stdin piping
// see: https://git.io/vNtX3
const hasStdio = utils.satisfies('>= 6.4.0 || < 5');

if (
// forking helps with sub-process handling and tends to clean up better
// than spawning, but it should only be used under specific conditions
const shouldFork =
!config.options.spawn &&
firstArg.indexOf('-') === -1 && // don't fork if there's a node arg
!inBinPath &&
firstArg.indexOf('-') === -1 && // don't fork if there's a node exec arg
firstArg !== 'inspect' && // don't fork it's `inspect` debugger
executable === 'node' && // only fork if node
utils.version.major > 4 // only fork if node version > 4
) {

if (shouldFork) {
var forkArgs = cmd.args.slice(1);
var env = utils.merge(options.execOptions.env, process.env);
stdio.push('ipc');
Expand Down
36 changes: 18 additions & 18 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -60,10 +60,10 @@
"ignore-by-default": "^1.0.1",
"minimatch": "^3.0.4",
"pstree.remy": "^1.1.0",
"semver": "^5.4.1",
"semver": "^5.5.0",
"supports-color": "^5.2.0",
"touch": "^3.1.0",
"undefsafe": "^2.0.1",
"undefsafe": "^2.0.2",
"update-notifier": "^2.3.0"
},
"version": "1.15.2-alpha.1"
Expand Down

0 comments on commit 7fb365d

Please sign in to comment.