diff options
author | isaacs <i@izs.me> | 2010-08-25 08:36:25 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2010-08-25 16:21:52 +0400 |
commit | 5628f8a0641a08b7234c608a5e420fcf1c02c1d1 (patch) | |
tree | 819fbe13aa1eb7d74b202924131e6f5597dd48da /lib | |
parent | d2fa25efde2322187f820c7f34de38d1da5f4391 (diff) |
Asynchronize
Diffstat (limited to 'lib')
-rw-r--r-- | lib/update.js | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/lib/update.js b/lib/update.js index dd56e1644..0c096fd84 100644 --- a/lib/update.js +++ b/lib/update.js @@ -40,6 +40,7 @@ var readInstalled = require("./utils/read-installed") , npm = require("../npm") , semver = require("./utils/semver") , lifecycle = require("./utils/lifecycle") + , asyncMap = require("./utils/async-map") function update (args, cb) { findUpdates(args, function (er, updates) { @@ -56,14 +57,13 @@ function installUpdates (updates, cb) { , preChain = [] , postChain = [] , fullList = [] - Object.keys(updates).forEach(function (i) { - var u = updates[i] + updates.forEach(function (u) { if (u.have.indexOf(u.latest) === -1) { - installList.push(i+"@"+u.latest) + installList.push(u.name+"@"+u.latest) } else { - updateList.push(i+"@"+u.latest) + updateList.push(u.name+"@"+u.latest) } - fullList.push(i+"@"+u.latest) + fullList.push(u.name+"@"+u.latest) preChain.push([lifecycle, u.pkg, "preupdate"]) postChain.push( [lifecycle, u.pkg, "update"] , [lifecycle, u.pkg, "postupdate"] @@ -98,23 +98,26 @@ function updateAndActivate (updateList, fullList, postChain, cb) { function findUpdates (args, cb) { readInstalled(args, function (er, inst) { if (er) return log.er(cb, "Couldn't read installed packages")(er) - var pkgs = Object.keys(inst) - , p = pkgs.length - , updates = {} - , tag = npm.config.get("tag") - function found () { if (--p === 0) cb(null, updates) } - pkgs.forEach(function (pkg) { + var tag = npm.config.get("tag") + asyncMap(Object.keys(inst), function (pkg, cb) { + log.verbose(pkg, "find updates") registry.get(pkg, function (er, data) { - if (er) return log(pkg, "not in registry", found) + if (er) return log.verbose(pkg, "not in registry", cb) var latest = data["dist-tags"] && data["dist-tags"][tag] , have = Object.keys(inst[pkg]).sort(semver.sort) , minHave = have[0] - if (!latest || !semver.gt(latest, minHave)) return found() + log.verbose(latest, pkg+"@latest") + log.verbose(minHave, pkg+" min installed") + log.verbose(semver.gt(latest, minHave), pkg+" latest > minHave") + if (!latest || !semver.gt(latest, minHave)) return cb() // we have something that's out of date. - updates[pkg] = {latest:latest,have:have,pkg:data.versions[latest]} - found() + cb(null, { latest : latest + , have : have + , pkg : data.versions[latest] + , name : data.name + }) }) - }) + }, cb) }) } |