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
path: root/lib/ls.js
diff options
context:
space:
mode:
authorRebecca Turner <me@re-becca.org>2017-07-07 00:32:48 +0300
committerRebecca Turner <me@re-becca.org>2017-07-11 01:47:47 +0300
commit9fe905c399d07a3c00c7b22035ddb6b7762731e6 (patch)
tree37bad42ff073e6ecad8697a2e819ee39ce93a1ad /lib/ls.js
parentb2b03733f8cf8983892076d15b830b5913891adb (diff)
install: fix max callstack exceeded loops with links
PR-URL: https://github.com/npm/npm/pull/17652 Credit: @iarna Reviewed-By: @zkat
Diffstat (limited to 'lib/ls.js')
-rw-r--r--lib/ls.js14
1 files changed, 7 insertions, 7 deletions
diff --git a/lib/ls.js b/lib/ls.js
index 67f09485f..27c8ada8a 100644
--- a/lib/ls.js
+++ b/lib/ls.js
@@ -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)
})
}