From 91c49dd0ea6787b07224de1d0468cff81c127632 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Mon, 16 Feb 2026 02:41:30 +0000 Subject: [PATCH] refactor(status): share registry summary formatting --- src/commands/status.update.ts | 45 ++++++++++++++++------------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/src/commands/status.update.ts b/src/commands/status.update.ts index 9d3215995d..9fd7809989 100644 --- a/src/commands/status.update.ts +++ b/src/commands/status.update.ts @@ -71,6 +71,24 @@ export function formatUpdateAvailableHint(update: UpdateCheckResult): string | n export function formatUpdateOneLiner(update: UpdateCheckResult): string { const parts: string[] = []; + + const appendRegistryUpdateSummary = () => { + if (update.registry?.latestVersion) { + const cmp = compareSemverStrings(VERSION, update.registry.latestVersion); + if (cmp === 0) { + parts.push(`npm latest ${update.registry.latestVersion}`); + } else if (cmp != null && cmp < 0) { + parts.push(`npm update ${update.registry.latestVersion}`); + } else { + parts.push(`npm latest ${update.registry.latestVersion} (local newer)`); + } + return; + } + if (update.registry?.error) { + parts.push("npm latest unknown"); + } + }; + if (update.installKind === "git" && update.git) { const branch = update.git.branch ? `git ${update.git.branch}` : "git"; parts.push(branch); @@ -94,33 +112,10 @@ export function formatUpdateOneLiner(update: UpdateCheckResult): string { if (update.git.fetchOk === false) { parts.push("fetch failed"); } - - if (update.registry?.latestVersion) { - const cmp = compareSemverStrings(VERSION, update.registry.latestVersion); - if (cmp === 0) { - parts.push(`npm latest ${update.registry.latestVersion}`); - } else if (cmp != null && cmp < 0) { - parts.push(`npm update ${update.registry.latestVersion}`); - } else { - parts.push(`npm latest ${update.registry.latestVersion} (local newer)`); - } - } else if (update.registry?.error) { - parts.push("npm latest unknown"); - } + appendRegistryUpdateSummary(); } else { parts.push(update.packageManager !== "unknown" ? update.packageManager : "pkg"); - if (update.registry?.latestVersion) { - const cmp = compareSemverStrings(VERSION, update.registry.latestVersion); - if (cmp === 0) { - parts.push(`npm latest ${update.registry.latestVersion}`); - } else if (cmp != null && cmp < 0) { - parts.push(`npm update ${update.registry.latestVersion}`); - } else { - parts.push(`npm latest ${update.registry.latestVersion} (local newer)`); - } - } else if (update.registry?.error) { - parts.push("npm latest unknown"); - } + appendRegistryUpdateSummary(); } if (update.deps) {