Files
vscode/build/lib/electronVersion.ts
T
roblourensandCopilot 573eff8eb4 [Perf] build: reduce local validation costs (#339968)
* build: reduce local validation costs (Written by Copilot)

Add client-only incremental builds, transpile extension JavaScript with correct module and output contracts, and reuse matching Electron runtimes for test startup. Update validation guidance and cover cold/warm state transitions and runtime loading.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* test: validate cold fast builds in CI (Written by Copilot)

Temporarily exercise cold build-fast and shipping extension activation on Windows and Linux before the existing Electron unit suites.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* test: seed cold CI activation profile (Written by Copilot)

Use the existing scenario harness profile migration setting so built-in Copilot participates in exact shipping-extension activation validation.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* test: remove temporary CI validation (Written by Copilot)

Windows x64 and Linux x64 both passed cold default build-fast and exact shipping-extension activation, language-service, and Markdown preview checks in Code OSS run 37404189501. Restore normal CI wiring and retain the validation evidence in the PR.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* build: repair caches and transpile modules (Written by Copilot)

Treat installed Electron runtime filesystem failures as cache misses while preserving repository configuration errors. Route explicit TypeScript module suffixes through extension transpilation and exclude sources and declarations from asset copying. Exercise the actual gulp task on an isolated fixture.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-10-06 11:11:35 -07:00

60 lines
2.4 KiB
TypeScript

/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import fs from 'fs';
import path from 'path';
const root = path.dirname(path.dirname(import.meta.dirname));
export function getElectronVersion(rootDir: string = root): Record<string, string> {
const npmrc = fs.readFileSync(path.join(rootDir, '.npmrc'), 'utf8');
const electronVersion = /^target="(.*)"$/m.exec(npmrc)![1];
const msBuildId = /^ms_build_id="(.*)"$/m.exec(npmrc)![1];
return { electronVersion, msBuildId };
}
export function shouldDownloadElectron(repoRoot = root, environment: NodeJS.ProcessEnv = process.env, platform: NodeJS.Platform = process.platform): boolean {
if (environment.VSCODE_SKIP_PRELAUNCH === '1') {
return false;
}
if (environment.VSCODE_FORCE_PRELAUNCH) {
return true;
}
const { electronVersion } = getElectronVersion(repoRoot);
const product: { nameLong: string; nameShort: string; applicationName: string } = JSON.parse(fs.readFileSync(path.join(repoRoot, 'product.json'), 'utf8'));
const electronDir = path.join(repoRoot, '.build', 'electron');
const executable = platform === 'darwin'
? path.join(electronDir, `${product.nameLong}.app`, 'Contents', 'MacOS', product.nameShort)
: path.join(electronDir, platform === 'win32' ? `${product.nameShort}.exe` : product.applicationName);
try {
const installedVersion = fs.readFileSync(path.join(electronDir, 'version'), 'utf8').trim().replace(/^v/, '');
if (installedVersion !== electronVersion || !fs.statSync(executable).isFile()) {
return true;
}
fs.accessSync(executable, platform === 'win32' ? fs.constants.F_OK : fs.constants.X_OK);
return false;
} catch {
return true;
}
}
/**
* Check the cached Electron version without launching it or requiring installed dependencies.
*/
export function isExpectedElectronInstalled(rootDir: string = root): boolean {
const { electronVersion } = getElectronVersion(rootDir);
try {
const installedVersion = fs.readFileSync(path.join(rootDir, '.build', 'electron', 'version'), 'utf8').trim().replace(/^v/, '');
return installedVersion === electronVersion;
} catch (error) {
if ((error as NodeJS.ErrnoException).code === 'ENOENT') {
return false;
}
throw error;
}
}