From e72a450736a1c102ade222ffb3e5b6f7f24901d3 Mon Sep 17 00:00:00 2001 From: isaacs Date: Wed, 24 Nov 2010 12:26:26 -0800 Subject: Make rebuild handle activation better --- lib/rebuild.js | 52 ++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 10 deletions(-) (limited to 'lib/rebuild.js') diff --git a/lib/rebuild.js b/lib/rebuild.js index 8f393e880..9e7a6e92d 100644 --- a/lib/rebuild.js +++ b/lib/rebuild.js @@ -19,12 +19,31 @@ function rebuild (args, cb) { lookupArgs(args, function (er, args) { if (er) return cb(er) if (!args.length) return log("Nothing to do", "rebuild", cb) - asyncMap(args, function (arg, cb) { + var folders = [] + , actives = [] + args = args.reduce(function (r, l) { + Object.keys(l).forEach(function (p) { + r[p] = r[p] || {} + Object.keys(l[p]).forEach(function (v) { + if (v === "active") { + r[p].active = l[p].active + actives.push([p, l[p].active]) + } else { + r[p][v] = l[p][v] + folders.push([p, v]) + } + }) + }) + return r + }, {}) + log.silly(folders,"rebuild folders") + log.silly(actives, "rebuild actives") + asyncMap(folders, function (arg, cb) { log.verbose(arg, "rebuild") - arg = arg.split("@") - var n = arg.shift() - , v = arg.join("@") - readJson(path.join(npm.dir, n, v, "package", "package.json"), function (er, data) { + var n = arg[0] + , v = arg[1] + readJson( path.join(npm.dir, n, v, "package", "package.json") + , function (er, data) { if (er) return cb(er) data.version = v data._id = data.name + "@" + data.version @@ -32,9 +51,13 @@ function rebuild (args, cb) { }) }, function (er, args) { if (er) return cb(er) - npm.config.set("update-dependents", false) - npm.config.set("auto-activate", false) - npm.commands.build(args, cb) + npm.commands.build(args, function (er) { + // now activate what was activated before, in case building + // activated a different thing (very likely) + asyncMap(actives, function (active, cb) { + npm.commands.activate([active.join("@")], cb) + }, cb) + }) }) }) } @@ -45,7 +68,11 @@ function lookupArgs (args, cb) { var a = [] asyncMap(Object.keys(inst), function (p, cb) { cb(null, Object.keys(inst[p]).map(function (v) { - return p+"@"+v + var o = {} + o[p] = {} + o[p][v] = inst[p][v] + if (o[p][v].active) o[p].active = v + return o })) }, cb) }) @@ -56,13 +83,18 @@ function lookupArgs (args, cb) { , v = a.join("@") ;(req[n] = req[n] || []).push(v) }) + log.silly(req, "rebuild request") readInstalled(Object.keys(req), function (er, inst) { asyncMap(Object.keys(inst), function (p, cb) { if (!req.hasOwnProperty(p)) return cb() var matches = [] Object.keys(inst[p]).forEach(function (v) { req[p].forEach(function (r) { - if (semver.satisfies(v, r)) matches.push(p+"@"+v), v = null + var o = {} + o[p] = {} + if (inst[p][v].active) o[p].active = v + if (semver.satisfies(v, r)) o[p][v] = inst[p][v] + matches.push(o) }) }) log.verbose(p, "rebuild") -- cgit v1.2.3