diff --git a/src/cli/update-cli/status.ts b/src/cli/update-cli/status.ts index 5c0f12c42a..452445dfe5 100644 --- a/src/cli/update-cli/status.ts +++ b/src/cli/update-cli/status.ts @@ -5,9 +5,8 @@ import { } from "../../commands/status.update.js"; import { readConfigFileSnapshot } from "../../config/config.js"; import { - formatUpdateChannelLabel, normalizeUpdateChannel, - resolveEffectiveUpdateChannel, + resolveUpdateChannelDisplay, } from "../../infra/update-channels.js"; import { checkUpdateStatus } from "../../infra/update-check.js"; import { defaultRuntime } from "../../runtime.js"; @@ -52,17 +51,13 @@ export async function updateStatusCommand(opts: UpdateStatusOptions): Promise { - const appendRegistryAndDepsStatus = (parts: string[]) => { - const latest = update.registry?.latestVersion; - if (latest) { - const cmp = compareSemverStrings(VERSION, latest); - if (cmp === 0) { - parts.push(`npm latest ${latest}`); - } else if (cmp != null && cmp < 0) { - parts.push(`npm update ${latest}`); - } else { - parts.push(`npm latest ${latest} (local newer)`); - } - } else if (update.registry?.error) { - parts.push("npm latest unknown"); - } - - if (update.deps?.status === "ok") { - parts.push("deps ok"); - } - if (update.deps?.status === "stale") { - parts.push("deps stale"); - } - if (update.deps?.status === "missing") { - parts.push("deps missing"); - } - }; - - if (update.installKind === "git" && update.git) { - const parts: string[] = []; - parts.push(update.git.branch ? `git ${update.git.branch}` : "git"); - if (update.git.upstream) { - parts.push(`↔ ${update.git.upstream}`); - } - if (update.git.dirty) { - parts.push("dirty"); - } - if (update.git.behind != null && update.git.ahead != null) { - if (update.git.behind === 0 && update.git.ahead === 0) { - parts.push("up to date"); - } else if (update.git.behind > 0 && update.git.ahead === 0) { - parts.push(`behind ${update.git.behind}`); - } else if (update.git.behind === 0 && update.git.ahead > 0) { - parts.push(`ahead ${update.git.ahead}`); - } else { - parts.push(`diverged (ahead ${update.git.ahead}, behind ${update.git.behind})`); - } - } - if (update.git.fetchOk === false) { - parts.push("fetch failed"); - } - - appendRegistryAndDepsStatus(parts); - return parts.join(" · "); - } - const parts: string[] = []; - parts.push(update.packageManager !== "unknown" ? update.packageManager : "pkg"); - appendRegistryAndDepsStatus(parts); - return parts.join(" · "); - })(); + const updateLine = formatUpdateOneLiner(update).replace(/^Update:\s*/i, ""); const gatewayTarget = remoteUrlMissing ? `fallback ${connection.url}` : connection.url; const gatewayStatus = gatewayReachable diff --git a/src/commands/status.command.ts b/src/commands/status.command.ts index 34c80962e8..e06feb42af 100644 --- a/src/commands/status.command.ts +++ b/src/commands/status.command.ts @@ -6,11 +6,7 @@ import { info } from "../globals.js"; import { formatTimeAgo } from "../infra/format-time/format-relative.ts"; import type { HeartbeatEventPayload } from "../infra/heartbeat-events.js"; import { formatUsageReportLines, loadProviderUsageSummary } from "../infra/provider-usage.js"; -import { - formatUpdateChannelLabel, - normalizeUpdateChannel, - resolveEffectiveUpdateChannel, -} from "../infra/update-channels.js"; +import { normalizeUpdateChannel, resolveUpdateChannelDisplay } from "../infra/update-channels.js"; import { formatGitInstallLabel } from "../infra/update-check.js"; import { resolveMemoryCacheSummary, @@ -132,10 +128,11 @@ export async function statusCommand( : null; const configChannel = normalizeUpdateChannel(cfg.update?.channel); - const channelInfo = resolveEffectiveUpdateChannel({ + const channelInfo = resolveUpdateChannelDisplay({ configChannel, installKind: update.installKind, - git: update.git ? { tag: update.git.tag, branch: update.git.branch } : undefined, + gitTag: update.git?.tag ?? null, + gitBranch: update.git?.branch ?? null, }); if (opts.json) { @@ -352,12 +349,7 @@ export async function statusCommand( const updateAvailability = resolveUpdateAvailability(update); const updateLine = formatUpdateOneLiner(update).replace(/^Update:\s*/i, ""); - const channelLabel = formatUpdateChannelLabel({ - channel: channelInfo.channel, - source: channelInfo.source, - gitTag: update.git?.tag ?? null, - gitBranch: update.git?.branch ?? null, - }); + const channelLabel = channelInfo.label; const gitLabel = formatGitInstallLabel(update); const overviewRows = [ diff --git a/src/infra/update-channels.ts b/src/infra/update-channels.ts index f363d943c0..bfa7f86827 100644 --- a/src/infra/update-channels.ts +++ b/src/infra/update-channels.ts @@ -81,3 +81,29 @@ export function formatUpdateChannelLabel(params: { } return `${params.channel} (default)`; } + +export function resolveUpdateChannelDisplay(params: { + configChannel?: UpdateChannel | null; + installKind: "git" | "package" | "unknown"; + gitTag?: string | null; + gitBranch?: string | null; +}): { channel: UpdateChannel; source: UpdateChannelSource; label: string } { + const channelInfo = resolveEffectiveUpdateChannel({ + configChannel: params.configChannel, + installKind: params.installKind, + git: + params.gitTag || params.gitBranch + ? { tag: params.gitTag ?? null, branch: params.gitBranch ?? null } + : undefined, + }); + return { + channel: channelInfo.channel, + source: channelInfo.source, + label: formatUpdateChannelLabel({ + channel: channelInfo.channel, + source: channelInfo.source, + gitTag: params.gitTag ?? null, + gitBranch: params.gitBranch ?? null, + }), + }; +}