refactor(status): share registry summary formatting

This commit is contained in:
Peter Steinberger
2026-02-16 02:41:30 +00:00
parent 8eecf97cc5
commit 91c49dd0ea

View File

@@ -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) {