Merge pull request #3569 from Tibsfox/fix/update-diagnostics

fix(cli): show latest version and bypass npm cache in update check
This commit is contained in:
Jeremy McSpadden 2026-04-05 15:57:41 -05:00 committed by GitHub
commit d666fea3a9
2 changed files with 32 additions and 2 deletions

View file

@ -0,0 +1,27 @@
/**
* Regression test for #3445: gsd update must print both current and latest
* versions for diagnostics, and bypass npm cache.
*/
import { test } from "node:test";
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import { join, dirname } from "node:path";
import { fileURLToPath } from "node:url";
const __dirname = dirname(fileURLToPath(import.meta.url));
test("update-cmd prints latest version before comparison (#3445)", () => {
const src = readFileSync(join(__dirname, "..", "update-cmd.ts"), "utf-8");
const latestPrintIdx = src.indexOf("Latest version:");
const comparisonIdx = src.indexOf("compareSemver(latest, current)");
assert.ok(latestPrintIdx !== -1, "Must print latest version");
assert.ok(latestPrintIdx < comparisonIdx, "Must print latest BEFORE comparison");
});
test("update-cmd bypasses npm cache (#3445)", () => {
const src = readFileSync(join(__dirname, "..", "update-cmd.ts"), "utf-8");
assert.ok(
src.includes("npm_config_cache"),
"Must clear npm cache env to bypass stale registry data",
);
});

View file

@ -14,18 +14,21 @@ export async function runUpdate(): Promise<void> {
process.stdout.write(`${dim}Current version:${reset} v${current}\n`)
process.stdout.write(`${dim}Checking npm registry...${reset}\n`)
// Fetch latest version
// Fetch latest version — bypass npm client cache to avoid stale results (#3445)
let latest: string
try {
latest = execSync(`npm view ${NPM_PACKAGE} version`, {
latest = execSync(`npm view ${NPM_PACKAGE} version --fetch-retry-mintimeout=3000`, {
encoding: 'utf-8',
stdio: ['ignore', 'pipe', 'ignore'],
env: { ...process.env, npm_config_cache: '' },
}).trim()
} catch {
process.stderr.write(`${yellow}Failed to reach npm registry.${reset}\n`)
process.exit(1)
}
process.stdout.write(`${dim}Latest version:${reset} v${latest}\n`)
if (compareSemver(latest, current) <= 0) {
process.stdout.write(`${green}Already up to date.${reset}\n`)
return