summaryrefslogtreecommitdiff
path: root/deps/npm/lib/utils/lifecycle.js
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/lib/utils/lifecycle.js')
-rw-r--r--deps/npm/lib/utils/lifecycle.js19
1 files changed, 16 insertions, 3 deletions
diff --git a/deps/npm/lib/utils/lifecycle.js b/deps/npm/lib/utils/lifecycle.js
index 6a862366f2..adf534d882 100644
--- a/deps/npm/lib/utils/lifecycle.js
+++ b/deps/npm/lib/utils/lifecycle.js
@@ -15,6 +15,7 @@ var uidNumber = require('uid-number')
var umask = require('./umask')
var usage = require('./usage')
var output = require('./output.js')
+var which = require('which')
// windows calls it's path 'Path' usually, but this is not guaranteed.
if (process.platform === 'win32') {
@@ -88,7 +89,7 @@ function _incorrectWorkingDirectory (wd, pkg) {
function lifecycle_ (pkg, stage, wd, env, unsafe, failOk, cb) {
var pathArr = []
- var p = wd.split('node_modules')
+ var p = wd.split(/[\\\/]node_modules[\\\/]/)
var acc = path.resolve(p.shift())
p.forEach(function (pp) {
@@ -101,8 +102,10 @@ function lifecycle_ (pkg, stage, wd, env, unsafe, failOk, cb) {
// the bundled one will be used for installing things.
pathArr.unshift(path.join(__dirname, '..', '..', 'bin', 'node-gyp-bin'))
- // prefer current node interpreter in child scripts
- pathArr.push(path.dirname(process.execPath))
+ if (shouldPrependCurrentNodeDirToPATH()) {
+ // prefer current node interpreter in child scripts
+ pathArr.push(path.dirname(process.execPath))
+ }
if (env[PATH]) pathArr.push(env[PATH])
env[PATH] = pathArr.join(process.platform === 'win32' ? ';' : ':')
@@ -138,6 +141,16 @@ function lifecycle_ (pkg, stage, wd, env, unsafe, failOk, cb) {
)
}
+function shouldPrependCurrentNodeDirToPATH () {
+ var isWindows = process.platform === 'win32'
+ try {
+ var foundExecPath = which.sync(path.basename(process.execPath), {pathExt: isWindows ? ';' : ':'})
+ return process.execPath.toUpperCase() !== foundExecPath.toUpperCase()
+ } catch (e) {
+ return true
+ }
+}
+
function validWd (d, cb) {
fs.stat(d, function (er, st) {
if (er || !st.isDirectory()) {