MCPcopy
hub / github.com/foambubble/foam / checkForUpdateNotice

Function checkForUpdateNotice

packages/foam-cli/src/support/version.ts:71–109  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

69}
70
71export function checkForUpdateNotice(): string | null {
72 const cache = State.readUpdateCheck();
73
74 const shouldFetch =
75 !cache || Date.now() - new Date(cache.lastChecked).getTime() > CHECK_INTERVAL_MS;
76
77 if (shouldFetch) {
78 // Fire-and-forget background refresh — never awaited
79 fetchLatestVersion({ unref: true })
80 .then(latestVersion => {
81 State.writeUpdateCheck({
82 ...cache,
83 lastChecked: new Date().toISOString(),
84 latestVersion,
85 });
86 })
87 .catch(() => {
88 // non-critical
89 });
90 }
91
92 if (!cache || !isNewerVersion(cache.latestVersion, getCurrentVersion())) {
93 return null;
94 }
95
96 // Rate-limit: show the notice at most once per NOTIFY_INTERVAL_MS, regardless
97 // of how often the user invokes the CLI.
98 const lastNotifiedMs = cache.lastNotified ? new Date(cache.lastNotified).getTime() : 0;
99 if (Date.now() - lastNotifiedMs < NOTIFY_INTERVAL_MS) {
100 return null;
101 }
102
103 State.writeUpdateCheck({
104 ...cache,
105 lastNotified: new Date().toISOString(),
106 });
107
108 return formatUpdateNotice(cache.latestVersion);
109}

Callers 2

runCliFunction · 0.90
version.test.tsFile · 0.90

Calls 7

fetchLatestVersionFunction · 0.85
isNewerVersionFunction · 0.85
getCurrentVersionFunction · 0.85
formatUpdateNoticeFunction · 0.85
readUpdateCheckMethod · 0.80
thenMethod · 0.80
writeUpdateCheckMethod · 0.80

Tested by

no test coverage detected