fix(updates): compare prerelease versions correctly (#1220)
Co-authored-by: Isaac Sanchez <isanchez-hawkins@arize.com>
This commit is contained in:
committed by
GitHub
co-authored by
Isaac Sanchez
parent
eb3f0e7f72
commit
0cfa37932e
@@ -655,16 +655,35 @@ export async function getLatestVersion() {
|
||||
/**
|
||||
* Compare semver-like version strings.
|
||||
*/
|
||||
function parseVersionForComparison(value) {
|
||||
const normalized = String(value || '').replace(/^v/, '').split('+')[0];
|
||||
const prereleaseIndex = normalized.indexOf('-');
|
||||
const core = prereleaseIndex >= 0 ? normalized.slice(0, prereleaseIndex) : normalized;
|
||||
const parts = core.split('.').map((part) => {
|
||||
const parsed = Number.parseInt(part || '0', 10);
|
||||
return Number.isFinite(parsed) ? parsed : 0;
|
||||
});
|
||||
|
||||
return {
|
||||
parts,
|
||||
prerelease: prereleaseIndex >= 0,
|
||||
};
|
||||
}
|
||||
|
||||
function compareVersions(left, right) {
|
||||
const a = String(left || '').replace(/^v/, '').split('.').map((part) => Number.parseInt(part || '0', 10));
|
||||
const b = String(right || '').replace(/^v/, '').split('.').map((part) => Number.parseInt(part || '0', 10));
|
||||
const length = Math.max(a.length, b.length);
|
||||
const a = parseVersionForComparison(left);
|
||||
const b = parseVersionForComparison(right);
|
||||
const length = Math.max(a.parts.length, b.parts.length);
|
||||
|
||||
for (let index = 0; index < length; index += 1) {
|
||||
const diff = (a[index] || 0) - (b[index] || 0);
|
||||
const diff = (a.parts[index] || 0) - (b.parts[index] || 0);
|
||||
if (diff !== 0) return diff;
|
||||
}
|
||||
|
||||
if (a.prerelease !== b.prerelease) {
|
||||
return a.prerelease ? -1 : 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user