diff --git a/bin/cli.js b/bin/cli.js index ff0afcd8..fbaa2009 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -47,15 +47,24 @@ if (arg === 'chat') { * Runs in the background. * @returns {Promise} */ -function checkForUpdates() { - const currentVersion = packageJson.version - return fetch('https://registry.npmjs.org/hyperparam/latest') - .then(response => response.json()) - .then(data => { - const latestVersion = data.version - if (latestVersion && latestVersion !== currentVersion) { - console.log(`\x1b[33mA newer version of hyperparam is available: ${latestVersion} (current: ${currentVersion})\x1b[0m`) - console.log('\x1b[33mRun \'npm install -g hyperparam\' to update\x1b[0m') - } +async function checkForUpdates() { + const abortController = new AbortController() + const timeout = 1000 // ms + const timeoutId = setTimeout(() => abortController.abort(), timeout) + + try { + const currentVersion = packageJson.version + const response = await fetch('https://registry.npmjs.org/hyperparam/latest', { + signal: abortController.signal, }) + const { version } = await response.json() + if (version && version !== currentVersion) { + console.log(`\x1b[33mA newer version of hyperparam is available: ${version} (current: ${currentVersion})\x1b[0m`) + console.log('\x1b[33mRun \'npm install -g hyperparam\' to update\x1b[0m') + } + } catch { + // fail silently + } finally { + clearTimeout(timeoutId) + } } diff --git a/package.json b/package.json index d1d7ab62..6f81226b 100644 --- a/package.json +++ b/package.json @@ -61,29 +61,29 @@ "icebird": "0.3.0" }, "devDependencies": { - "@eslint/js": "9.35.0", - "@storybook/react-vite": "9.1.6", + "@eslint/js": "9.36.0", + "@storybook/react-vite": "9.1.7", "@testing-library/react": "16.3.0", - "@types/node": "24.5.1", + "@types/node": "24.5.2", "@types/react": "19.1.13", "@types/react-dom": "19.1.9", "@vitejs/plugin-react": "5.0.3", "@vitest/coverage-v8": "3.2.4", - "eslint": "9.35.0", + "eslint": "9.36.0", "eslint-plugin-react": "7.37.5", "eslint-plugin-react-hooks": "5.2.0", "eslint-plugin-react-refresh": "0.4.20", - "eslint-plugin-storybook": "9.1.6", + "eslint-plugin-storybook": "9.1.7", "globals": "16.4.0", "jsdom": "27.0.0", "nodemon": "3.1.10", "npm-run-all": "4.1.5", "react": "19.1.1", "react-dom": "19.1.1", - "storybook": "9.1.6", + "storybook": "9.1.7", "typescript": "5.8.3", "typescript-eslint": "8.44.0", - "vite": "7.1.5", + "vite": "7.1.6", "vitest": "3.2.4" }, "peerDependencies": {