diff options
Diffstat (limited to 'packages/cli/src/ui/utils/updateCheck.ts')
| -rw-r--r-- | packages/cli/src/ui/utils/updateCheck.ts | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/packages/cli/src/ui/utils/updateCheck.ts b/packages/cli/src/ui/utils/updateCheck.ts index b0a0de1b..2fe5df39 100644 --- a/packages/cli/src/ui/utils/updateCheck.ts +++ b/packages/cli/src/ui/utils/updateCheck.ts @@ -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 { |
