fix(update): correctly report new updates (#4821)

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: Jacob Richman <jacob314@gmail.com>
This commit is contained in:
Sambhav Khanna
2025-07-29 20:11:15 -04:00
committed by GitHub
parent c156fb0e8b
commit 0b912e2e09
2 changed files with 48 additions and 8 deletions

View File

@@ -8,6 +8,8 @@ import updateNotifier, { UpdateInfo } from 'update-notifier';
import semver from 'semver';
import { getPackageJson } from '../../utils/package.js';
export const FETCH_TIMEOUT_MS = 2000;
export interface UpdateObject {
message: string;
update: UpdateInfo;
@@ -34,8 +36,11 @@ export async function checkForUpdates(): Promise<UpdateObject | null> {
// allow notifier to run in scripts
shouldNotifyInNpmScript: true,
});
const updateInfo = await notifier.fetchInfo();
// avoid blocking by waiting at most FETCH_TIMEOUT_MS for fetchInfo to resolve
const timeout = new Promise<null>((resolve) =>
setTimeout(resolve, FETCH_TIMEOUT_MS, null),
);
const updateInfo = await Promise.race([notifier.fetchInfo(), timeout]);
if (updateInfo && semver.gt(updateInfo.latest, updateInfo.current)) {
return {