Skip to content

Commit bf166ce

Browse files
committed
Avoid cycles in failedDependency
failedDependency is depth first search for a path to a top-level or user-required package. If failedDependency revisits a package it will recurse till it blows the call stack.
1 parent abdf528 commit bf166ce

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/install/deps.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,11 @@ function isDepOptional (tree, name, pkg) {
436436
}
437437

438438
exports.failedDependency = failedDependency
439-
function failedDependency (tree, name, pkg) {
439+
function failedDependency (tree, name, pkg, visited = new Set()) {
440+
// cycle detection
441+
if (visited.has(tree)) return false
442+
visited.add(tree)
443+
440444
if (name) {
441445
if (isDepOptional(tree, name, pkg || {})) {
442446
return false
@@ -454,7 +458,7 @@ function failedDependency (tree, name, pkg) {
454458
let anyFailed = false
455459
for (var ii = 0; ii < tree.requiredBy.length; ++ii) {
456460
var requireParent = tree.requiredBy[ii]
457-
if (failedDependency(requireParent, moduleName(tree), tree)) {
461+
if (failedDependency(requireParent, moduleName(tree), tree, visited)) {
458462
anyFailed = true
459463
}
460464
}

0 commit comments

Comments
 (0)