Skip to content

Commit e42b6e0

Browse files
authored
Add an abort timeout on the version check (#319)
1 parent b81aa3a commit e42b6e0

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

bin/cli.js

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,29 +61,29 @@
6161
"icebird": "0.3.0"
6262
},
6363
"devDependencies": {
64-
"@eslint/js": "9.35.0",
65-
"@storybook/react-vite": "9.1.6",
64+
"@eslint/js": "9.36.0",
65+
"@storybook/react-vite": "9.1.7",
6666
"@testing-library/react": "16.3.0",
67-
"@types/node": "24.5.1",
67+
"@types/node": "24.5.2",
6868
"@types/react": "19.1.13",
6969
"@types/react-dom": "19.1.9",
7070
"@vitejs/plugin-react": "5.0.3",
7171
"@vitest/coverage-v8": "3.2.4",
72-
"eslint": "9.35.0",
72+
"eslint": "9.36.0",
7373
"eslint-plugin-react": "7.37.5",
7474
"eslint-plugin-react-hooks": "5.2.0",
7575
"eslint-plugin-react-refresh": "0.4.20",
76-
"eslint-plugin-storybook": "9.1.6",
76+
"eslint-plugin-storybook": "9.1.7",
7777
"globals": "16.4.0",
7878
"jsdom": "27.0.0",
7979
"nodemon": "3.1.10",
8080
"npm-run-all": "4.1.5",
8181
"react": "19.1.1",
8282
"react-dom": "19.1.1",
83-
"storybook": "9.1.6",
83+
"storybook": "9.1.7",
8484
"typescript": "5.8.3",
8585
"typescript-eslint": "8.44.0",
86-
"vite": "7.1.5",
86+
"vite": "7.1.6",
8787
"vitest": "3.2.4"
8888
},
8989
"peerDependencies": {

0 commit comments

Comments
 (0)