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

Moved the discovering function to a proper place

  • Loading branch information...
lazywithclass committed Nov 1, 2011
commit 42c7bf337a04389401b600cf70be90295cbb8b8e
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
@@ -82,14 +83,14 @@ 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()
})
var has = null
fs.readdir(path.resolve(dir, "node_modules"), function (er, pkgs) {
if (er) {
has = Object.create(parentHas)
runNpmView(has)
return next()
}
asyncMap(pkgs, function (pkg, cb) {
@@ -100,29 +101,32 @@ function outdated_ (args, dir, parentHas, cb) {
}, function (er, pvs) {
if (er) return cb(er)
has = Object.create(parentHas)
runNpmView(has)
pvs.forEach(function (pv) {
has[pv[0]] = pv[1]
})
next()
})
})
function runNpmView (has) {
var keys = []
for (var key in has) {
keys.push(key)
}
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 discoverNew (deps) {
asyncMap(deps, function (dep, cb_) {
var depName = Object.keys(dep)[0]
get(depName, function (er, doc) {
var versions = Object.keys(doc.versions)
//TODO check if doc.version is lways ordered
var newest = versions[versions.length-1]
cb_(null, {"name": depName, "current": dep[depName], "newest": newest})
})
}, function (er, results) {
results.forEach(function (dep) {
if (semver.gt(dep.newest, dep.current)) {
//TODO why pass dep.current two times? is it correct?
//TODO why the double square parens?
cb(null, [[dir, dep.name, dep.current, dep.current, dep.newest]])
}
})
}
)
}
function next () {
ProTip! Use n and p to navigate between commits in a pull request.