Skip to content

Commit 7fb365d

Browse files
authored
feat: try to resolve exec in node_modules/.bin (#1275)
Fixes #1268
1 parent 7ffd545 commit 7fb365d

File tree

3 files changed

+39
-26
lines changed

3 files changed

+39
-26
lines changed

lib/monitor/run.js

+19-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var debug = require('debug')('nodemon');
2+
const statSync = require('fs').statSync;
23
var utils = require('../utils');
34
var bus = utils.bus;
45
var childProcess = require('child_process');
@@ -39,12 +40,15 @@ function run(options) {
3940
stdio = [process.stdin, process.stdout, process.stderr];
4041
}
4142

42-
var sh = 'sh';
43-
var shFlag = '-c';
43+
const sh = 'sh';
44+
const shFlag = '-c';
4445

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

4648
const spawnOptions = {
47-
env: utils.merge(options.execOptions.env, process.env),
49+
env: Object.assign({}, process.env, options.execOptions.env, {
50+
PATH: binPath + ':' + process.env.PATH,
51+
}),
4852
stdio: stdio,
4953
}
5054

@@ -73,17 +77,26 @@ function run(options) {
7377

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

80+
var inBinPath = false;
81+
try {
82+
inBinPath = statSync(`${binPath}/${executable}`).isFile();
83+
} catch (e) {}
84+
7685
// hasStdio allows us to correctly handle stdin piping
7786
// see: https://git.io/vNtX3
7887
const hasStdio = utils.satisfies('>= 6.4.0 || < 5');
7988

80-
if (
89+
// forking helps with sub-process handling and tends to clean up better
90+
// than spawning, but it should only be used under specific conditions
91+
const shouldFork =
8192
!config.options.spawn &&
82-
firstArg.indexOf('-') === -1 && // don't fork if there's a node arg
93+
!inBinPath &&
94+
firstArg.indexOf('-') === -1 && // don't fork if there's a node exec arg
8395
firstArg !== 'inspect' && // don't fork it's `inspect` debugger
8496
executable === 'node' && // only fork if node
8597
utils.version.major > 4 // only fork if node version > 4
86-
) {
98+
99+
if (shouldFork) {
87100
var forkArgs = cmd.args.slice(1);
88101
var env = utils.merge(options.execOptions.env, process.env);
89102
stdio.push('ipc');

package-lock.json

+18-18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@
6060
"ignore-by-default": "^1.0.1",
6161
"minimatch": "^3.0.4",
6262
"pstree.remy": "^1.1.0",
63-
"semver": "^5.4.1",
63+
"semver": "^5.5.0",
6464
"supports-color": "^5.2.0",
6565
"touch": "^3.1.0",
66-
"undefsafe": "^2.0.1",
66+
"undefsafe": "^2.0.2",
6767
"update-notifier": "^2.3.0"
6868
},
6969
"version": "1.15.2-alpha.1"

0 commit comments

Comments
 (0)