Skip to content

fix: correctly find max satisfying version from unsorted arrays#217

Open
leny-mi wants to merge 3 commits intoantfu-collective:mainfrom
leny-mi:main
Open

fix: correctly find max satisfying version from unsorted arrays#217
leny-mi wants to merge 3 commits intoantfu-collective:mainfrom
leny-mi:main

Conversation

@leny-mi
Copy link

@leny-mi leny-mi commented Sep 30, 2025

Description

The getMaxSatisfying function assumed versions were sorted, but Object.keys() returns versions in arbitrary order from npm registry. This caused taze to suggest older compatible versions instead of the latest ones. Added comparison logic to track the actual maximum version during iteration. I've included a previously failing test for this.

Linked Issues

Fixes #189

Additional context

I've been confused for a hot minute why taze wouldn't want to update to 2.8.1 of the yaml library if not using taze latest.

The getMaxSatisfying function assumed versions were sorted, but Object.keys()
returns versions in arbitrary order from npm registry. This caused taze to
suggest older compatible versions instead of the latest ones.

Added comparison logic to track the actual maximum version during iteration.
Also fixed TypeScript implicit any type error for the version variable.

Fixes the issue where taze suggests ^2.4.1 instead of ^2.8.1 when both
satisfy the version range.
Similar to the default mode bug, newest mode also assumed versions were
sorted and simply returned the last element. This caused it to return
an incorrect version when arrays were unsorted from Object.keys().

Changed to iterate through all versions and find the actual maximum.

Test case: ['1.0.0', '3.0.0', '2.0.0'] now correctly returns '3.0.0'
instead of '2.0.0'.
@leny-mi
Copy link
Author

leny-mi commented Oct 1, 2025

After the initial fix, I found the same bug in 'newest' mode - it was also assuming sorted arrays. Fixed it the same way and added a previously failing test. Also cleaned up the test to match the existing style. I think both modes now handle unsorted arrays correctly.

@leny-mi
Copy link
Author

leny-mi commented Oct 1, 2025

On a second scan of the project issues, I think this is the same issue as and fixes #189

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.

taze ignores valid updates

1 participant