Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

npm translator: Fix endless loop in case of dependency cycles #15

Merged
merged 1 commit into from
Jun 26, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to to check for the combination of project.id and project.version instead of only the project.id?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The projectPreprocessor does the same also on id-level: projectPreprocessor.js#L55. So I guess it wouldn't change much down that line.

While it is yet to be decided and documented, we once agreed (for the time being) to always prefer the projects closer to the root, ignoring the version.

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