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

fix: only automatically resolve optional peers with versions that satisfy the ranges #8028

Merged
merged 7 commits into from Apr 29, 2024

Conversation

zkochan
Copy link
Member

@zkochan zkochan commented Apr 28, 2024

close #7985

@zkochan zkochan marked this pull request as ready for review April 29, 2024 00:14
@zkochan zkochan requested a review from a team April 29, 2024 00:14
pkgAddresses: resolveDependenciesResult.pkgAddresses,
...filterMissingPeers(await resolveDependenciesResult.resolvingPeers, parentPkgAliases),
}
pkgAddresses.push(...importerResolutionResult.pkgAddresses)
Copy link
Member

Choose a reason for hiding this comment

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

I see this happens above on line 48 too, but I'd be a bit worried about stack overflows here with large arrays. It might be safer to use a for loop since that doesn't have the same downside?

Are we guaranteed importerResolutionResult.pkgAddresses is small? I'm guessing it will be 99% of the time, but still depends on user input.

Copy link
Member Author

Choose a reason for hiding this comment

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

I am not sure what you mean. How does an array concatenation cause a stackoverflow?

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I should have cited something. The best discussion of the issue I can find is:

nodejs/node#16870

The problem is that all arguments are placed onto the stack one by one before calling .push, which means that this code can throw depending on how deep in the stack we are already and argument size.

I tend to avoid spreading arguments into a function if the arguments aren't a fixed size so I don't have to think about this problem.

Copy link
Member Author

Choose a reason for hiding this comment

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

oh wow, good to know

@@ -27,3 +27,20 @@ export function hoistPeers (
}
return dependencies
}

export function hoistOptionalPeers (
Copy link
Member

Choose a reason for hiding this comment

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

nitpick: The name hoistOptionalPeers makes me think it'll perform a side-effect. In this case, it looks like it's just a pure function that computes a map. How about getSatisfyingOptionalPeersFromFullGraph?

Choose a reason for hiding this comment

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

👏

@zkochan zkochan merged commit 1a6f7fb into main Apr 29, 2024
13 of 14 checks passed
@zkochan zkochan deleted the fix-optional-peers-dedupe branch April 29, 2024 12:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optional peer dependency cause unmet warning
3 participants