@@ -47,15 +47,24 @@ if (arg === 'chat') {
4747 * Runs in the background.
4848 * @returns {Promise<void> }
4949 */
50- function checkForUpdates ( ) {
51- const currentVersion = packageJson . version
52- return fetch ( 'https://registry.npmjs.org/hyperparam/latest' )
53- . then ( response => response . json ( ) )
54- . then ( data => {
55- const latestVersion = data . version
56- if ( latestVersion && latestVersion !== currentVersion ) {
57- console . log ( `\x1b[33mA newer version of hyperparam is available: ${ latestVersion } (current: ${ currentVersion } )\x1b[0m` )
58- console . log ( '\x1b[33mRun \'npm install -g hyperparam\' to update\x1b[0m' )
59- }
50+ async function checkForUpdates ( ) {
51+ const abortController = new AbortController ( )
52+ const timeout = 1000 // ms
53+ const timeoutId = setTimeout ( ( ) => abortController . abort ( ) , timeout )
54+
55+ try {
56+ const currentVersion = packageJson . version
57+ const response = await fetch ( 'https://registry.npmjs.org/hyperparam/latest' , {
58+ signal : abortController . signal ,
6059 } )
60+ const { version } = await response . json ( )
61+ if ( version && version !== currentVersion ) {
62+ console . log ( `\x1b[33mA newer version of hyperparam is available: ${ version } (current: ${ currentVersion } )\x1b[0m` )
63+ console . log ( '\x1b[33mRun \'npm install -g hyperparam\' to update\x1b[0m' )
64+ }
65+ } catch {
66+ // fail silently
67+ } finally {
68+ clearTimeout ( timeoutId )
69+ }
6170}
0 commit comments