Skip to content

Commit fa9b5a9

Browse files
committed
Fix max version in --list output being wrong
1 parent 2b1f9a0 commit fa9b5a9

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Changelog
22

33
## Next
4+
- Fixed incorrect maximum versions being returned in the output of `--list`.
45
- Fixed snapshots being incorrectly formatted in the output of `--list`.
56

67
## 1.3.10

src/index.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,31 @@ function getVersions(format: number, type: PackType = 'resource'): VersionsResul
132132
}
133133
if (!format || format > LATEST[type] || (type === 'data' && format < 4)) return output
134134

135+
const getVersionBelow = function (ver: VersionName, minVer: VersionName): VersionName {
136+
const formatVer = ([x, y, z]: Array<string | number>) => [x, y, z].join('.') as VersionName
137+
const [minX, minY, minZ] = minVer.split('.')
138+
const [x, y, z] = ver.split('.')
139+
// (1.X.a) vs 1.X.b
140+
if (minY === y) {
141+
if (z === 'x') return formatVer([x, y, z])
142+
else return formatVer([x, y, +z - 1])
143+
}
144+
// (1.X.a) vs 1.Y.b
145+
else {
146+
if (z === 'x') return formatVer([x, +y - 1, z])
147+
else return formatVer([x, y, +z - 1])
148+
}
149+
}
150+
135151
// Min and max releases
136152
const startReleases = Object.entries(START_RELEASES)
137153
const relIndex = startReleases.findIndex(([, data]) => data[type] === format)
138154
if (relIndex >= 0) {
139-
const minRelease = startReleases[relIndex][0]
140-
const maxRelease = startReleases[relIndex + 1][0].replace(/\.(\d+)\./, (_, major) => `.${major - 1}.`)
141-
output.releases.min = minRelease as VersionName
142-
output.releases.max = maxRelease as VersionName
155+
const lastWithFormat = startReleases.find(([, obj]) => (obj[type] ?? 0) > format) ?? []
156+
const minRelease = startReleases[relIndex][0] as VersionName
157+
const maxRelease = getVersionBelow(lastWithFormat[0] as VersionName, minRelease)
158+
output.releases.min = minRelease
159+
output.releases.max = maxRelease
143160
}
144161

145162
// Min and max snapshots

test/test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ testVersions([10, 'resource'], { releases: { min: '', max: '' }, snapshots: { mi
5252
testVersions([6, 'resource'], { releases: { min: '1.16.x', max: '1.16.x' }, snapshots: { min: '', max: '' } })
5353
testVersions([6, 'data'], { releases: { min: '1.16.x', max: '1.16.x' }, snapshots: { min: '20w45a', max: '20w45a' } })
5454
testVersions([7, 'resource'], { releases: { min: '1.17.x', max: '1.17.x' }, snapshots: { min: '20w45a', max: '21w38a' } })
55+
testVersions([10, 'data'], { releases: { min: '1.19.x', max: '1.19.3' }, snapshots: { min: '22w11a', max: '23w02a' } })
5556
testVersions([11, 'resource'], { releases: { min: '', max: '' }, snapshots: { min: '22w42a', max: '22w44a' } })
57+
testVersions([15, 'data'], { releases: { min: '1.20.x', max: '1.20.1' }, snapshots: { min: '23w18a', max: '23w30a' } })
5658

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

0 commit comments

Comments
 (0)