-
Notifications
You must be signed in to change notification settings - Fork 3k
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 findBestMatch so it finds the best match and not the first match #6611
Conversation
Thanks again for the review @Jarred-Sumner. I've made the changes requested. It's a lot cleaner now thanks to your feedback, and I understand even more! |
return .{ .version = version, .package = &packages[i - 1] }; | ||
// If we find one that matches, save it, but keep looping because we might find a newer match. | ||
// The versions from the registry are not in any particular order. | ||
if (group.satisfies(version) and (best_match_version == null or Semver.Version.order(version, best_match_version.?, "", "") == .gt)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to account for pre/post tags? Usually the way we do this is to get the string buffer from lockfile.buffers.string_bytes.items
and pass that to the parent function
if (group.satisfies(version) and (best_match_version == null or Semver.Version.order(version, best_match_version.?, "", "") == .gt)) { | |
if (group.satisfies(version) and (best_match_version == null or Semver.Version.order(version, best_match_version.?, string_bytes, string_bytes) == .gt)) { |
I have some changes I'd like to make to this PR but it's a great start so I'm going to go ahead and merge it and then apply my changes afterwards. Thank you. |
What does this PR do?
Fixes
findBestMatch
.Bug Explained
findBestMatch
was picking the first version that satisfies semver range, but registries don't return versions in any particular order.This was easily repeatable with
lines-and-columns@^1.1.6
, it would always pick the first version1.2.0
, which happens to be deprecated and broken, instead of the best match, which is1.2.4
.This PR should help with a bunch of install-related bugs:
How did you verify your code works?
This modifies zig code
zig fmt
on the changed filesFirst time Zig user
I've contributed to Bun before, but this is my first time contributing to the zig code. I installed Zig and its dependencies this morning. I'm happy to accept input to improve this PR!