Skip to content

Commit

Permalink
Fix max version in --list output being wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
Nixinova committed Jan 3, 2024
1 parent 2b1f9a0 commit fa9b5a9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## Next
- Fixed incorrect maximum versions being returned in the output of `--list`.
- Fixed snapshots being incorrectly formatted in the output of `--list`.

## 1.3.10
Expand Down
25 changes: 21 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,31 @@ function getVersions(format: number, type: PackType = 'resource'): VersionsResul
}
if (!format || format > LATEST[type] || (type === 'data' && format < 4)) return output

const getVersionBelow = function (ver: VersionName, minVer: VersionName): VersionName {
const formatVer = ([x, y, z]: Array<string | number>) => [x, y, z].join('.') as VersionName
const [minX, minY, minZ] = minVer.split('.')
const [x, y, z] = ver.split('.')
// (1.X.a) vs 1.X.b
if (minY === y) {
if (z === 'x') return formatVer([x, y, z])
else return formatVer([x, y, +z - 1])
}
// (1.X.a) vs 1.Y.b
else {
if (z === 'x') return formatVer([x, +y - 1, z])
else return formatVer([x, y, +z - 1])
}
}

// Min and max releases
const startReleases = Object.entries(START_RELEASES)
const relIndex = startReleases.findIndex(([, data]) => data[type] === format)
if (relIndex >= 0) {
const minRelease = startReleases[relIndex][0]
const maxRelease = startReleases[relIndex + 1][0].replace(/\.(\d+)\./, (_, major) => `.${major - 1}.`)
output.releases.min = minRelease as VersionName
output.releases.max = maxRelease as VersionName
const lastWithFormat = startReleases.find(([, obj]) => (obj[type] ?? 0) > format) ?? []
const minRelease = startReleases[relIndex][0] as VersionName
const maxRelease = getVersionBelow(lastWithFormat[0] as VersionName, minRelease)
output.releases.min = minRelease
output.releases.max = maxRelease
}

// Min and max snapshots
Expand Down
2 changes: 2 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ testVersions([10, 'resource'], { releases: { min: '', max: '' }, snapshots: { mi
testVersions([6, 'resource'], { releases: { min: '1.16.x', max: '1.16.x' }, snapshots: { min: '', max: '' } })
testVersions([6, 'data'], { releases: { min: '1.16.x', max: '1.16.x' }, snapshots: { min: '20w45a', max: '20w45a' } })
testVersions([7, 'resource'], { releases: { min: '1.17.x', max: '1.17.x' }, snapshots: { min: '20w45a', max: '21w38a' } })
testVersions([10, 'data'], { releases: { min: '1.19.x', max: '1.19.3' }, snapshots: { min: '22w11a', max: '23w02a' } })
testVersions([11, 'resource'], { releases: { min: '', max: '' }, snapshots: { min: '22w42a', max: '22w44a' } })
testVersions([15, 'data'], { releases: { min: '1.20.x', max: '1.20.1' }, snapshots: { min: '23w18a', max: '23w30a' } })

console.log(`\nRan ${total} tests | ${passed} passed | ${failed} failed`)

0 comments on commit fa9b5a9

Please sign in to comment.