Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

desktop-external-packages.ts

38 lines1.6 KB

1/**
2 * Packages the desktop main-process bundle must NOT inline.
3 *
4 * The desktop bundle follows the same policy as the server CLI bundle (see
5 * cli-external-packages.ts): everything is inlined except what Node has to
6 * load from the real filesystem. Both `apps/desktop/vite.config.ts` and the
7 * artifact stage in scripts/build-desktop-artifact.ts derive from this list,
8 * so a package that is external is also the only kind of package the staged
9 * production install carries. Anything not listed here ships inside
10 * `dist-electron/*.cjs` and has no `node_modules` presence at all.
11 *
12 * Entries are matched as prefixes so platform-specific siblings are covered.
13 */
14export const DESKTOP_RUNTIME_EXTERNAL_PREFIXES = [
15 // Native addons and the wrappers that dlopen them by real path.
16 "@napi-rs/keyring",
17 "@crowecawcaw/xa11y",
18 "@clerk/electron-passkeys",
19 "ffi-rs",
20 "@yuuang/",
21 // Reads its own bundle from disk by resolving `playwright-core/package.json`
22 // at runtime and ships the browser driver alongside; there is nothing to
23 // gain from inlining a 10 MB file the code re-reads as text.
24 "playwright-core",
25] as const;
26​
27export function isDesktopRuntimeExternalDependency(id: string): boolean {
28 return DESKTOP_RUNTIME_EXTERNAL_PREFIXES.some((prefix) => id.startsWith(prefix));
30​
31/** Select the desktop dependency roots whose runtime closure the stage must install. */
32export function selectDesktopRuntimeExternalDependencies(
33 dependencies: Readonly<Record<string, string>>,
34): Record<string, string> {
35 return Object.fromEntries(
36 Object.entries(dependencies).filter(([name]) => isDesktopRuntimeExternalDependency(name)),
37 );