From 9fe905c399d07a3c00c7b22035ddb6b7762731e6 Mon Sep 17 00:00:00 2001 From: Rebecca Turner Date: Thu, 6 Jul 2017 14:32:48 -0700 Subject: install: fix max callstack exceeded loops with links PR-URL: https://github.com/npm/npm/pull/17652 Credit: @iarna Reviewed-By: @zkat --- lib/ls.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'lib/ls.js') 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) }) } -- cgit v1.2.3