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 "electron-webauthn",
20 "ffi-rs",
21 "@yuuang/",
22 // Reads its own bundle from disk by resolving `playwright-core/package.json`
23 // at runtime and ships the browser driver alongside; there is nothing to
24 // gain from inlining a 10 MB file the code re-reads as text.
25 "playwright-core",
26] as const;
27
28export function isDesktopRuntimeExternalDependency(id: string): boolean {
29 return DESKTOP_RUNTIME_EXTERNAL_PREFIXES.some((prefix) => id.startsWith(prefix));
30}
31
32/** Select the desktop dependency roots whose runtime closure the stage must install. */
33export function selectDesktopRuntimeExternalDependencies(
34 dependencies: Readonly<Record<string, string>>,
35): Record<string, string> {
36 return Object.fromEntries(
37 Object.entries(dependencies).filter(([name]) => isDesktopRuntimeExternalDependency(name)),
38 );
39}