Skip to content

Commit f424416

Browse files
committed
build(desktop): reduce installed app size by ~300MB
- drop extra Electron language packs (~48MB) - drop the Claude Agent SDK's bundled platform executables (~255MB). T3 Code always runs the user's own Claude install - pack dependencies into ASAR on macOS/Linux, retaining Windows-only unpacking for WSL macOS arm64: 737MB -> 424MB installed, 227MB -> 149MB DMG.
1 parent 1b4830f commit f424416

2 files changed

Lines changed: 68 additions & 18 deletions

File tree

‎scripts/build-desktop-artifact.test.ts‎

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import {
1313
createStageWorkspaceConfig,
1414
createStagePatchedDependencies,
1515
createBuildConfig,
16-
DESKTOP_ASAR_UNPACK,
16+
DESKTOP_ELECTRON_LANGUAGES,
17+
DESKTOP_FILE_EXCLUSIONS,
1718
InvalidMacPasskeyRpDomainError,
1819
InvalidMacPasskeyPublishableKeyError,
1920
InvalidMockUpdateServerPortError,
@@ -37,6 +38,7 @@ import {
3738
resolvePackageManagerUserAgent,
3839
stageLinuxIconSize,
3940
STAGE_INSTALL_ARGS,
41+
WINDOWS_ASAR_UNPACK,
4042
} from "./build-desktop-artifact.ts";
4143
import { BRAND_ASSET_PATHS } from "./lib/brand-assets.ts";
4244
import { HostProcessArchitecture, HostProcessPlatform } from "@t3tools/shared/hostProcess";
@@ -303,10 +305,53 @@ it.layer(NodeServices.layer)("build-desktop-artifact", (it) => {
303305
);
304306
});
305307

306-
it("unpacks the fff shared library for filesystem and FFI access", () => {
307-
assert.deepStrictEqual(DESKTOP_ASAR_UNPACK, ["node_modules/@ff-labs/fff-bin-*/**/*"]);
308+
it("limits Electron locales and excludes the unused Claude SDK executable", () => {
309+
assert.deepStrictEqual(DESKTOP_ELECTRON_LANGUAGES, ["en-US"]);
310+
assert.deepStrictEqual(DESKTOP_FILE_EXCLUSIONS, [
311+
"!**/node_modules/@anthropic-ai/claude-agent-sdk-*/**/*",
312+
]);
308313
});
309314

315+
it.effect("applies platform-specific packaging to the build config", () =>
316+
Effect.gen(function* () {
317+
const mac = yield* createBuildConfig(
318+
"mac",
319+
"dmg",
320+
"1.2.3",
321+
false,
322+
false,
323+
undefined,
324+
undefined,
325+
);
326+
const linux = yield* createBuildConfig(
327+
"linux",
328+
"AppImage",
329+
"1.2.3",
330+
false,
331+
false,
332+
undefined,
333+
undefined,
334+
);
335+
const win = yield* createBuildConfig(
336+
"win",
337+
"nsis",
338+
"1.2.3",
339+
false,
340+
false,
341+
undefined,
342+
undefined,
343+
);
344+
345+
assert.notProperty(mac, "asarUnpack");
346+
assert.notProperty(linux, "asarUnpack");
347+
assert.deepStrictEqual(win.asarUnpack, WINDOWS_ASAR_UNPACK);
348+
for (const config of [mac, linux, win]) {
349+
assert.deepStrictEqual(config.electronLanguages, DESKTOP_ELECTRON_LANGUAGES);
350+
assert.deepStrictEqual(config.files, DESKTOP_FILE_EXCLUSIONS);
351+
}
352+
}).pipe(Effect.provide(ConfigProvider.layer(ConfigProvider.fromEnv({ env: {} })))),
353+
);
354+
310355
it.effect("preserves both Linux icon resize failures with structural context", () => {
311356
const commands: Array<{ readonly command: string; readonly args: ReadonlyArray<string> }> = [];
312357

‎scripts/build-desktop-artifact.ts‎

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,20 @@ interface StagePackageJson {
579579
}
580580

581581
export const STAGE_INSTALL_ARGS = ["install", "--prod"] as const;
582-
export const DESKTOP_ASAR_UNPACK = ["node_modules/@ff-labs/fff-bin-*/**/*"] as const;
582+
export const DESKTOP_ELECTRON_LANGUAGES = ["en-US"] as const;
583+
export const DESKTOP_FILE_EXCLUSIONS = [
584+
// T3 Code always passes the user's installed Claude executable to the SDK,
585+
// so the SDK's optional platform packages (each a ~200MB bundled executable)
586+
// are dead weight. The trailing dash keeps the SDK's own JS package.
587+
"!**/node_modules/@anthropic-ai/claude-agent-sdk-*/**/*",
588+
] as const;
589+
// The WSL backend launches the server with plain `wsl.exe -- node`, which
590+
// cannot read inside an asar archive — and the server bundle externalizes its
591+
// runtime deps, so the whole node_modules tree must be unpacked, not just the
592+
// bundle (otherwise ERR_MODULE_NOT_FOUND: "Cannot find package 'effect'").
593+
// The Windows primary backend reads the same files through the asar redirect,
594+
// so nothing is duplicated.
595+
export const WINDOWS_ASAR_UNPACK = ["apps/server/dist/**", "**/node_modules/**"] as const;
583596

584597
export interface MacPasskeySigningConfiguration {
585598
readonly appId: string;
@@ -1390,23 +1403,15 @@ export const createBuildConfig = Effect.fn("createBuildConfig")(function* (
13901403
appId: DESKTOP_APP_ID,
13911404
productName: resolveDesktopProductName(version),
13921405
artifactName: "T3-Code-${version}-${arch}.${ext}",
1406+
electronLanguages: [...DESKTOP_ELECTRON_LANGUAGES],
1407+
files: [...DESKTOP_FILE_EXCLUSIONS],
13931408
directories: {
13941409
buildResources: "apps/desktop/resources",
13951410
},
1396-
// The Windows primary backend runs the server bundle through
1397-
// ELECTRON_RUN_AS_NODE (asar-aware), so it reads bin.mjs straight out of
1398-
// app.asar. The WSL backend instead launches plain `wsl.exe -- node`, which
1399-
// cannot read inside an asar archive, so everything it loads must be on the
1400-
// real filesystem. The server bundle externalizes its runtime dependencies
1401-
// (effect, @effect/*, node-pty, ...) to node_modules rather than inlining
1402-
// them, so unpacking just the bundle + node-pty isn't enough — the Linux Node
1403-
// fails with ERR_MODULE_NOT_FOUND (e.g. "Cannot find package 'effect'") before
1404-
// it even reaches node-pty. Unpack the server bundle AND the whole
1405-
// node_modules tree so every import resolves (this also covers the fff native
1406-
// binaries in DESKTOP_ASAR_UNPACK). The Windows primary keeps reading the same
1407-
// files through the asar (transparently redirected to the unpacked copy), so
1408-
// there's no duplication.
1409-
asarUnpack: [...DESKTOP_ASAR_UNPACK, "apps/server/dist/**", "**/node_modules/**"],
1411+
// Only the Windows WSL backend needs files outside the asar (see
1412+
// WINDOWS_ASAR_UNPACK); macOS and Linux stay packed — smart unpack
1413+
// extracts native libraries, which fff-node finds in app.asar.unpacked.
1414+
...(platform === "win" ? { asarUnpack: [...WINDOWS_ASAR_UNPACK] } : {}),
14101415
};
14111416
const updateChannel = resolveDesktopUpdateChannel(version);
14121417
const publishConfig = yield* resolveGitHubPublishConfig(updateChannel);

0 commit comments

Comments
 (0)