MCPcopy Create free account
hub / github.com/afar1/fieldtheory-cli / checkForUpdate

Function checkForUpdate

src/cli.ts:367–395  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

365}
366
367async function checkForUpdate(): Promise<void> {
368 try {
369 const cacheFile = path.join(dataDir(), '.update-check');
370 // Re-fetch from npm if cache is stale (>24hr)
371 let needsFetch = true;
372 try {
373 const stat = fs.statSync(cacheFile);
374 if (Date.now() - stat.mtimeMs < UPDATE_CHECK_INTERVAL_MS) needsFetch = false;
375 } catch { /* file doesn't exist, fetch */ }
376
377 if (needsFetch) {
378 const controller = new AbortController();
379 const timeout = setTimeout(() => controller.abort(), 5000);
380 const res = await fetch('https://registry.npmjs.org/fieldtheory/latest', {
381 signal: controller.signal,
382 headers: { accept: 'application/json' },
383 });
384 clearTimeout(timeout);
385
386 if (res.ok) {
387 const data = await res.json() as any;
388 if (data?.version) fs.writeFileSync(cacheFile, data.version);
389 }
390 }
391
392 // Always show notice from cache
393 showCachedUpdateNotice();
394 } catch { /* network error, offline, etc — silently skip */ }
395}
396
397/** Sync version — reads cached check result. Used after help output where we can't await. */
398function showCachedUpdateNotice(): void {

Callers 2

showDashboardFunction · 0.85
cli.tsFile · 0.85

Calls 2

dataDirFunction · 0.85
showCachedUpdateNoticeFunction · 0.85

Tested by

no test coverage detected