MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / scheduleBackgroundInstall

Function scheduleBackgroundInstall

packages/cli/src/utils/autoUpdate.ts:124–189  ·  view source on GitHub ↗
(latestVersion: string, currentVersion: string)

Source from the content-addressed store, hash-verified

122 * installer. Returns whether an install was spawned (for tests).
123 */
124export function scheduleBackgroundInstall(latestVersion: string, currentVersion: string): boolean {
125 if (isAutoInstallDisabled()) return false;
126 if (!latestVersion || !currentVersion) return false;
127
128 let cmp: number;
129 try {
130 cmp = compareVersions(latestVersion, currentVersion);
131 } catch {
132 return false;
133 }
134 if (cmp <= 0) return false;
135
136 // Major-version jumps carry breaking-change risk. Don't silent-install;
137 // the existing `printUpdateNotice` banner nudges the user to run
138 // `hyperframes upgrade` explicitly.
139 const latestMajor = majorOf(latestVersion);
140 const currentMajor = majorOf(currentVersion);
141 if (Number.isFinite(latestMajor) && Number.isFinite(currentMajor) && latestMajor > currentMajor) {
142 log(`[skip] major-bump ${currentVersion} -> ${latestVersion}`);
143 return false;
144 }
145
146 const installer = detectInstaller();
147 if (installer.kind === "skip") {
148 log(`[skip] ${installer.reason}`);
149 return false;
150 }
151 const installCommand = installer.installCommand(latestVersion);
152 if (!installCommand) return false;
153
154 const config = readConfig();
155
156 // Don't re-launch if a previous install is still fresh. Treat anything
157 // over PENDING_TIMEOUT_MS as stuck and let the next run supersede it.
158 if (config.pendingUpdate) {
159 const startedAt = Date.parse(config.pendingUpdate.startedAt);
160 const age = Number.isFinite(startedAt) ? Date.now() - startedAt : Number.POSITIVE_INFINITY;
161 if (age < PENDING_TIMEOUT_MS && config.pendingUpdate.version === latestVersion) {
162 return false;
163 }
164 }
165
166 // Skip if the previous completed outcome is already for this version and
167 // hasn't been surfaced yet — that run already did the work.
168 if (config.completedUpdate && config.completedUpdate.version === latestVersion) {
169 return false;
170 }
171
172 config.pendingUpdate = {
173 version: latestVersion,
174 command: installCommand,
175 startedAt: new Date().toISOString(),
176 };
177 writeConfig(config);
178
179 try {
180 launchDetachedInstall(installCommand, latestVersion);
181 return true;

Callers 1

autoUpdate.test.tsFile · 0.85

Calls 8

isAutoInstallDisabledFunction · 0.85
majorOfFunction · 0.85
logFunction · 0.85
detectInstallerFunction · 0.85
readConfigFunction · 0.85
writeConfigFunction · 0.85
launchDetachedInstallFunction · 0.85
nowMethod · 0.80

Tested by

no test coverage detected