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>2010-11-24 23:26:26 +0300
committerisaacs <i@izs.me>2010-11-24 23:26:26 +0300
commite72a450736a1c102ade222ffb3e5b6f7f24901d3 (patch)
tree149f942faf73d5ed1ffed08ccaa6b2faf9a0a1d1 /lib/rebuild.js
parenta802dfa44c1da02beb7ad17c2ce161544639587d (diff)
Make rebuild handle activation better
Diffstat (limited to 'lib/rebuild.js')
-rw-r--r--lib/rebuild.js52
1 files changed, 42 insertions, 10 deletions
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")