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

npm outdated: have default depth=0

interpret Infinity as 0 for `outdated`
remove depth: 0 from outdated-depth unit test
add child package with outdated dependency to outdated-depth test
new unit test outdated-depth-deep to confirm that
  npm outdated --depth=9999 works as expected
  • Loading branch information...
smikes authored and othiym23 committed Feb 11, 2015
1 parent 0fe0caa commit 8b98f0e709d77a8616c944aebd48ab726f726f76
View
@@ -243,8 +243,13 @@ If true, then only prints color codes for tty file descriptors.
* Default: Infinity
* Type: Number
-The depth to go when recursing directories for `npm ls` and
-`npm cache ls`.
+The depth to go when recursing directories for `npm ls`,
+`npm cache ls`, and `npm outdated`.
+
+For `npm outdated`, a setting of `Infinity` will be treated as `0`
+since that gives more useful information. To show the outdated status
+of all packages and dependents, use a large integer value,
+e.g., `npm outdated --depth 9999`
### description
View
@@ -40,6 +40,10 @@ var path = require("path")
function outdated (args, silent, cb) {
if (typeof cb !== "function") cb = silent, silent = false
var dir = path.resolve(npm.dir, "..")
+
+ // default depth for `outdated` is 0 (cf. `ls`)
+ if (npm.config.get("depth") === Infinity) npm.config.set("depth", 0)
+
outdated_(args, dir, {}, 0, function (er, list) {
if (!list) list = []
if (er || silent || list.length === 0) return cb(er, list)
@@ -0,0 +1,78 @@
+var common = require("../common-tap")
+ , path = require("path")
+ , test = require("tap").test
+ , rimraf = require("rimraf")
+ , npm = require("../../")
+ , mr = require("npm-registry-mock")
+ , pkg = path.resolve(__dirname, "outdated-depth-deep")
+ , cache = path.resolve(pkg, "cache")
+
+var osenv = require("osenv")
+var mkdirp = require("mkdirp")
+var fs = require("fs")
+
+var pj = JSON.stringify({
+ "name": "whatever",
+ "description": "yeah idk",
+ "version": "1.2.3",
+ "main": "index.js",
+ "dependencies": {
+ "underscore": "1.3.1",
+ "npm-test-peer-deps": "0.0.0"
+ },
+ "repository": "git://github.com/luk-/whatever"
+}, null, 2)
+
+function cleanup () {
+ process.chdir(osenv.tmpdir())
+ rimraf.sync(pkg)
+}
+
+function setup () {
+ mkdirp.sync(pkg)
+ process.chdir(pkg)
+ fs.writeFileSync(path.resolve(pkg, "package.json"), pj)
+}
+
+test("setup", function (t) {
+ cleanup()
+ setup()
+ t.end()
+})
+
+test("outdated depth deep (9999)", function (t) {
+ var underscoreOutdated = ["underscore", "1.3.1", "1.3.1", "1.5.1", "1.3.1"]
+ var childPkg = path.resolve(pkg, "node_modules", "npm-test-peer-deps")
+
+ var expected = [ [pkg].concat(underscoreOutdated),
+ [childPkg].concat(underscoreOutdated) ]
+
+ process.chdir(pkg)
+
+ mr({port : common.port}, function (er, s) {
+ npm.load({
+ cache: cache
+ , loglevel: "silent"
+ , registry: common.registry
+ , depth: 9999
+ }
+ , function () {
+ npm.install(".", function (er) {
+ if (er) throw new Error(er)
+ npm.outdated(function (err, d) {
+ if (err) throw new Error(err)
+ t.deepEqual(d, expected)
+ s.close()
+ t.end()
+ })
+ })
+ }
+ )
+ })
+})
+
+
+test("cleanup", function (t) {
+ cleanup()
+ t.end()
+})
@@ -30,7 +30,6 @@ test("outdated depth zero", function (t) {
cache: cache
, loglevel: "silent"
, registry: common.registry
- , depth: 0
}
, function () {
npm.install(".", function (er) {
@@ -4,7 +4,8 @@
"version": "1.2.3",
"main": "index.js",
"dependencies": {
- "underscore": "1.3.1"
+ "underscore": "1.3.1",
+ "npm-test-peer-deps": "0.0.0"
},
"repository": "git://github.com/luk-/whatever"
}

1 comment on commit 8b98f0e

@douglasduteil

This comment has been minimized.

Show comment
Hide comment
Please sign in to comment.