diff options
author | isaacs <i@izs.me> | 2011-03-28 19:41:34 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2011-03-28 19:42:14 +0400 |
commit | 0e76807c0ef746d8be82aa3202ff15b70e138fd8 (patch) | |
tree | 33c6edd355d676d20e9f25163e982f8a4fca1875 | |
parent | 57f86f9e632ba7bbfe8d1137f4aa1cb0cd8af49e (diff) |
Closes GH-754 Be smarter about detecting correct lifecycle script paths
-rw-r--r-- | lib/utils/lifecycle.js | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/lib/utils/lifecycle.js b/lib/utils/lifecycle.js index 81bb4fe84..6b8504281 100644 --- a/lib/utils/lifecycle.js +++ b/lib/utils/lifecycle.js @@ -20,9 +20,9 @@ function lifecycle (pkg, stage, wd, cb) { log(pkg._id, stage) if (!pkg.scripts || !pkg.scripts[stage]) return cb() - var pkgDir = path.join(npm.dir, pkg.name) - wd = validWd(wd || pkgDir) - if (wd !== pkgDir && !npm.config.get("unsafe-perm")) { + wd = validWd(wd || path.resolve(npm.dir, pkg.name)) + if ((wd.indexOf(npm.dir) !== 0 || path.basename(wd) !== pkg.name) + && !npm.config.get("unsafe-perm")) { log.warn(pkg._id+" "+pkg.scripts[stage], "skipping, cannot run in "+wd) return cb() } @@ -32,7 +32,7 @@ function lifecycle (pkg, stage, wd, cb) { env.npm_lifecycle_event = stage if (!npm.config.get("unsafe-perm")) env.TMPDIR = wd - lifecycle_(pkg, stage, wd, pkgDir, env, cb) + lifecycle_(pkg, stage, wd, env, cb) } function checkForLink (pkg, cb) { @@ -42,9 +42,17 @@ function checkForLink (pkg, cb) { }) } -function lifecycle_ (pkg, stage, wd, pkgDir, env, cb) { - env.PATH = path.join(pkgDir, "node_modules", ".bin") - + (env.PATH ? ":" + env.PATH : "") +function lifecycle_ (pkg, stage, wd, env, cb) { + var PATH = [] + , p = wd.split("node_modules") + , acc = p.shift() + p.pop() + p.forEach(function (pp) { + PATH.push(path.resolve(acc, "node_modules", ".bin")) + acc = path.resolve(acc, "node_modules", pp) + }) + if (env.PATH) PATH.push(env.PATH) + env.PATH = PATH.join(":") var packageLifecycle = pkg.scripts && pkg.scripts.hasOwnProperty(stage) |