Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/ls.js6
-rw-r--r--test/tap/ls-depth-cli.js46
2 files changed, 51 insertions, 1 deletions
diff --git a/lib/ls.js b/lib/ls.js
index 51f0b5155..1c9292082 100644
--- a/lib/ls.js
+++ b/lib/ls.js
@@ -139,13 +139,14 @@ function isCruft (data) {
return data.extraneous && data.error && data.error.code === 'ENOTDIR'
}
-function getLite (data, noname) {
+function getLite (data, noname, depth) {
var lite = {}
if (isCruft(data)) return lite
var maxDepth = npm.config.get('depth')
+ if (typeof depth === 'undefined') depth = 0
if (!noname && data.name) lite.name = data.name
if (data.version) lite.version = data.version
if (data.extraneous) {
@@ -213,6 +214,9 @@ function getLite (data, noname) {
lite.problems.push(pdm)
})
return [d, { required: dep, peerMissing: true }]
+ } else if (npm.config.get('json')) {
+ if (depth === maxDepth) delete dep.dependencies
+ return [d, getLite(dep, true, depth + 1)]
}
return [d, getLite(dep, true)]
}).reduce(function (deps, d) {
diff --git a/test/tap/ls-depth-cli.js b/test/tap/ls-depth-cli.js
index 77689cbc5..760681427 100644
--- a/test/tap/ls-depth-cli.js
+++ b/test/tap/ls-depth-cli.js
@@ -113,6 +113,52 @@ test('npm ls --depth=Infinity', function (t) {
)
})
+test('npm ls --depth=0 --json', function (t) {
+ common.npm(
+ ['ls', '--depth=0', '--json'],
+ EXEC_OPTS,
+ function (er, c, out) {
+ t.ifError(er, 'npm ls ran without issue')
+ t.equal(c, 0, 'ls ran without raising error code')
+ t.has(
+ out,
+ /test-package-with-one-dep@0\.0\.0/,
+ 'output contains test-package-with-one-dep@0.0.0'
+ )
+ t.doesNotHave(
+ out,
+ /test-package@0\.0\.0/,
+ 'output not contains test-package@0.0.0'
+ )
+ t.end()
+ }
+ )
+})
+
+test('npm ls --depth=Infinity --json', function (t) {
+ // travis has a preconfigured depth=0, in general we can not depend
+ // on the default value in all environments, so explictly set it here
+ common.npm(
+ ['ls', '--depth=Infinity', '--json'],
+ EXEC_OPTS,
+ function (er, c, out) {
+ t.ifError(er, 'npm ls ran without issue')
+ t.equal(c, 0, 'ls ran without raising error code')
+ t.has(
+ out,
+ /test-package-with-one-dep@0\.0\.0/,
+ 'output contains test-package-with-one-dep@0.0.0'
+ )
+ t.has(
+ out,
+ /test-package@0\.0\.0/,
+ 'output contains test-package@0.0.0'
+ )
+ t.end()
+ }
+ )
+})
+
test('cleanup', function (t) {
cleanup()
t.end()