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