Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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({
Expand Down
6 changes: 6 additions & 0 deletions src/core/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ async function fetchLatest(): Promise<string | null> {
}
}

/** Return the cached latest version (available after checkForUpdate has run). */
export async function getLatestVersion(): Promise<string | null> {
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,
Expand Down