Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Closes GH-754 Be smarter about detecting correct lifecycle script paths

  • Loading branch information...
commit 0e76807c0ef746d8be82aa3202ff15b70e138fd8 1 parent 57f86f9
@isaacs isaacs authored
Showing with 15 additions and 7 deletions.
  1. +15 −7 lib/utils/lifecycle.js
View
22 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)
Please sign in to comment.
Something went wrong with that request. Please try again.