diff options
author | Mark Reeder <mreeder@uber.com> | 2015-11-21 11:03:15 +0300 |
---|---|---|
committer | Forrest L Norvell <forrest@npmjs.com> | 2015-12-11 05:06:26 +0300 |
commit | 71c9590be61b6a7b7fa8b6dc19baa588cda26a27 (patch) | |
tree | 0cb2323a6db9dc1908d4719742d49cffff925185 /lib/ls.js | |
parent | b88c37c1cced40e9e41402cc54a5efc3c33cd13e (diff) |
ls: fix depth when outputting JSON
Credit: @MarkReeder
Reviewed-By: @othiym23
PR-URL: https://github.com/npm/npm/pull/10505
Diffstat (limited to 'lib/ls.js')
-rw-r--r-- | lib/ls.js | 6 |
1 files changed, 5 insertions, 1 deletions
@@ -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) { |