tracker-boot-git-hooks 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tracker-boot-git-hooks",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Git hooks for Tracker Boot — automatically comments on stories when commits are pushed",
5
5
  "type": "module",
6
6
  "bin": {
@@ -31,7 +31,10 @@
31
31
  "engines": {
32
32
  "node": ">=18.0.0"
33
33
  },
34
- "os": ["darwin", "linux"],
34
+ "os": [
35
+ "darwin",
36
+ "linux"
37
+ ],
35
38
  "dependencies": {
36
39
  "boxen": "^8.0.1"
37
40
  },
@@ -14,21 +14,27 @@ function isNewer(latest, current) {
14
14
 
15
15
  export async function checkForUpdate({ timeoutMs = 2000, fetch: _fetch = fetch } = {}) {
16
16
  const current = require('../package.json').version
17
- try {
18
- const controller = new AbortController()
19
- const timer = setTimeout(() => controller.abort(), timeoutMs)
20
- let res
17
+ const controller = new AbortController()
18
+ const deadline = new Promise(resolve => {
19
+ controller.signal.addEventListener('abort', () => resolve(null))
20
+ })
21
+ const timer = setTimeout(() => controller.abort(), timeoutMs)
22
+ const attempt = (async () => {
21
23
  try {
22
- res = await _fetch(NPM_REGISTRY_URL, { signal: controller.signal })
23
- } finally {
24
- clearTimeout(timer)
24
+ let res
25
+ try {
26
+ res = await _fetch(NPM_REGISTRY_URL, { signal: controller.signal })
27
+ } finally {
28
+ clearTimeout(timer)
29
+ }
30
+ if (!res.ok) return null
31
+ const data = await res.json()
32
+ const latest = data?.version
33
+ if (typeof latest !== 'string' || !isNewer(latest, current)) return null
34
+ return { latest, current }
35
+ } catch {
36
+ return null
25
37
  }
26
- if (!res.ok) return null
27
- const data = await res.json()
28
- const latest = data?.version
29
- if (typeof latest !== 'string' || !isNewer(latest, current)) return null
30
- return { latest, current }
31
- } catch {
32
- return null
33
- }
38
+ })()
39
+ return Promise.race([attempt, deadline])
34
40
  }