Skip to content

The agent that grows with you

perf(webapp): build the browser bundle without downloading Electron

unsupportedpastels3883e0293579
diff --git a/apps/desktop/scripts/build-webapp.mjs b/apps/desktop/scripts/build-webapp.mjs
index 43682ca4a3f..d851524adfb 100644
--- a/apps/desktop/scripts/build-webapp.mjs
+++ b/apps/desktop/scripts/build-webapp.mjs
@@ -47,6 +47,8 @@ export async function buildSourceWebapp({
prepare({
source: workspace, workspaces: ['apps/desktop'], reuse: true, install,
env: { ...process.env, npm_config_ignore_scripts: 'true' },
+ // The browser bundle never runs Electron, so its binary is not downloaded.
+ electron: false,
})
return buildWebapp({ source, workspace, out: join(source, 'apps/desktop/dist-webapp') })
}
diff --git a/scripts/build/node-deps.mjs b/scripts/build/node-deps.mjs
index 8b0596a5b0f..4655dec9719 100644
--- a/scripts/build/node-deps.mjs
+++ b/scripts/build/node-deps.mjs
@@ -90,8 +90,9 @@ function runNpmCi(node, npm, args, { source, env }) {
}
}
-/** Install the full requested workspace union in one strict, locked operation. */
-export function prepareNodeDependencies({ source, workspaces, env = process.env, reuse = false, install = true, nativeToolchain }) {
+/** Install the full requested workspace union in one strict, locked operation.
+ * ``electron: false`` leaves Desktop's Electron binary unprepared, for builds that never run it. */
+export function prepareNodeDependencies({ source, workspaces, env = process.env, reuse = false, install = true, nativeToolchain, electron = true }) {
source = resolve(source)
if (!Array.isArray(workspaces) || workspaces.length === 0) {
throw new Error('Select at least one workspace; implicit all-workspace installation is not allowed')
@@ -108,7 +109,7 @@ export function prepareNodeDependencies({ source, workspaces, env = process.env,
}
return path
}))].sort()
- const prepareElectron = selected.includes('apps/desktop')
+ const prepareElectron = electron && selected.includes('apps/desktop')
&& Boolean(JSON.parse(readFileSync(join(source, 'apps/desktop/package.json'), 'utf8')).devDependencies?.electron)
const [node, npm] = npmCommand({ env })
const npmVersion = npmManifestVersion(npm) ?? execFileSync(
diff --git a/tests-js/node-deps.test.mjs b/tests-js/node-deps.test.mjs
index f4e8ff77b0e..2a55b6adf40 100644
--- a/tests-js/node-deps.test.mjs
+++ b/tests-js/node-deps.test.mjs
@@ -118,6 +118,20 @@ test('one locked preparation retains the requested union without provisioning de
expect(createRequire(join(source, 'web/package.json'))('web-only')).toBe('web-only')
}, 30000)
+test('electron: false installs Desktop without preparing its Electron binary', async () => {
+ const { prepareNodeDependencies } = await import('../scripts/build/node-deps.mjs')
+ const source = fixture()
+ const env = { ...process.env, npm_config_offline: 'true', npm_config_cache: join(source, '.npm-cache') }
+ json(join(source, 'vendor/electron/package.json'), { name: 'electron', version: '1.0.0' })
+ json(join(source, 'apps/desktop/package.json'), { name: 'desktop', version: '1.0.0', devDependencies: { electron: 'file:../../vendor/electron' } })
+ const [node, npm] = npmCommand()
+ execFileSync(node, [npm, 'install', '--package-lock-only', '--ignore-scripts', '--no-audit', '--no-fund', '--offline'], { cwd: source, env, stdio: 'pipe' })
+ // Electron preparation runs after the install: this fake is not the version Desktop pins.
+ expect(() => prepareNodeDependencies({ source, workspaces: ['apps/desktop'], env })).toThrow(/lock-pinned/)
+ prepareNodeDependencies({ source, workspaces: ['apps/desktop'], env, electron: false })
+ expect(existsSync(join(source, 'node_modules/electron/package.json'))).toBe(true)
+}, 30000)
+
test('web-only selection excludes siblings and rejects stale locks without rewriting them', async () => {
const { prepareNodeDependencies } = await import('../scripts/build/node-deps.mjs')
const source = fixture()
diff --git a/tests-js/product-builders.test.mjs b/tests-js/product-builders.test.mjs
index fbe64095625..c418889ba6f 100644
--- a/tests-js/product-builders.test.mjs
+++ b/tests-js/product-builders.test.mjs
@@ -514,6 +514,8 @@ test('Webapp builds install privately and never disturb the native Desktop insta
installs.push(options.install)
expect(options.source).toBe(workspace)
expect(options.env.npm_config_ignore_scripts).toBe('true')
+ // The browser bundle never runs Electron, so its binary is never downloaded.
+ expect(options.electron).toBe(false)
// npm ci validates the whole locked graph, not only the compiled workspaces.
expect(existsSync(path.join(workspace, 'web/package.json'))).toBe(true)
if (!existsSync(path.join(workspace, 'node_modules/vite'))) dependency(workspace, '', 'vite')