Skip to content

Commit

Permalink
Avoid cycles in failedDependency
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
everett1992 authored Jun 24, 2020
1 parent abdf528 commit 049cafe
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/install/deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,11 @@ function isDepOptional (tree, name, pkg) {
}

exports.failedDependency = failedDependency
function failedDependency (tree, name, pkg) {
function failedDependency (tree, name, pkg, visited = new Set()) {
// cycle detection
if (visited.has(tree)) return false
visited.add(tree)

if (name) {
if (isDepOptional(tree, name, pkg || {})) {
return false
Expand All @@ -454,7 +458,7 @@ function failedDependency (tree, name, pkg) {
let anyFailed = false
for (var ii = 0; ii < tree.requiredBy.length; ++ii) {
var requireParent = tree.requiredBy[ii]
if (failedDependency(requireParent, moduleName(tree), tree)) {
if (failedDependency(requireParent, moduleName(tree), tree, visited)) {
anyFailed = true
}
}
Expand Down

0 comments on commit 049cafe

Please sign in to comment.