Permalink
Browse files

Cleaned up the code so there is no need of specifying a callback when…

… invoking npm.commands.view; added a call to runNpmView when dealing with error while reading the filesystem
  • Loading branch information...
1 parent 5bc6a62 commit 14c6c8551f0dc0317acdcc666220464ba960d568 @lazywithclass committed Oct 13, 2011
Showing with 14 additions and 22 deletions.
  1. +14 −22 lib/outdated.js
View
@@ -89,7 +89,7 @@ function outdated_ (args, dir, parentHas, cb) {
fs.readdir(path.resolve(dir, "node_modules"), function (er, pkgs) {
if (er) {
has = Object.create(parentHas)
- //TODO what to do here?
+ runNpmView(has)
return next()
}
asyncMap(pkgs, function (pkg, cb) {
@@ -99,38 +99,30 @@ function outdated_ (args, dir, parentHas, cb) {
})
}, function (er, pvs) {
if (er) return cb(er)
- has = Object.create(parentHas)
- discoverNew(has, function (er, result) {
- for (var key in result) {
- var newest = key.split("@")
- var currentVersion = has[newest[0]]
- var newestVersion = newest[1]
- if (semver.gt(newestVersion, currentVersion)) {
- cb(null, [[dir, newest[0], currentVersion, currentVersion, newestVersion]])
- }
- }
- })
+ has = Object.create(parentHas)
+ runNpmView(has)
pvs.forEach(function (pv) {
has[pv[0]] = pv[1]
})
next()
})
})
- function dump (obj) {
- var out = '';
- for (var i in obj) {
- out += i + ": " + obj[i] + "\n";
- }
- console.log("*** dumping***\n")
- }
-
- function discoverNew (has, cb) {
+ function runNpmView (has) {
var keys = []
for (var key in has) {
keys.push(key)
}
- npm.commands.view(["mkdirp"], true, cb)
+ npm.commands.view(["mkdirp"], true, function (er, result) {
+ for (var key in result) {
+ var newest = key.split("@")
+ var currentVersion = has[newest[0]]
+ var newestVersion = newest[1]
+ if (semver.gt(newestVersion, currentVersion)) {
+ cb(null, [[dir, newest[0], currentVersion, currentVersion, newestVersion]])
+ }
+ }
+ })
}
function next () {

0 comments on commit 14c6c85

Please sign in to comment.