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

Discover new versions with outdated

Add versions that are not matching the version specified in the
package.json as 'latest', at cost of one request more per package.

Show versions that are specified by the package.json as 'wanted'

Fixes #1428
  • Loading branch information...
robertkowalski authored and domenic committed Jul 6, 2013
1 parent 982a7cc commit 2f7fd625a0f2eaf59789ab13bd15bba907ae166d
Showing with 69 additions and 20 deletions.
  1. +4 −0 doc/cli/npm-outdated.md
  2. +28 −19 lib/outdated.js
  3. +1 −1 package.json
  4. +25 −0 test/tap/outdated-new-versions.js
  5. +11 −0 test/tap/outdated-new-versions/package.json
View
@@ -10,6 +10,10 @@ npm-outdated(1) -- Check for outdated packages
This command will check the registry to see if any (or, specific) installed
packages are currently outdated.
The resulting field 'wanted' shows the latest version according to the
version specified in the package.json, the field 'latest' the very latest
version of the package.
## SEE ALSO
* npm-update(1)
View
@@ -45,6 +45,7 @@ function makePretty (p) {
, dir = path.resolve(p[0], "node_modules", dep)
, has = p[2]
, want = p[3]
, latest = p[4]
// XXX add --json support
// Should match (more or less) the output of ls --json
@@ -61,8 +62,10 @@ function makePretty (p) {
if (!npm.config.get("global")) {
dir = path.relative(process.cwd(), dir)
}
return dep + "@" + want + " " + dir
return dep + " " + dir
+ " current=" + (has || "MISSING")
+ " wanted=" + want
+ " latest=" + latest
}
function outdated_ (args, dir, parentHas, cb) {
@@ -154,29 +157,35 @@ function shouldUpdate (args, dir, dep, has, req, cb) {
, cb )
}
function doIt (shouldHave) {
cb(null, [[ dir, dep, curr && curr.version, shouldHave, req ]])
function doIt (wanted, latest) {
cb(null, [[ dir, dep, curr && curr.version, wanted, latest, req ]])
}
if (args.length && args.indexOf(dep) === -1) {
return skip()
}
// so, we can conceivably update this. find out if we need to.
cache.add(dep, req, function (er, d) {
// if this fails, then it means we can't update this thing.
// it's probably a thing that isn't published.
if (er) return skip()
// check that the url origin hasn't changed (#1727) and that
// there is no newer version available
var dFromUrl = d._from && url.parse(d._from).protocol
var cFromUrl = curr && curr.from && url.parse(curr.from).protocol
if (!curr || dFromUrl && cFromUrl && d._from !== curr.from
|| d.version !== curr.version)
doIt(d.version)
else
skip()
var registry = npm.registry
// search for the latest package
registry.get(dep + "/latest", function (er, l) {
if (er) return cb()
// so, we can conceivably update this. find out if we need to.
cache.add(dep, req, function (er, d) {
// if this fails, then it means we can't update this thing.
// it's probably a thing that isn't published.
if (er) return skip()
// check that the url origin hasn't changed (#1727) and that
// there is no newer version available
var dFromUrl = d._from && url.parse(d._from).protocol
var cFromUrl = curr && curr.from && url.parse(curr.from).protocol
if (!curr || dFromUrl && cFromUrl && d._from !== curr.from
|| d.version !== curr.version
|| d.version !== l.version)
doIt(d.version, l.version)
else
skip()
})
})
}
View
@@ -123,7 +123,7 @@
"devDependencies": {
"ronn": "~0.3.6",
"tap": "~0.4.0",
"npm-registry-mock": "~0.3.0"
"npm-registry-mock": "~0.4.1"
},
"engines": {
"node": ">=0.6",
@@ -0,0 +1,25 @@
var test = require("tap").test
var npm = require("../../")
var mr = require("npm-registry-mock")
// config
var port = 1331
var address = "http://localhost:" + port
var pkg = __dirname + '/outdated-new-versions'
test("dicovers new versions in outdated", function (t) {
process.chdir(pkg)
mr(port, function (s) {
npm.load({registry: address}, function () {
npm.outdated(function (er, d) {
t.equal("1.5.1", d[0][4]) // dependencies
t.equal("2.27.0", d[1][4]) // devDependencies
s.close()
t.end()
})
})
})
})
@@ -0,0 +1,11 @@
{
"name": "new-versions-with-outdated",
"author": "Rockbert",
"version": "0.0.0",
"dependencies": {
"underscore": "~1.3.1"
},
"devDependencies": {
"request": "~0.9.0"
}
}

0 comments on commit 2f7fd62

Please sign in to comment.