Skip to content

Commit

Permalink
[FIX] npm translator: Fix endless loop in case of dependency cycles (#15
Browse files Browse the repository at this point in the history
  • Loading branch information
codeworrior authored Jun 26, 2018
1 parent 2ca710b commit cf31112
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/translators/npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,18 @@ class NpmTranslator {

processPendingDeps(tree) {
const queue = [tree];
const visited = new Set();

// Breadth-first search to prefer projects closer to root
while (queue.length) {
const project = queue.shift(); // Get and remove first entry from queue
if (!project.id) {
throw new Error("Encountered project with missing id");
}
if (visited.has(project.id)) {
continue;
}
visited.add(project.id);

if (this.pendingDeps[project.id]) {
for (let i = this.pendingDeps[project.id].parents.length - 1; i >= 0; i--) {
Expand Down

0 comments on commit cf31112

Please sign in to comment.