feat(autoupdate): Improve update check and refactor for testability (#5389)

This commit is contained in:
Gal Zahavi
2025-08-01 20:17:32 -07:00
committed by GitHub
parent 15a1f1af9d
commit 820169ba2e
5 changed files with 258 additions and 68 deletions

View File

@@ -4,17 +4,19 @@
* SPDX-License-Identifier: Apache-2.0
*/
import { spawn } from 'node:child_process';
import { UpdateObject } from '../ui/utils/updateCheck.js';
import { LoadedSettings } from '../config/settings.js';
import { getInstallationInfo } from './installationInfo.js';
import { updateEventEmitter } from './updateEventEmitter.js';
import { HistoryItem, MessageType } from '../ui/types.js';
import { spawnWrapper } from './spawnWrapper.js';
import { spawn } from 'child_process';
export function handleAutoUpdate(
info: UpdateObject | null,
settings: LoadedSettings,
projectRoot: string,
spawnFn: typeof spawn = spawnWrapper,
) {
if (!info) {
return;
@@ -37,13 +39,13 @@ export function handleAutoUpdate(
if (!installationInfo.updateCommand || settings.merged.disableAutoUpdate) {
return;
}
const isNightly = info.update.latest.includes('nightly');
const updateCommand = installationInfo.updateCommand.replace(
'@latest',
`@${info.update.latest}`,
isNightly ? '@nightly' : `@${info.update.latest}`,
);
const updateProcess = spawn(updateCommand, { stdio: 'pipe', shell: true });
const updateProcess = spawnFn(updateCommand, { stdio: 'pipe', shell: true });
let errorOutput = '';
updateProcess.stderr.on('data', (data) => {
errorOutput += data.toString();