This repository has been archived by the owner. It is now read-only.

Discover newer versions of dependencies than package.json allows #1638

Closed
wants to merge 4 commits into
base: master
from
View
@@ -27,6 +27,7 @@ var path = require("path")
, log = require("./utils/log.js")
, semver = require("semver")
, relativize = require("./utils/relativize.js")
, get = require("./utils/npm-registry-client/get.js")
function outdated (args, silent, cb) {
if (typeof cb !== "function") cb = silent, silent = false
@@ -49,11 +50,20 @@ function makePretty (p) {
, dir = path.resolve(p[0], "node_modules", dep)
, has = p[2]
, want = p[3]
, newer = p[4]
var depStatus = has ? (dep + "@" + has) : "MISSING"
if (newer) {
if (semver.lte(newer, want)) {
depStatus = "CANUPDATE("+newer+" available)"
} else {
depStatus = "OUTDATED("+newer+" available)"
}
}
if (parseable) {
var str = dir
if (npm.config.get("long")) {
str += ":" + dep + "@" + want
+ ":" + (has ? (dep + "@" + has) : "MISSING")
+ ":" + depStatus
}
return str
}
@@ -62,7 +72,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) {
@@ -77,6 +87,7 @@ function outdated_ (args, dir, parentHas, cb) {
var deps = null
readJson(path.resolve(dir, "package.json"), function (er, d) {
deps = (er) ? true : d.dependencies
discoverNew(deps)
return next()
})
@@ -87,20 +98,38 @@ function outdated_ (args, dir, parentHas, cb) {
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) {
pvs.forEach(function (pv) {
has[pv[0]] = pv[1]
})
next()
})
})
function discoverNew (deps) {
asyncMap(deps, function (dep, cb_) {
var depName = Object.keys(dep)[0]
get(depName, function (er, doc) {
var versions = Object.keys(doc.versions)
var newest = versions[versions.length-1]
cb_(null, {"name": depName, "current": dep[depName], "newest": newest})
})
}, function (er, results) {
results.forEach(function (dep) {
if (semver.gte(dep.newest, dep.current)) {
cb(null, [[dir, dep.name, dep.current, dep.current, dep.newest]])
}
})
}
)
}
function next () {
if (!has || !deps) return
if (deps === true) {
@@ -145,3 +174,4 @@ function shouldUpdate (args, dir, dep, has, req, cb) {
return (er || d.version === has[dep]) ? skip() : doIt(d.version)
})
}
ProTip! Use n and p to navigate between commits in a pull request.