Open History to see the last commit
1import "vite-plus/test/config";
2import { defineConfig } from "vite-plus";
3
4import { isDesktopRuntimeExternalDependency } from "../../scripts/lib/desktop-external-packages.ts";
5import { loadRepoEnv } from "../../scripts/lib/public-config.ts";
6
7const repoEnv = loadRepoEnv();
8
9// The main process is bundled the same way the server CLI is: every JS
10// dependency is inlined and only packages Node must load from disk stay
11// external. The packaged app then installs just those externals, instead of a
12// full production install of apps/desktop's dependency tree next to a server
13// bundle that already carries its own copy of the same libraries.
14const isMainProcessExternal = (id: string) =>
15 id === "electron" || id.startsWith("electron/") || isDesktopRuntimeExternalDependency(id);
16const shouldLaunchElectronAfterPack = process.env.T3CODE_DESKTOP_DEV === "1";
17const publicConfigDefine = {
18 __T3CODE_BUILD_CLERK_PUBLISHABLE_KEY__: JSON.stringify(
19 repoEnv.T3CODE_CLERK_PUBLISHABLE_KEY?.trim() ?? "",
20 ),
21};
22
23export default defineConfig({
24 run: {
25 tasks: {
26 build: {
27 command:
28 "node scripts/build-browser-secret.mjs && node scripts/build-preview-annotation-css.mjs && vp pack",
29 dependsOn: ["t3#build"],
30 cache: false,
31 },
32 dev: {
33 command:
34 "node scripts/build-browser-secret.mjs && node scripts/build-preview-annotation-css.mjs && cross-env T3CODE_DESKTOP_DEV=1 vp pack --watch",
35 dependsOn: ["t3#build"],
36 cache: false,
37 },
38 "dev:bundle": {
39 command:
40 "node scripts/build-browser-secret.mjs && node scripts/build-preview-annotation-css.mjs && vp pack --watch",
41 cache: false,
42 },
43 "dev:electron": {
44 command: "node scripts/dev-electron.mjs",
45 dependsOn: ["t3#build"],
46 cache: false,
47 },
48 },
49 },
50 pack: [
51 {
52 format: "cjs",
53 outDir: "dist-electron",
54 dts: false,
55 sourcemap: true,
56 outExtensions: () => ({ js: ".cjs" }),
57 define: publicConfigDefine,
58 outputOptions: { codeSplitting: false },
59 entry: ["src/main.ts"],
60 clean: true,
61 deps: {
62 alwaysBundle: (id) => !id.startsWith("node:") && !isMainProcessExternal(id),
63 neverBundle: isMainProcessExternal,
64 onlyBundle: false,
65 },
66 ...(shouldLaunchElectronAfterPack ? { onSuccess: "node scripts/dev-electron.mjs" } : {}),
67 },
68 {
69 format: "cjs",
70 outDir: "dist-electron",
71 dts: false,
72 sourcemap: true,
73 outExtensions: () => ({ js: ".cjs" }),
74 define: publicConfigDefine,
75 entry: [
76 "src/electron/WindowsForegroundFocusWorker.ts",
77 "src/snapShot/GlobalShiftShortcutWorker.ts",
78 "src/snapShot/RegionSnapShotWorker.ts",
79 "src/snapShot/SnapShotAccessibilityWorker.ts",
80 ],
81 clean: false,
82 deps: {
83 alwaysBundle: (id) => !id.startsWith("node:") && !isMainProcessExternal(id),
84 neverBundle: isMainProcessExternal,
85 onlyBundle: false,
86 },
87 },
88 {
89 // boot.cjs requires the other two at runtime, so all three stay separate files.
90 format: "cjs",
91 outDir: "dist-electron",
92 dts: false,
93 sourcemap: true,
94 outExtensions: () => ({ js: ".cjs" }),
95 entry: ["src/boot.ts", "src/compileCache.ts"],
96 clean: false,
97 deps: {
98 neverBundle: (id) => id === "./main.cjs" || id === "./compileCache.cjs",
99 },
100 },
101 {
102 format: "cjs",
103 outDir: "dist-electron",
104 dts: false,
105 sourcemap: true,
106 outExtensions: () => ({ js: ".cjs" }),
107 define: publicConfigDefine,
108 entry: ["src/preload.ts"],
109 deps: {
110 // Sandboxed Electron preloads cannot reliably resolve package imports
111 // from inside the packaged ASAR. Bundle Clerk's preload bridge into the
112 // preload artifact instead of leaving a runtime require() behind.
113 alwaysBundle: (id) => id === "@clerk/electron" || id.startsWith("@clerk/electron/"),
114 },
115 },
116 {
117 format: "cjs",
118 outDir: "dist-electron",
119 dts: false,
120 sourcemap: true,
121 outExtensions: () => ({ js: ".cjs" }),
122 entry: ["src/preview-pick-preload.ts"],
123 deps: {
124 alwaysBundle: (id) => id === "react-grab" || id.startsWith("react-grab/"),
125 },
126 },
127 {
128 format: "cjs",
129 outDir: "dist-electron",
130 dts: false,
131 sourcemap: true,
132 outExtensions: () => ({ js: ".cjs" }),
133 entry: ["src/preview-pip-preload.ts"],
134 },
135 {
136 // Sandboxed preloads must be self-contained, without shared runtime chunks.
137 format: "cjs",
138 outDir: "dist-electron",
139 dts: false,
140 sourcemap: true,
141 outExtensions: () => ({ js: ".cjs" }),
142 entry: ["src/mac-permission-preload.ts"],
143 },
144 ],
145 test: {
146 // The Windows lane runs workspace suites concurrently; filesystem-heavy
147 // desktop integration tests can exceed Vitest's 5 second default there.
148 testTimeout: 15_000,
149 setupFiles: ["../../packages/shared/src/testing/longTempDir.ts"],
150 },
151});