diff options
author | isaacs <i@izs.me> | 2014-08-30 03:21:34 +0400 |
---|---|---|
committer | Forrest L Norvell <forrest@npmjs.com> | 2014-08-30 04:28:47 +0400 |
commit | 0dc6a07c778071c94c2251429c7d107e88a45095 (patch) | |
tree | c79fbd1e80450befc8e3a580a72bfda8328ff774 /lib/run-script.js | |
parent | 65d2179af96737eb9038eaa24a293a62184aaa13 (diff) |
Run commands in prefix, not cwd
In general, we should never be relying on {cwd}/package.json.
The current working directory should be used for printing out relative
paths for human consumption, but npm should always walk up the directory
tree to find its working dir for *doing* stuff.
Fix #6059
Diffstat (limited to 'lib/run-script.js')
-rw-r--r-- | lib/run-script.js | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/lib/run-script.js b/lib/run-script.js index dd9dc37d5..6cb7bf7fb 100644 --- a/lib/run-script.js +++ b/lib/run-script.js @@ -21,7 +21,7 @@ runScript.completion = function (opts, cb) { if (argv.length === 3) { // either specified a script locally, in which case, done, // or a package, in which case, complete against its scripts - var json = path.join(npm.prefix, "package.json") + var json = path.join(npm.localPrefix, "package.json") return readJson(json, function (er, d) { if (er && er.code !== "ENOENT" && er.code !== "ENOTDIR") return cb(er) if (er) d = {} @@ -30,7 +30,7 @@ runScript.completion = function (opts, cb) { if (scripts.indexOf(argv[2]) !== -1) return cb() // ok, try to find out which package it was, then var pref = npm.config.get("global") ? npm.config.get("prefix") - : npm.prefix + : npm.localPrefix var pkgDir = path.resolve( pref, "node_modules" , argv[2], "package.json" ) readJson(pkgDir, function (er, d) { @@ -54,7 +54,7 @@ runScript.completion = function (opts, cb) { }) if (npm.config.get("global")) scripts = [], next() - else readJson(path.join(npm.prefix, "package.json"), function (er, d) { + else readJson(path.join(npm.localPrefix, "package.json"), function (er, d) { if (er && er.code !== "ENOENT" && er.code !== "ENOTDIR") return cb(er) d = d || {} scripts = Object.keys(d.scripts || {}) @@ -70,7 +70,7 @@ runScript.completion = function (opts, cb) { function runScript (args, cb) { if (!args.length) return list(cb) - var pkgdir = process.cwd() + var pkgdir = npm.localPrefix , cmd = args.shift() readJson(path.resolve(pkgdir, "package.json"), function (er, d) { @@ -80,7 +80,7 @@ function runScript (args, cb) { } function list(cb) { - var json = path.join(npm.prefix, 'package.json') + var json = path.join(npm.localPrefix, 'package.json') return readJson(json, function(er, d) { if (er && er.code !== 'ENOENT' && er.code !== 'ENOTDIR') return cb(er) if (er) d = {} |