MCPcopy Index your code
hub / github.com/upstash/context7 / checkForUpdates

Function checkForUpdates

packages/cli/src/utils/update-check.ts:218–259  ·  view source on GitHub ↗
(
  options: CheckForUpdatesOptions = {}
)

Source from the content-addressed store, hash-verified

216}
217
218export async function checkForUpdates(
219 options: CheckForUpdatesOptions = {}
220): Promise<UpdateInfo | null> {
221 const now = options.now ?? Date.now();
222 const cacheTtlMs = options.cacheTtlMs ?? DEFAULT_CACHE_TTL_MS;
223 const stateFile = options.stateFile;
224 const state = await readUpdateState(stateFile);
225 const isStale =
226 options.force ||
227 !state.lastCheckedAt ||
228 now - state.lastCheckedAt >= cacheTtlMs ||
229 !state.latestVersion;
230
231 let latestVersion = state.latestVersion ?? null;
232
233 if (isStale) {
234 const fetchedVersion = await fetchLatestVersion();
235 if (fetchedVersion) {
236 latestVersion = fetchedVersion;
237 await writeUpdateState(
238 {
239 ...state,
240 latestVersion: fetchedVersion,
241 lastCheckedAt: now,
242 },
243 stateFile
244 );
245 }
246 }
247
248 if (!latestVersion) return null;
249
250 const installMethod = detectInstallMethod();
251
252 return {
253 currentVersion: VERSION,
254 latestVersion,
255 updateAvailable: compareVersions(latestVersion, VERSION) > 0,
256 installMethod,
257 upgradePlan: getUpgradePlan(installMethod),
258 };
259}
260
261export async function shouldShowUpdateNotification(
262 info: UpdateInfo,

Callers 4

maybeShowUpgradeNoticeFunction · 0.85
upgradeCommandFunction · 0.85

Calls 6

readUpdateStateFunction · 0.85
fetchLatestVersionFunction · 0.85
writeUpdateStateFunction · 0.85
detectInstallMethodFunction · 0.85
compareVersionsFunction · 0.85
getUpgradePlanFunction · 0.85

Tested by

no test coverage detected