Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

⚡️ perf(desktop): stop double-building main and max-compressing mac zips (#22121)

Inneib4f618570088
diff --git a/.github/scripts/desktopReleasePackaging.test.mjs b/.github/scripts/desktopReleasePackaging.test.mjs
new file mode 100644
index 00000000000..03f5d58f820
--- /dev/null
+++ b/.github/scripts/desktopReleasePackaging.test.mjs
@@ -0,0 +1,47 @@
+import assert from 'node:assert/strict';
+import { readFile } from 'node:fs/promises';
+import { test } from 'node:test';
+
+const readJson = async (path) =>
+ JSON.parse(await readFile(new URL(`../../${path}`, import.meta.url), 'utf8'));
+
+const root = (await readJson('package.json')).scripts;
+const desktop = (await readJson('apps/desktop/package.json')).scripts;
+const buildElectron = await readFile(
+ new URL('../../scripts/electronWorkflow/buildElectron.ts', import.meta.url),
+ 'utf8',
+);
+const platformScripts = [
+ ...buildElectron.matchAll(/npm run (package:\w+) --prefix=\.\/apps\/desktop/g),
+].map((match) => match[1]);
+
+const expand = (scripts, name, platform) => {
+ const script = scripts[name];
+ assert.ok(script, `script ${name} exists`);
+ return script.split('&&').flatMap((part) => {
+ const command = part.trim();
+ if (command === 'tsx scripts/electronWorkflow/buildElectron.ts') {
+ return expand(desktop, platform, platform);
+ }
+ const call = command.match(
+ /^(?:cross-env (?:\S+=\S+ )+)?npm run ([\w:-]+)( --prefix=\.\/apps\/desktop)?$/,
+ );
+ if (!call) return [command];
+ return expand(call[2] ? desktop : scripts, call[1], platform);
+ });
+};
+
+test('every desktop package entry point builds the main bundle once', () => {
+ assert.deepEqual(platformScripts, ['package:mac', 'package:win', 'package:linux']);
+ for (const [entry, platforms] of [
+ ['desktop:package:app', platformScripts],
+ ['desktop:package:local', ['package:local']],
+ ]) {
+ for (const platform of platforms) {
+ const commands = expand(root, entry, platform);
+ const builds = commands.filter((command) => command.includes('vite.main.config.ts'));
+ assert.equal(builds.length, 1, `${entry} on ${platform} runs build:main once`);
+ assert.ok(commands.at(-1).startsWith('electron-builder'), `${entry} ends by packaging`);
+ }
+ }
+});
diff --git a/apps/desktop/electron-builder.mjs b/apps/desktop/electron-builder.mjs
index ed06f7a32be..17e58c6283d 100644
--- a/apps/desktop/electron-builder.mjs
+++ b/apps/desktop/electron-builder.mjs
@@ -351,6 +351,7 @@ const config = {
dmg: {
artifactName: '${productName}-${version}-${arch}.${ext}',
background: 'resources/dmg.png',
+ format: 'UDBZ',
contents: [
{ type: 'file', x: 150, y: 240 },
{ type: 'link', path: '/Applications', x: 450, y: 240 },
@@ -393,7 +394,8 @@ const config = {
'Contents/Resources/app.asar.unpacked/node_modules/font-list/libs/darwin/fontlist',
'Contents/Resources/bin/auv',
],
- compression: 'maximum',
+ // 'maximum' zips with 15-pass deflate: 7.7x slower for 0.2% smaller, up to 20 min on Intel CI. dmg.format keeps UDBZ separately.
+ compression: 'normal',
entitlementsInherit: 'build/entitlements.mac.plist',
...(macCommunicationEntitlements
? {
diff --git a/package.json b/package.json
index 070c409ce1f..9ac005be38f 100644
--- a/package.json
+++ b/package.json
@@ -72,9 +72,9 @@
"desktop:build:main": "npm run build:main --prefix=./apps/desktop",
"desktop:build-channel": "tsx scripts/electronWorkflow/buildDesktopChannel.ts",
"desktop:main:build": "npm run desktop:main:build --prefix=./apps/desktop",
- "desktop:package:app": "npm run desktop:build:all && npm run desktop:package:app:platform",
+ "desktop:package:app": "npm run desktop:package:app:platform",
"desktop:package:app:platform": "tsx scripts/electronWorkflow/buildElectron.ts",
- "desktop:package:local": "npm run desktop:build:all && npm run package:local --prefix=./apps/desktop",
+ "desktop:package:local": "npm run package:local --prefix=./apps/desktop",
"desktop:package:local:reuse": "npm run package:local:reuse --prefix=./apps/desktop",
"dev": "tsx scripts/devStartupSequence.mts",
"dev:bun": "bun --bun next dev -p 3010",