From 7fb365d0cc6f6225c9b82af3bd64055b90ac3c8c Mon Sep 17 00:00:00 2001 From: Remy Sharp Date: Tue, 27 Feb 2018 16:44:14 +0000 Subject: [PATCH] feat: try to resolve exec in node_modules/.bin (#1275) Fixes #1268 --- lib/monitor/run.js | 25 +++++++++++++++++++------ package-lock.json | 36 ++++++++++++++++++------------------ package.json | 4 ++-- 3 files changed, 39 insertions(+), 26 deletions(-) diff --git a/lib/monitor/run.js b/lib/monitor/run.js index f7505565..a0d07124 100644 --- a/lib/monitor/run.js +++ b/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'); @@ -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, } @@ -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'); diff --git a/package-lock.json b/package-lock.json index c446099f..1eff6dd0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -44,7 +44,7 @@ "pos": "0.4.2", "rc": "1.2.2", "resolve-from": "3.0.0", - "semver": "5.4.1" + "semver": "5.5.0" } }, "@semantic-release/commit-analyzer": { @@ -87,7 +87,7 @@ "@semantic-release/error": "2.1.0", "github": "12.1.0", "parse-github-repo-url": "1.4.1", - "semver": "5.4.1", + "semver": "5.5.0", "travis-deploy-once": "3.0.0" }, "dependencies": { @@ -900,7 +900,7 @@ "json-stringify-safe": "5.0.1", "lodash": "4.17.4", "meow": "3.7.0", - "semver": "5.4.1", + "semver": "5.5.0", "split": "1.0.1", "through2": "2.0.3" }, @@ -2525,7 +2525,7 @@ "dev": true, "requires": { "meow": "3.7.0", - "semver": "5.4.1" + "semver": "5.5.0" } }, "gitconfiglocal": { @@ -4227,7 +4227,7 @@ "requires": { "hosted-git-info": "2.5.0", "is-builtin-module": "1.0.0", - "semver": "5.4.1", + "semver": "5.5.0", "validate-npm-package-license": "3.0.1" } }, @@ -4247,7 +4247,7 @@ "requires": { "hosted-git-info": "2.5.0", "osenv": "0.1.4", - "semver": "5.4.1", + "semver": "5.5.0", "validate-npm-package-name": "3.0.0" } }, @@ -4265,7 +4265,7 @@ "once": "1.4.0", "request": "2.74.0", "retry": "0.10.1", - "semver": "5.4.1", + "semver": "5.5.0", "slide": "1.1.6", "ssri": "4.1.6" } @@ -4558,7 +4558,7 @@ "got": "6.7.1", "registry-auth-token": "3.3.1", "registry-url": "3.1.0", - "semver": "5.4.1" + "semver": "5.5.0" } }, "parse-github-repo-url": { @@ -5058,7 +5058,7 @@ "p-series": "1.0.0", "parse-github-repo-url": "1.4.1", "require-relative": "0.8.7", - "semver": "5.4.1" + "semver": "5.5.0" }, "dependencies": { "execa": { @@ -5089,16 +5089,16 @@ } }, "semver": { - "version": "5.4.1", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.4.1.tgz", - "integrity": "sha1-4FnAnYVx8FQII3M0M1BdOi8AsY4=" + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.5.0.tgz", + "integrity": "sha512-4SJ3dm0WAwWy/NVeioZh5AntkdJoWKxHxcmyP622fOkgHa4z3R0TdBJICINyaSDE6uNwVc8gZr+ZinwZAH4xIA==" }, "semver-diff": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/semver-diff/-/semver-diff-2.1.0.tgz", "integrity": "sha1-S7uEN8jTfksM8aaP1ybsbWRdbTY=", "requires": { - "semver": "5.4.1" + "semver": "5.5.0" } }, "set-blocking": { @@ -5805,7 +5805,7 @@ "requires": { "chalk": "2.3.0", "p-retry": "1.0.0", - "semver": "5.4.1", + "semver": "5.5.0", "travis-ci": "2.1.1" } }, @@ -5920,9 +5920,9 @@ "dev": true }, "undefsafe": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/undefsafe/-/undefsafe-2.0.1.tgz", - "integrity": "sha1-A7LyoWyUVW4Usu3vMmzWaq+CcHo=", + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/undefsafe/-/undefsafe-2.0.2.tgz", + "integrity": "sha1-Il9rngM3Zj4Njnz9aG/Cg2zKznY=", "requires": { "debug": "2.6.9" }, @@ -6273,7 +6273,7 @@ "which": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/which/-/which-1.3.0.tgz", - "integrity": "sha1-/wS9/AEO5UfXgL7DjhrBwnd9JTo=", + "integrity": "sha512-xcJpopdamTuY5duC/KnTTNBraPK54YwpenP4lzxU8H91GudWpFv38u0CKjclE1Wi2EH2EDz5LRcHcKbCIzqGyg==", "requires": { "isexe": "2.0.0" } diff --git a/package.json b/package.json index bb03c369..5192499b 100644 --- a/package.json +++ b/package.json @@ -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"