From 47beacec3c7eaec4cfa4ce8031ab0663178f2f3a Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 15 Feb 2026 05:30:27 +0000 Subject: [PATCH] refactor(status): dedupe update status formatting --- src/commands/status-all.ts | 73 +++++++++++++++----------------------- 1 file changed, 28 insertions(+), 45 deletions(-) diff --git a/src/commands/status-all.ts b/src/commands/status-all.ts index 10c26c292..36892d1d4 100644 --- a/src/commands/status-all.ts +++ b/src/commands/status-all.ts @@ -266,6 +266,32 @@ export async function statusAllCommand( : null; const updateLine = (() => { + 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"); @@ -290,55 +316,12 @@ export async function statusAllCommand( parts.push("fetch failed"); } - 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"); - } + appendRegistryAndDepsStatus(parts); return parts.join(" · "); } const parts: string[] = []; parts.push(update.packageManager !== "unknown" ? update.packageManager : "pkg"); - 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"); - } + appendRegistryAndDepsStatus(parts); return parts.join(" · "); })();