Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: try to resolve exec in node_modules/.bin #1275

Merged
merged 3 commits into from
Feb 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions lib/monitor/run.js
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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