Skip to content
This repository was archived by the owner on Aug 11, 2022. It is now read-only.

Commit 8b98f0e

Browse files
smikesothiym23
authored andcommitted
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
1 parent 0fe0caa commit 8b98f0e

5 files changed

Lines changed: 91 additions & 4 deletions

File tree

doc/misc/npm-config.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,13 @@ If true, then only prints color codes for tty file descriptors.
243243
* Default: Infinity
244244
* Type: Number
245245

246-
The depth to go when recursing directories for `npm ls` and
247-
`npm cache ls`.
246+
The depth to go when recursing directories for `npm ls`,
247+
`npm cache ls`, and `npm outdated`.
248+
249+
For `npm outdated`, a setting of `Infinity` will be treated as `0`
250+
since that gives more useful information. To show the outdated status
251+
of all packages and dependents, use a large integer value,
252+
e.g., `npm outdated --depth 9999`
248253

249254
### description
250255

lib/outdated.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ var path = require("path")
4040
function outdated (args, silent, cb) {
4141
if (typeof cb !== "function") cb = silent, silent = false
4242
var dir = path.resolve(npm.dir, "..")
43+
44+
// default depth for `outdated` is 0 (cf. `ls`)
45+
if (npm.config.get("depth") === Infinity) npm.config.set("depth", 0)
46+
4347
outdated_(args, dir, {}, 0, function (er, list) {
4448
if (!list) list = []
4549
if (er || silent || list.length === 0) return cb(er, list)

test/tap/outdated-depth-deep.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
var common = require("../common-tap")
2+
, path = require("path")
3+
, test = require("tap").test
4+
, rimraf = require("rimraf")
5+
, npm = require("../../")
6+
, mr = require("npm-registry-mock")
7+
, pkg = path.resolve(__dirname, "outdated-depth-deep")
8+
, cache = path.resolve(pkg, "cache")
9+
10+
var osenv = require("osenv")
11+
var mkdirp = require("mkdirp")
12+
var fs = require("fs")
13+
14+
var pj = JSON.stringify({
15+
"name": "whatever",
16+
"description": "yeah idk",
17+
"version": "1.2.3",
18+
"main": "index.js",
19+
"dependencies": {
20+
"underscore": "1.3.1",
21+
"npm-test-peer-deps": "0.0.0"
22+
},
23+
"repository": "git://github.com/luk-/whatever"
24+
}, null, 2)
25+
26+
function cleanup () {
27+
process.chdir(osenv.tmpdir())
28+
rimraf.sync(pkg)
29+
}
30+
31+
function setup () {
32+
mkdirp.sync(pkg)
33+
process.chdir(pkg)
34+
fs.writeFileSync(path.resolve(pkg, "package.json"), pj)
35+
}
36+
37+
test("setup", function (t) {
38+
cleanup()
39+
setup()
40+
t.end()
41+
})
42+
43+
test("outdated depth deep (9999)", function (t) {
44+
var underscoreOutdated = ["underscore", "1.3.1", "1.3.1", "1.5.1", "1.3.1"]
45+
var childPkg = path.resolve(pkg, "node_modules", "npm-test-peer-deps")
46+
47+
var expected = [ [pkg].concat(underscoreOutdated),
48+
[childPkg].concat(underscoreOutdated) ]
49+
50+
process.chdir(pkg)
51+
52+
mr({port : common.port}, function (er, s) {
53+
npm.load({
54+
cache: cache
55+
, loglevel: "silent"
56+
, registry: common.registry
57+
, depth: 9999
58+
}
59+
, function () {
60+
npm.install(".", function (er) {
61+
if (er) throw new Error(er)
62+
npm.outdated(function (err, d) {
63+
if (err) throw new Error(err)
64+
t.deepEqual(d, expected)
65+
s.close()
66+
t.end()
67+
})
68+
})
69+
}
70+
)
71+
})
72+
})
73+
74+
75+
test("cleanup", function (t) {
76+
cleanup()
77+
t.end()
78+
})

test/tap/outdated-depth.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ test("outdated depth zero", function (t) {
3030
cache: cache
3131
, loglevel: "silent"
3232
, registry: common.registry
33-
, depth: 0
3433
}
3534
, function () {
3635
npm.install(".", function (er) {

test/tap/outdated-depth/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"version": "1.2.3",
55
"main": "index.js",
66
"dependencies": {
7-
"underscore": "1.3.1"
7+
"underscore": "1.3.1",
8+
"npm-test-peer-deps": "0.0.0"
89
},
910
"repository": "git://github.com/luk-/whatever"
1011
}

0 commit comments

Comments
 (0)