Skip to content

Commit

Permalink
fix(winget/version): latest returns last newest version instead of th…
Browse files Browse the repository at this point in the history
…e first newest version
  • Loading branch information
anatawa12 committed Nov 3, 2024
1 parent 120d3ce commit 439a7e0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion services/winget/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ function latest(versions) {

let version = versions[0]
for (let i = 1; i < len; i++) {
if (compareVersion(version, versions[i]) < 0) {
if (compareVersion(version, versions[i]) <= 0) {
version = versions[i]
}
}
Expand Down
8 changes: 7 additions & 1 deletion services/winget/version.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test, given } from 'sazerac'
import { compareVersion } from './version.js'
import { compareVersion, latest } from './version.js'

describe('Winget Version helpers', function () {
test(compareVersion, () => {
Expand Down Expand Up @@ -45,4 +45,10 @@ describe('Winget Version helpers', function () {
// trailing .0 and .0-beta
given('1.6.0', '1.6.0-beta.98').expect(-1)
})

test(latest, () => {
// compareVersion('3.1.1.0', '3.1.1') == 0, so It's free to choose any of them.
// I don't know why but it looks winget registry uses last newest version.
given(['3.1.1.0', '3.1.1']).expect('3.1.1')
})
})

0 comments on commit 439a7e0

Please sign in to comment.