Skip to content

Commit

Permalink
Pass a flag through to say whether it's an npat script call
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Jan 8, 2012
1 parent e6173a8 commit bb89c59
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/build.js
Expand Up @@ -55,7 +55,7 @@ function build_ (global, didPre, didRB) { return function (folder, cb) {
, didPre !== build._noLC && [lifecycle, pkg, "postinstall", folder] , didPre !== build._noLC && [lifecycle, pkg, "postinstall", folder]
, didPre !== build._noLC , didPre !== build._noLC
&& npm.config.get("npat") && npm.config.get("npat")
&& [lifecycle, pkg, "test", folder] ] && [lifecycle, pkg, "test", folder, false, false, true] ]
, cb ) , cb )
}) })
}} }}
Expand Down
20 changes: 13 additions & 7 deletions lib/utils/lifecycle.js
Expand Up @@ -12,7 +12,8 @@ var log = require("./log.js")
, constants = require("constants") , constants = require("constants")
, output = require("./output.js") , output = require("./output.js")


function lifecycle (pkg, stage, wd, unsafe, failOk, cb) { function lifecycle (pkg, stage, wd, unsafe, failOk, isNpat, cb) {
if (typeof cb !== "function") cb = isNpat, isNpat = false
if (typeof cb !== "function") cb = failOk, failOk = false if (typeof cb !== "function") cb = failOk, failOk = false
if (typeof cb !== "function") cb = unsafe, unsafe = false if (typeof cb !== "function") cb = unsafe, unsafe = false
if (typeof cb !== "function") cb = wd, wd = null if (typeof cb !== "function") cb = wd, wd = null
Expand Down Expand Up @@ -42,7 +43,7 @@ function lifecycle (pkg, stage, wd, unsafe, failOk, cb) {
// even if it's never used, sh freaks out. // even if it's never used, sh freaks out.
if (!npm.config.get("unsafe-perm")) env.TMPDIR = wd if (!npm.config.get("unsafe-perm")) env.TMPDIR = wd


lifecycle_(pkg, stage, wd, env, unsafe, failOk, cb) lifecycle_(pkg, stage, wd, env, unsafe, failOk, isNpat, cb)
}) })
} }


Expand All @@ -53,7 +54,7 @@ function checkForLink (pkg, cb) {
}) })
} }


function lifecycle_ (pkg, stage, wd, env, unsafe, failOk, cb) { function lifecycle_ (pkg, stage, wd, env, unsafe, failOk, isNpat, cb) {
var PATH = [] var PATH = []
, p = wd.split("node_modules") , p = wd.split("node_modules")
, acc = path.resolve(p.shift()) , acc = path.resolve(p.shift())
Expand Down Expand Up @@ -87,7 +88,7 @@ function lifecycle_ (pkg, stage, wd, env, unsafe, failOk, cb) {
} }


chain chain
( [ packageLifecycle && [runPackageLifecycle, pkg, env, wd, unsafe] ( [ packageLifecycle && [runPackageLifecycle, pkg, env, wd, unsafe, isNpat]
, [runHookLifecycle, pkg, env, wd, unsafe] ] , [runHookLifecycle, pkg, env, wd, unsafe] ]
, cb ) , cb )
} }
Expand All @@ -105,15 +106,15 @@ function validWd (d, cb) {
}) })
} }


function runPackageLifecycle (pkg, env, wd, unsafe, cb) { function runPackageLifecycle (pkg, env, wd, unsafe, isNpat, cb) {
// run package lifecycle scripts in the package root, or the nearest parent. // run package lifecycle scripts in the package root, or the nearest parent.
var stage = env.npm_lifecycle_event var stage = env.npm_lifecycle_event
, user = unsafe ? null : npm.config.get("user") , user = unsafe ? null : npm.config.get("user")
, group = unsafe ? null : npm.config.get("group") , group = unsafe ? null : npm.config.get("group")
, cmd = env.npm_lifecycle_script , cmd = env.npm_lifecycle_script
, sh = "sh" , sh = "sh"
, shFlag = "-c" , shFlag = "-c"

if (process.platform === "win32") { if (process.platform === "win32") {
sh = "cmd" sh = "cmd"
shFlag = "/c" shFlag = "/c"
Expand All @@ -123,10 +124,15 @@ function runPackageLifecycle (pkg, env, wd, unsafe, cb) {


output.write("\n> "+pkg._id+" " + stage+" "+wd+"\n> "+cmd+"\n", function (er) { output.write("\n> "+pkg._id+" " + stage+" "+wd+"\n> "+cmd+"\n", function (er) {
if (er) return cb(er) if (er) return cb(er)

exec( sh, [shFlag, cmd], env, true, wd exec( sh, [shFlag, cmd], env, true, wd
, user, group , user, group
, function (er, code, stdout, stderr) { , function (er, code, stdout, stderr) {

if (isNpat) {
// XXX DTrejo, go nuts on this right here
}

if (er && !npm.ROLLBACK) { if (er && !npm.ROLLBACK) {
log("Failed to exec "+stage+" script", pkg._id) log("Failed to exec "+stage+" script", pkg._id)
er.message = pkg._id + " " er.message = pkg._id + " "
Expand Down

0 comments on commit bb89c59

Please sign in to comment.