Fix semver ordering for libraries (#5959)

Fix #5951
Fix #5085

Extended the fictitious version number for non-numbers, so that trunk
can be listed higher than a `yyyymmdd` as a version (EVE uses this)
This commit is contained in:
Patrick Quist
2024-01-08 22:10:25 -06:00
committed by GitHub
parent 124e9db250
commit 730437464d
3 changed files with 21 additions and 17 deletions
+1 -5
View File
@@ -362,11 +362,7 @@ export class ClientOptionsHandler {
for (const langGroup of Object.values(libraries)) {
for (const libGroup of Object.values(langGroup)) {
const versions = Object.values(libGroup.versions);
// TODO: A and B don't contain any property called semver here. It's probably leftover from old code
// and should be removed in the future.
versions.sort((a, b) =>
semverParser.compare(asSafeVer((a as any).semver), asSafeVer((b as any).semver), true),
);
versions.sort((a, b) => semverParser.compare(asSafeVer(a.version), asSafeVer(b.version), true));
let order = 0;
// Set $order to index on array. As group is an array, iteration order is guaranteed.
for (const lib of versions) {
+11 -2
View File
@@ -499,7 +499,12 @@ export function countOccurrences<T>(collection: Iterable<T>, item: T): number {
return result;
}
export function asSafeVer(semver: string | number | null | undefined) {
export enum magic_semver {
trunk = '99999999.99999.999',
non_trunk = '99999998.99999.999',
}
export function asSafeVer(semver: string | number | null | undefined): string {
if (semver != null) {
if (typeof semver === 'number') {
semver = `${semver}`;
@@ -516,6 +521,10 @@ export function asSafeVer(semver: string | number | null | undefined) {
return validated;
}
}
if (semver.includes('trunk') || semver.includes('main')) {
return magic_semver.trunk;
}
}
return '9999999.99999.999';
return magic_semver.non_trunk;
}
+9 -10
View File
@@ -566,17 +566,16 @@ describe('safe semver', () => {
utils.asSafeVer('1.1.0').should.equal('1.1.0');
utils.asSafeVer('1.1.1').should.equal('1.1.1');
const MAGIC_TRUNK_VERSION = '9999999.99999.999';
utils.asSafeVer('trunk').should.equal(MAGIC_TRUNK_VERSION);
utils.asSafeVer('(trunk)').should.equal(MAGIC_TRUNK_VERSION);
utils.asSafeVer('(123.456.789 test)').should.equal(MAGIC_TRUNK_VERSION);
utils.asSafeVer('trunk').should.equal(utils.magic_semver.trunk);
utils.asSafeVer('(trunk)').should.equal(utils.magic_semver.trunk);
utils.asSafeVer('(123.456.789 test)').should.equal(utils.magic_semver.non_trunk);
utils.asSafeVer('0..0').should.equal(MAGIC_TRUNK_VERSION);
utils.asSafeVer('0.0.').should.equal(MAGIC_TRUNK_VERSION);
utils.asSafeVer('0.').should.equal(MAGIC_TRUNK_VERSION);
utils.asSafeVer('.0.0').should.equal(MAGIC_TRUNK_VERSION);
utils.asSafeVer('.0..').should.equal(MAGIC_TRUNK_VERSION);
utils.asSafeVer('0..').should.equal(MAGIC_TRUNK_VERSION);
utils.asSafeVer('0..0').should.equal(utils.magic_semver.non_trunk);
utils.asSafeVer('0.0.').should.equal(utils.magic_semver.non_trunk);
utils.asSafeVer('0.').should.equal(utils.magic_semver.non_trunk);
utils.asSafeVer('.0.0').should.equal(utils.magic_semver.non_trunk);
utils.asSafeVer('.0..').should.equal(utils.magic_semver.non_trunk);
utils.asSafeVer('0..').should.equal(utils.magic_semver.non_trunk);
utils.asSafeVer('123 TEXT').should.equal('123.0.0');
utils.asSafeVer('123.456 TEXT').should.equal('123.456.0');