diff options
Diffstat (limited to 'lib/ls.js')
-rw-r--r-- | lib/ls.js | 14 |
1 files changed, 7 insertions, 7 deletions
@@ -87,13 +87,13 @@ var lsFromTree = ls.fromTree = function (dir, physicalTree, args, silent, cb) { var json = npm.config.get('json') var out if (json) { - var seen = [] + var seen = new Set() var d = long ? unlooped : lite // the raw data can be circular out = JSON.stringify(d, function (k, o) { if (typeof o === 'object') { - if (inList(seen, o)) return '[Circular]' - seen.push(o) + if (seen.has(o)) return '[Circular]' + seen.add(o) } return o }, 2) @@ -255,8 +255,8 @@ function getLite (data, noname, depth) { function unloop (root) { var queue = [root] - var seen = {} - seen[root.path] = true + var seen = new Set() + seen.add(root) while (queue.length) { var current = queue.shift() @@ -264,13 +264,13 @@ function unloop (root) { Object.keys(deps).forEach(function (d) { var dep = deps[d] if (dep.missing && !dep.dependencies) return - if (dep.path && seen[dep.path]) { + if (dep.path && seen.has(dep)) { dep = deps[d] = Object.assign({}, dep) dep.dependencies = {} dep._deduped = path.relative(root.path, dep.path).replace(/node_modules\//g, '') return } - seen[dep.path] = true + seen.add(dep) queue.push(dep) }) } |