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
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2012-02-09 00:16:53 +0400
committerisaacs <i@izs.me>2012-02-09 00:16:53 +0400
commit21b77a4785dcb98d1f0249cae009f997b7ef7eef (patch)
tree1586942c9462e0fd9c295dfa692a15933bfdb458
parent1c60c7e64fe08721489ca3c436cc8c78b6990970 (diff)
Fix #2123 Set path properly for lifecycle scripts on windows
-rw-r--r--lib/utils/lifecycle.js30
1 files changed, 22 insertions, 8 deletions
diff --git a/lib/utils/lifecycle.js b/lib/utils/lifecycle.js
index 970157349..51ad7ba69 100644
--- a/lib/utils/lifecycle.js
+++ b/lib/utils/lifecycle.js
@@ -11,6 +11,17 @@ var log = require("./log.js")
, chain = require("slide").chain
, constants = require("constants")
, output = require("./output.js")
+ , PATH = "PATH"
+
+// windows calls it's path "Path" usually, but this is not guaranteed.
+if (process.platform === "win32") {
+ PATH = "Path"
+ Object.keys(process.env).forEach(function (e) {
+ if (e.match(/^PATH$/i)) {
+ PATH = e
+ }
+ })
+}
function lifecycle (pkg, stage, wd, unsafe, failOk, cb) {
if (typeof cb !== "function") cb = failOk, failOk = false
@@ -54,16 +65,16 @@ function checkForLink (pkg, cb) {
}
function lifecycle_ (pkg, stage, wd, env, unsafe, failOk, cb) {
- var PATH = []
+ var pathArr = []
, p = wd.split("node_modules")
, acc = path.resolve(p.shift())
p.forEach(function (pp) {
- PATH.unshift(path.join(acc, "node_modules", ".bin"))
+ pathArr.unshift(path.join(acc, "node_modules", ".bin"))
acc = path.join(acc, "node_modules", pp)
})
- PATH.unshift(path.join(acc, "node_modules", ".bin"))
- if (env.PATH) PATH.push(env.PATH)
- env.PATH = PATH.join(process.platform === "win32" ? ";" : ":")
+ pathArr.unshift(path.join(acc, "node_modules", ".bin"))
+ if (env[PATH]) pathArr.push(env[PATH])
+ env[PATH] = pathArr.join(process.platform === "win32" ? ";" : ":")
var packageLifecycle = pkg.scripts && pkg.scripts.hasOwnProperty(stage)
@@ -113,7 +124,7 @@ function runPackageLifecycle (pkg, env, wd, unsafe, cb) {
, cmd = env.npm_lifecycle_script
, sh = "sh"
, shFlag = "-c"
-
+
if (process.platform === "win32") {
sh = "cmd"
shFlag = "/c"
@@ -121,9 +132,12 @@ function runPackageLifecycle (pkg, env, wd, unsafe, cb) {
log.verbose(unsafe, "unsafe-perm in lifecycle")
- output.write("\n> "+pkg._id+" " + stage+" "+wd+"\n> "+cmd+"\n", function (er) {
+ var note = "\n> " + pkg._id + " " + stage + " " + wd
+ + "\n> " + cmd + "\n"
+
+ output.write(note, function (er) {
if (er) return cb(er)
-
+
exec( sh, [shFlag, cmd], env, true, wd
, user, group
, function (er, code, stdout, stderr) {