Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2014-08-30 03:21:34 +0400
committerForrest L Norvell <forrest@npmjs.com>2014-08-30 04:28:47 +0400
commit0dc6a07c778071c94c2251429c7d107e88a45095 (patch)
treec79fbd1e80450befc8e3a580a72bfda8328ff774 /lib
parent65d2179af96737eb9038eaa24a293a62184aaa13 (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')
-rw-r--r--lib/build.js2
-rw-r--r--lib/docs.js2
-rw-r--r--lib/run-script.js10
-rw-r--r--lib/unpublish.js4
-rw-r--r--lib/version.js6
5 files changed, 12 insertions, 12 deletions
diff --git a/lib/build.js b/lib/build.js
index f78e91169..f1c61bdb8 100644
--- a/lib/build.js
+++ b/lib/build.js
@@ -95,7 +95,7 @@ function linkStuff (pkg, folder, global, didRB, cb) {
function shouldWarn(pkg, folder, global, cb) {
var parent = path.dirname(folder)
, top = parent === npm.dir
- , cwd = process.cwd()
+ , cwd = npm.localPrefix
readJson(path.resolve(cwd, "package.json"), function(er, topPkg) {
if (er) return cb(er)
diff --git a/lib/docs.js b/lib/docs.js
index 2c59b2672..dead3f755 100644
--- a/lib/docs.js
+++ b/lib/docs.js
@@ -41,7 +41,7 @@ function docs (args, cb) {
function getDoc (project, cb) {
project = project || '.'
- var package = path.resolve(process.cwd(), "package.json")
+ var package = path.resolve(npm.localPrefix, "package.json")
if (project === '.' || project === './') {
var json
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 = {}
diff --git a/lib/unpublish.js b/lib/unpublish.js
index 0f2e7224d..2566cd5ae 100644
--- a/lib/unpublish.js
+++ b/lib/unpublish.js
@@ -65,10 +65,10 @@ function unpublish (args, cb) {
+ unpublish.usage)
}
- if (!project || path.resolve(project) === npm.prefix) {
+ if (!project || path.resolve(project) === npm.localPrefix) {
// if there's a package.json in the current folder, then
// read the package name and version out of that.
- var cwdJson = path.join(process.cwd(), "package.json")
+ var cwdJson = path.join(npm.localPrefix, "package.json")
return readJson(cwdJson, function (er, data) {
if (er && er.code !== "ENOENT" && er.code !== "ENOTDIR") return cb(er)
if (er) return cb("Usage:\n" + unpublish.usage)
diff --git a/lib/version.js b/lib/version.js
index 95d5ff2ee..5091ab9e2 100644
--- a/lib/version.js
+++ b/lib/version.js
@@ -23,7 +23,7 @@ version.usage = "npm version [<newversion> | major | minor | patch | prerelease
function version (args, silent, cb_) {
if (typeof cb_ !== "function") cb_ = silent, silent = false
if (args.length > 1) return cb_(version.usage)
- fs.readFile(path.join(process.cwd(), "package.json"), function (er, data) {
+ fs.readFile(path.join(npm.localPrefix, "package.json"), function (er, data) {
if (!args.length) {
var v = {}
Object.keys(process.versions).forEach(function (k) {
@@ -63,7 +63,7 @@ function version (args, silent, cb_) {
if (data.version === newVer) return cb_(new Error("Version not changed"))
data.version = newVer
- fs.stat(path.join(process.cwd(), ".git"), function (er, s) {
+ fs.stat(path.join(npm.localPrefix, ".git"), function (er, s) {
function cb (er) {
if (!er && !silent) console.log("v" + newVer)
cb_(er)
@@ -111,7 +111,7 @@ function checkGit (data, cb) {
}
function write (data, cb) {
- fs.writeFile( path.join(process.cwd(), "package.json")
+ fs.writeFile( path.join(npm.localPrefix, "package.json")
, new Buffer(JSON.stringify(data, null, 2) + "\n")
, cb )
}