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 format: "cjs",
90 outDir: "dist-electron",
91 dts: false,
92 sourcemap: true,
93 outExtensions: () => ({ js: ".cjs" }),
94 define: publicConfigDefine,
95 entry: ["src/preload.ts"],
96 deps: {
97 // Sandboxed Electron preloads cannot reliably resolve package imports
98 // from inside the packaged ASAR. Bundle Clerk's preload bridge into the
99 // preload artifact instead of leaving a runtime require() behind.
100 alwaysBundle: (id) => id === "@clerk/electron" || id.startsWith("@clerk/electron/"),
101 },
102 },
103 {
104 format: "cjs",
105 outDir: "dist-electron",
106 dts: false,
107 sourcemap: true,
108 outExtensions: () => ({ js: ".cjs" }),
109 entry: ["src/preview-pick-preload.ts"],
110 deps: {
111 alwaysBundle: (id) => id === "react-grab" || id.startsWith("react-grab/"),
112 },
113 },
114 {
115 format: "cjs",
116 outDir: "dist-electron",
117 dts: false,
118 sourcemap: true,
119 outExtensions: () => ({ js: ".cjs" }),
120 entry: ["src/preview-pip-preload.ts"],
121 },
122 {
123 // Sandboxed preloads must be self-contained, without shared runtime chunks.
124 format: "cjs",
125 outDir: "dist-electron",
126 dts: false,
127 sourcemap: true,
128 outExtensions: () => ({ js: ".cjs" }),
129 entry: ["src/mac-permission-preload.ts"],
130 },
131 ],
132 test: {
133 // The Windows lane runs workspace suites concurrently; filesystem-heavy
134 // desktop integration tests can exceed Vitest's 5 second default there.
135 testTimeout: 15_000,
136 setupFiles: ["../../packages/shared/src/testing/longTempDir.ts"],
137 },
138});