fix(fetchVersions): Sort package versions (#10695)

* fix(fetchVersions): sort package versions

* fix(middleware): fix stable redirect
This commit is contained in:
Jiralite
2025-01-12 18:09:46 +00:00
committed by GitHub
parent 01e64b4e9a
commit 91f59cf183
3 changed files with 15 additions and 19 deletions

View File

@@ -9,9 +9,12 @@ async function fetchLatestVersion(packageName: string): Promise<string> {
}
try {
const { rows } = await sql`select version from documentation where name = ${packageName} order by version desc`;
const { rows } = await sql<{ version: string }>`with ordered_versions as (
select version from documentation where name = ${packageName} and version != 'main' order by string_to_array(version, '.')::int[] desc
)
select version from ordered_versions limit 1`;
return rows.map((row) => row.version).at(1) ?? 'main';
return rows[0]?.version ?? 'main';
} catch {
return '';
}