Skip to content
Browse files

npm outdated --parseable fix

  • Loading branch information...
1 parent ef4902f commit 9575a23f955ce3e75b509c89504ef0bd707c8cf6 @yhpark yhpark committed with isaacs Feb 8, 2014
Showing with 23 additions and 14 deletions.
  1. +23 −14 lib/outdated.js
View
37 lib/outdated.js
@@ -9,6 +9,9 @@ Does the following:
If no packages are specified, then run for all installed
packages.
+--parseable creates output like this:
+<fullpath>:<name@wanted>:<name@installed>:<name@latest>
+
*/
module.exports = outdated
@@ -30,6 +33,7 @@ var path = require("path")
, styles = require("ansistyles")
, table = require("text-table")
, semver = require("semver")
+ , os = require("os")
function outdated (args, silent, cb) {
if (typeof cb !== "function") cb = silent, silent = false
@@ -38,6 +42,8 @@ function outdated (args, silent, cb) {
if (er || silent) return cb(er, list)
if (npm.config.get("json")) {
console.log(makeJSON(list))
+ } else if (npm.config.get("parseable")) {
+ console.log(makeParseable(list));
} else {
var outList = list.map(makePretty)
var outTable = [[ "Package"
@@ -62,28 +68,15 @@ function outdated (args, silent, cb) {
})
}
-// [[ dir, dep, has, want ]]
+// [[ dir, dep, has, want, latest ]]
function makePretty (p) {
var parseable = npm.config.get("parseable")
- , long = npm.config.get("long")
, dep = p[1]
, 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
-
- if (parseable) {
- var str = dir
- if (npm.config.get("long")) {
- str += ":" + dep + "@" + want
- + ":" + (has ? (dep + "@" + has) : "MISSING")
- }
- return str
- }
-
if (!npm.config.get("global")) {
dir = path.relative(process.cwd(), dir)
}
@@ -116,6 +109,22 @@ function dirToPrettyLocation (dir) {
.replace(/[[/\\]node_modules[/\\]/g, " > ")
}
+function makeParseable (list) {
+ return list.map(function (p) {
+ var dep = p[1]
+ , dir = path.resolve(p[0], "node_modules", dep)
+ , has = p[2]
+ , want = p[3]
+ , latest = p[4];
+
+ return [ dir
+ , dep + "@" + want
+ , (has ? (dep + "@" + has) : "MISSING")
+ , dep + "@" + latest
+ ].join(":")
+ }).join(os.EOL)
+}
+
function makeJSON (list) {
var out = {}
list.forEach(function (p) {

0 comments on commit 9575a23

Please sign in to comment.
Something went wrong with that request. Please try again.