diff --git a/src/cli.ts b/src/cli.ts index 143c716..bd75ab6 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -9,7 +9,7 @@ import { updateCommand } from "./commands/update.js"; import { getUpdateCommand } from "./core/package-manager.js"; import type { Scope } from "./core/paths.js"; import { detectInstallation } from "./core/status.js"; -import { checkForUpdate } from "./core/version.js"; +import { checkForUpdate, getLatestVersion } from "./core/version.js"; import { isInteractive } from "./ui/interactive.js"; import { COLORS, ICONS } from "./ui/palette.js"; @@ -115,13 +115,14 @@ if (process.argv.length <= 2) { console.log(); const allInstalled = installed.length === status.platforms.length; + const latest = newer ?? (await getLatestVersion()); + const updateLabel = newer + ? `Update ${COLORS.dim(`(${pkg.version} → ${newer})`)}` + : latest + ? `Update ${COLORS.dim(`(${pkg.version} ${ICONS.ok})`)}` + : `Update ${COLORS.dim(`(${pkg.version})`)}`; const choices: { name: string; value: Action }[] = [ - { - name: newer - ? `Update ${COLORS.dim(`(${pkg.version} → ${newer})`)}` - : `Update ${COLORS.dim(`(${pkg.version})`)}`, - value: "update", - }, + { name: updateLabel, value: "update" }, ]; if (!allInstalled) { choices.push({ diff --git a/src/core/version.ts b/src/core/version.ts index f3d0100..dc4f528 100644 --- a/src/core/version.ts +++ b/src/core/version.ts @@ -51,6 +51,12 @@ async function fetchLatest(): Promise { } } +/** Return the cached latest version (available after checkForUpdate has run). */ +export async function getLatestVersion(): Promise { + const cache = await readCache(); + return cache?.latestVersion ?? null; +} + /** Check npm registry for a newer version. Returns newer version string or null. */ export async function checkForUpdate( currentVersion: string,