| 128 | } |
| 129 | |
| 130 | async function fetchLatestVersion(name: string, signal: AbortSignal) { |
| 131 | try { |
| 132 | const response = await fetch( |
| 133 | `https://registry.npmjs.org/${encodeURIComponent(name)}/latest`, |
| 134 | { |
| 135 | signal, |
| 136 | }, |
| 137 | ) |
| 138 | if (!response.ok) return undefined |
| 139 | const data: unknown = await response.json() |
| 140 | if (!data || typeof data !== "object") return undefined |
| 141 | const version = (data as { version?: unknown }).version |
| 142 | return typeof version === "string" ? version : undefined |
| 143 | } catch { |
| 144 | return undefined |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | export function isVersionNewer(latest: string, current: string) { |
| 149 | const next = parseVersion(latest) |