|
1 | 1 | var debug = require('debug')('nodemon');
|
| 2 | +const statSync = require('fs').statSync; |
2 | 3 | var utils = require('../utils');
|
3 | 4 | var bus = utils.bus;
|
4 | 5 | var childProcess = require('child_process');
|
@@ -39,12 +40,15 @@ function run(options) {
|
39 | 40 | stdio = [process.stdin, process.stdout, process.stderr];
|
40 | 41 | }
|
41 | 42 |
|
42 |
| - var sh = 'sh'; |
43 |
| - var shFlag = '-c'; |
| 43 | + const sh = 'sh'; |
| 44 | + const shFlag = '-c'; |
44 | 45 |
|
| 46 | + const binPath = process.cwd() + '/node_modules/.bin'; |
45 | 47 |
|
46 | 48 | 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 | + }), |
48 | 52 | stdio: stdio,
|
49 | 53 | }
|
50 | 54 |
|
@@ -73,17 +77,26 @@ function run(options) {
|
73 | 77 |
|
74 | 78 | const firstArg = cmd.args[0] || '';
|
75 | 79 |
|
| 80 | + var inBinPath = false; |
| 81 | + try { |
| 82 | + inBinPath = statSync(`${binPath}/${executable}`).isFile(); |
| 83 | + } catch (e) {} |
| 84 | + |
76 | 85 | // hasStdio allows us to correctly handle stdin piping
|
77 | 86 | // see: https://git.io/vNtX3
|
78 | 87 | const hasStdio = utils.satisfies('>= 6.4.0 || < 5');
|
79 | 88 |
|
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 = |
81 | 92 | !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 |
83 | 95 | firstArg !== 'inspect' && // don't fork it's `inspect` debugger
|
84 | 96 | executable === 'node' && // only fork if node
|
85 | 97 | utils.version.major > 4 // only fork if node version > 4
|
86 |
| - ) { |
| 98 | + |
| 99 | + if (shouldFork) { |
87 | 100 | var forkArgs = cmd.args.slice(1);
|
88 | 101 | var env = utils.merge(options.execOptions.env, process.env);
|
89 | 102 | stdio.push('ipc');
|
|
0 commit comments