fix: prefer stable release when beta lags

This commit is contained in:
Peter Steinberger
2026-01-20 16:28:25 +00:00
parent 4fda10c508
commit 3d5ffee07f
4 changed files with 54 additions and 17 deletions

View File

@@ -3,6 +3,7 @@ import path from "node:path";
import { runCommandWithTimeout } from "../process/exec.js";
import { parseSemver } from "./runtime-guard.js";
import { channelToNpmTag, type UpdateChannel } from "./update-channels.js";
export type PackageManager = "pnpm" | "bun" | "npm" | "unknown";
@@ -315,6 +316,30 @@ export async function fetchNpmTagVersion(params: {
}
}
export async function resolveNpmChannelTag(params: {
channel: UpdateChannel;
timeoutMs?: number;
}): Promise<{ tag: string; version: string | null }> {
const channelTag = channelToNpmTag(params.channel);
const channelStatus = await fetchNpmTagVersion({ tag: channelTag, timeoutMs: params.timeoutMs });
if (params.channel !== "beta") {
return { tag: channelTag, version: channelStatus.version };
}
const latestStatus = await fetchNpmTagVersion({ tag: "latest", timeoutMs: params.timeoutMs });
if (!latestStatus.version) {
return { tag: channelTag, version: channelStatus.version };
}
if (!channelStatus.version) {
return { tag: "latest", version: latestStatus.version };
}
const cmp = compareSemverStrings(channelStatus.version, latestStatus.version);
if (cmp != null && cmp < 0) {
return { tag: "latest", version: latestStatus.version };
}
return { tag: channelTag, version: channelStatus.version };
}
export function compareSemverStrings(a: string | null, b: string | null): number | null {
const pa = parseSemver(a);
const pb = parseSemver(b);