Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

npm outdated --json

  • Loading branch information...
commit 0b6c9b7c8c5579f4d7d37a0c24d9b7a12ccbe5fe 1 parent 5829ecf
Evan You yyx990803 authored luk- committed
Showing with 21 additions and 2 deletions.
  1. +21 −2 lib/outdated.js
23 lib/outdated.js
View
@@ -32,8 +32,11 @@ function outdated (args, silent, cb) {
var dir = path.resolve(npm.dir, "..")
outdated_(args, dir, {}, function (er, list) {
if (er || silent) return cb(er, list)
- var outList = list.map(makePretty)
- console.log(outList.join("\n"))
+ if (npm.config.get("json")) {
+ console.log(makeJSON(list))
+ } else {
+ console.log(list.map(makePretty).join("\n"))
+ }
cb(null, list)
})
}
@@ -69,6 +72,22 @@ function makePretty (p) {
+ " latest=" + latest
}
+function makeJSON (list) {
+ var out = {}
+ list.forEach(function (p) {
+ var dir = path.resolve(p[0], "node_modules", p[1])
+ if (!npm.config.get("global")) {
+ dir = path.relative(process.cwd(), dir)
+ }
+ out[p[1]] = { current: p[2]
+ , wanted: p[3]
+ , latest: p[4]
+ , location: dir
+ }
+ })
+ return JSON.stringify(out, null, 2)
+}
+
function outdated_ (args, dir, parentHas, cb) {
// get the deps from package.json, or {<dir/node_modules/*>:"*"}
// asyncMap over deps:
Please sign in to comment.
Something went wrong with that request. Please try again.