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-08-03 11:38:51 +0400
committerisaacs <i@izs.me>2010-08-03 11:38:51 +0400
commit913abefcb8da741c75162af39dfd4ccc04b4dc69 (patch)
treeaf4787794c45f89bf0bf26aad95094976ca3b443 /lib/update.js
parentbb9532d312e1ab92e40fa7d7638041a90d012ac7 (diff)
Add lifecycle events for update and updatedependencies
Diffstat (limited to 'lib/update.js')
-rw-r--r--lib/update.js33
1 files changed, 23 insertions, 10 deletions
diff --git a/lib/update.js b/lib/update.js
index b344e156d..46abdd58b 100644
--- a/lib/update.js
+++ b/lib/update.js
@@ -39,6 +39,7 @@ var readInstalled = require("./utils/read-installed")
, registry = require("./utils/registry")
, npm = require("../npm")
, semver = require("./utils/semver")
+ , lifecycle = require("./utils/lifecycle")
function update (args, cb) {
findUpdates(args, function (er, updates) {
@@ -52,6 +53,9 @@ function installUpdates (updates, cb) {
npm.config.set("auto-update", true)
var installList = []
, updateList = []
+ , preChain = []
+ , postChain = []
+ , fullList = []
Object.keys(updates).forEach(function (i) {
var u = updates[i]
if (u.have.indexOf(u.latest) === -1) {
@@ -59,21 +63,30 @@ function installUpdates (updates, cb) {
} else {
updateList.push(i+"@"+u.latest)
}
+ fullList.push(i+"@"+u.latest)
+ preChain.push([lifecycle, u.pkg, "preupdate"])
+ postChain.push( [lifecycle, u.pkg, "update"]
+ , [lifecycle, u.pkg, "postupdate"]
+ )
})
- log(installList, "update installList")
- log(updateList, "update updateList")
- var fullList = installList.concat(updateList)
cb = (function (cb) { return function (er) {
log(fullList.join(" "), er ? "failed to update" : "updated")
cb(er)
}})(cb)
- npm.commands.install(installList, function (er) {
- if (er) return log.er(cb, "install failed "+installList)(er)
- npm.commands["update-dependents"](updateList, function (er) {
- if (er) return log.er(cb, "update failed "+updateList)(er)
- npm.commands.activate(fullList, cb)
+ log(fullList.join(" "), "updates")
+ chain(preChain.concat(function (er) {
+ if (er) return cb(er)
+ npm.commands.install(installList, function (er) {
+ if (er) return log.er(cb, "install failed "+installList)(er)
+ npm.commands["update-dependents"](updateList, function (er) {
+ if (er) return log.er(cb, "update failed "+updateList)(er)
+ npm.commands.activate(fullList, function (er) {
+ if (er) return cb(er)
+ chain(postChain.concat(cb))
+ })
+ })
})
- })
+ }))
}
function findUpdates (args, cb) {
@@ -92,7 +105,7 @@ function findUpdates (args, cb) {
, minHave = have[0]
if (!latest || !semver.gt(latest, minHave)) return found()
// we have something that's out of date.
- updates[pkg] = {latest:latest,have:have}
+ updates[pkg] = {latest:latest,have:have,pkg:data.versions[latest]}
found()
})
})