Permalink
Browse files

Added support for issue #1428. Versions upper limit specified in pack…

…ages.json is ignored when launching a npm outdated [package], so if a newer version is found then the user is notified with a proper message formatted like this: "mkdirp@0.0.1 ./node_modules/mkdirp current=OUTDATED(0.0.7 available)". I still have to check if everything is ok for pull request (testing, corner cases, is this what was requested, ...)
  • Loading branch information...
1 parent 8423a87 commit 5bc6a62c177cfbfc6dafff29b1a33bba81bad15f @lazywithclass committed Oct 10, 2011
Showing with 38 additions and 5 deletions.
  1. +38 −5 lib/outdated.js
View
@@ -49,11 +49,16 @@ function makePretty (p) {
, dir = path.resolve(p[0], "node_modules", dep)
, has = p[2]
, want = p[3]
+ , newerVersion = p[4]
+ var depStatus = has ? (dep + "@" + has) : "MISSING"
+ if (newerVersion) {
+ depStatus = "OUTDATED("+newerVersion+" available)"
+ }
if (parseable) {
var str = dir
if (npm.config.get("long")) {
str += ":" + dep + "@" + want
- + ":" + (has ? (dep + "@" + has) : "MISSING")
+ + ":" + depStatus
}
return str
}
@@ -62,7 +67,7 @@ function makePretty (p) {
dir = relativize(dir, process.cwd()+"/x")
}
return dep + "@" + want + " " + dir
- + " current=" + (has || "MISSING")
+ + " current=" + (depStatus || has || "MISSING")
}
function outdated_ (args, dir, parentHas, cb) {
@@ -84,23 +89,50 @@ 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?
return next()
}
asyncMap(pkgs, function (pkg, cb) {
- readJson( path.resolve(dir, "node_modules", pkg, "package.json")
+ readJson(path.resolve(dir, "node_modules", pkg, "package.json")
, function (er, d) {
cb(null, er ? [] : [[d.name, d.version]])
})
}, function (er, pvs) {
if (er) return cb(er)
- has = Object.create(parentHas)
- pvs.forEach(function (pv) {
+ 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]])
+ }
+ }
+ })
+ 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) {
+ var keys = []
+ for (var key in has) {
+ keys.push(key)
+ }
+ npm.commands.view(["mkdirp"], true, cb)
+ }
+
function next () {
if (!has || !deps) return
if (deps === true) {
@@ -145,3 +177,4 @@ function shouldUpdate (args, dir, dep, has, req, cb) {
return (er || d.version === has[dep]) ? skip() : doIt(d.version)
})
}
+

0 comments on commit 5bc6a62

Please sign in to comment.