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-25 10:37:29 +0400
committerisaacs <i@izs.me>2010-08-25 16:21:53 +0400
commit30122afd23076ec207709580553871030b1988c5 (patch)
treef2592e457a7a8f28abe261fa3d987d8c077f9852
parent0bfc4254eaa94b9cf47acff1b6b4b6baebe85725 (diff)
Asynchronize
-rw-r--r--lib/update-dependents.js50
1 files changed, 23 insertions, 27 deletions
diff --git a/lib/update-dependents.js b/lib/update-dependents.js
index ae247b396..71c6b7f95 100644
--- a/lib/update-dependents.js
+++ b/lib/update-dependents.js
@@ -29,6 +29,7 @@ var readInstalled = require("./utils/read-installed")
, fs = require("./utils/graceful-fs")
, rm = require("./utils/rm-rf")
, lifecycle = require("./utils/lifecycle")
+ , asyncMap = require("./utils/async-map")
function updateDependents (args, cb) {
// replace args with the installed data
@@ -48,7 +49,7 @@ function updateDependents (args, cb) {
// no more dependents
if (!args.length) return log(
"Nothing to update", "update dependents", cb)
- chain(args.map(function (arg) { return function (cb) {
+ asyncMap(args, function (arg, cb) {
chain
( [lifecycle, arg, "preupdatedependents"]
, [updateDepsTo, arg]
@@ -56,7 +57,8 @@ function updateDependents (args, cb) {
, [lifecycle, arg, "postupdatedependents"]
, cb
)
- }}).concat(function (er) {
+ }, function (er) {
+ if (er) return cb(er)
// now they've all been updated, so remove the others.
var rmList = []
args.forEach(function (arg) {
@@ -65,20 +67,16 @@ function updateDependents (args, cb) {
rmList.push(arg.name+"@"+o)
})
})
- npm.commands.rm(rmList, function (er) {
- // if it can't be removed, that's actually fine.
- if (er) log(er.message.split("\n")[0], "not removing")
- cb()
- })
- }))
+ npm.commands.rm(rmList, cb)
+ })
})
}
// update the _others to this one.
function updateDepsTo (arg, cb) {
- chain(arg._others.map(function (o) {
- return [updateOtherVersionDeps, o, arg]
- }).concat(cb))
+ asyncMap(arg._others, function (o, cb) {
+ updateOtherVersionDeps(o, arg, cb)
+ }, cb)
}
function updateOtherVersionDeps (other, pkg, cb) {
@@ -94,13 +92,13 @@ function updateOtherVersionDeps (other, pkg, cb) {
// for each of these, update the dependency on
// other to pkg
if (!deps.length) return cb()
- chain(deps.map(function (d) {
+ asyncMap(deps, function (d, cb) {
// todo: make this a @ instead of a -
d = d.split("-")
var name = d.shift()
, ver = d.join("-")
- return [updateDepToNew, name, ver, pkg, other]
- }).concat(cb))
+ return updateDepToNew(name, ver, pkg, other, cb)
+ }, cb)
})
}
function updateDepToNew (depName, depVer, pkg, other, cb) {
@@ -121,7 +119,7 @@ function updateDepToNew (depName, depVer, pkg, other, cb) {
dependencies = deps
}
var dependency = data.dependencies[pkg.name]
- if (!dependency) return log
+ if (!dependency) return log.error
( "Weird, "+depName+"@"+depVer+" doesn't depend on "+pkg.name
, "wtf?"
, cb
@@ -150,13 +148,7 @@ function removeDependencyLinks (dep, pkg, other, cb) {
, "dependents"
, dep.name + "-" + dep.version
)
- chain
- ( [ rm, deps+".js" ]
- , [ rm, deps ]
- , [ rm, depsOn ]
- , [ rm, dependentLink ]
- , cb
- )
+ asyncMap([deps+"js", deps, depsOn, dependentLink], rm, cb)
}
function createDependencyLinks (dep, pkg, cb) {
var depdir = path.join(npm.dir, dep.name, dep.version)
@@ -174,11 +166,15 @@ function createDependencyLinks (dep, pkg, cb) {
, "dependents"
, dep.name + "-" + dep.version
)
- chain
- ( [ link, targetRoot, depsOn ]
- , [ link, depdir, dependentLink ]
- , [ linkIfExists, targetLib, deps ]
- , [ shimIfExists, targetMain, deps + ".js" ]
+ asyncMap
+ ( [ [ link, targetRoot, depsOn ]
+ , [ link, depdir, dependentLink ]
+ , [ linkIfExists, targetLib, deps ]
+ , [ shimIfExists, targetMain, deps + ".js" ]
+ ]
+ , function (c, cb) {
+ c.shift().apply(null, c.concat(cb))
+ }
, cb
)
}