Open History to see the last commit
1import "vite-plus/test/config";
2import * as NodeOS from "node:os";
3
4import { defaultInclude, defineConfig } from "vite-plus";
5
6import { isDesktopRuntimeExternalDependency } from "../../scripts/lib/desktop-external-packages.ts";
7import { loadRepoEnv } from "../../scripts/lib/public-config.ts";
8
9const repoEnv = loadRepoEnv();
10const domTests = ["src/preview/PickPreload.test.ts"];
11
12// Install only bundle externals; the server bundle already carries its dependency tree.
13const isMainProcessExternal = (id: string) =>
14 id === "electron" || id.startsWith("electron/") || isDesktopRuntimeExternalDependency(id);
15const shouldLaunchElectronAfterPack = process.env.T3CODE_DESKTOP_DEV === "1";
16// tsdown runs onSuccess through a shell. dash forks instead of exec'ing the last command, which
17// would leave an `sh` between `vp pack` and the supervisor and hide `vp pack` dying from it.
18const devElectronCommand =
19 // oxlint-disable-next-line t3code/no-global-process-runtime -- Build config has no Effect runtime.
20 NodeOS.platform() === "win32"
21 ? "node scripts/dev-electron.mjs"
22 : "exec node scripts/dev-electron.mjs";
23const publicConfigDefine = {
24 __T3CODE_BUILD_CLERK_PUBLISHABLE_KEY__: JSON.stringify(
25 repoEnv.T3CODE_CLERK_PUBLISHABLE_KEY?.trim() ?? "",
26 ),
27};
28
29export default defineConfig({
30 run: {
31 tasks: {
32 build: {
33 command:
34 "node scripts/build-browser-secret.mjs && node scripts/build-preview-annotation-css.mjs && vp pack",
35 dependsOn: ["t3#build"],
36 cache: false,
37 },
38 // CI bundle jobs skip the Linux browser secret helper; packaging stages one per arch.
39 "build:bundle": {
40 command: "node scripts/build-preview-annotation-css.mjs && vp pack",
41 dependsOn: ["t3#build"],
42 cache: false,
43 },
44 dev: {
45 command:
46 "node scripts/build-browser-secret.mjs && node scripts/build-preview-annotation-css.mjs && cross-env T3CODE_DESKTOP_DEV=1 vp pack --watch",
47 dependsOn: ["t3#build"],
48 cache: false,
49 },
50 "dev:bundle": {
51 command:
52 "node scripts/build-browser-secret.mjs && node scripts/build-preview-annotation-css.mjs && vp pack --watch",
53 cache: false,
54 },
55 "dev:electron": {
56 command: "node scripts/dev-electron.mjs",
57 dependsOn: ["t3#build"],
58 cache: false,
59 },
60 // A local tsbuildinfo is leftover build state, not a typecheck input.
61 typecheck: {
62 command: "effect-tsgo tsrs --noEmit",
63 cache: { input: [{ auto: true }, "!*.tsbuildinfo"] },
64 },
65 },
66 },
67 pack: [
68 {
69 format: "cjs",
70 outDir: "dist-electron",
71 dts: false,
72 sourcemap: true,
73 outExtensions: () => ({ js: ".cjs" }),
74 define: publicConfigDefine,
75 outputOptions: { codeSplitting: false },
76 entry: ["src/main.ts"],
77 clean: true,
78 deps: {
79 alwaysBundle: (id) => !id.startsWith("node:") && !isMainProcessExternal(id),
80 neverBundle: isMainProcessExternal,
81 onlyBundle: false,
82 },
83 ...(shouldLaunchElectronAfterPack ? { onSuccess: devElectronCommand } : {}),
84 },
85 {
86 format: "cjs",
87 outDir: "dist-electron",
88 dts: false,
89 sourcemap: true,
90 outExtensions: () => ({ js: ".cjs" }),
91 define: publicConfigDefine,
92 entry: [
93 "src/electron/WindowsForegroundFocusWorker.ts",
94 "src/snapShot/GlobalShiftShortcutWorker.ts",
95 "src/snapShot/RegionSnapShotWorker.ts",
96 "src/snapShot/SnapShotAccessibilityWorker.ts",
97 ],
98 clean: false,
99 deps: {
100 alwaysBundle: (id) => !id.startsWith("node:") && !isMainProcessExternal(id),
101 neverBundle: isMainProcessExternal,
102 onlyBundle: false,
103 },
104 },
105 {
106 // boot.cjs requires the other two at runtime, so all three stay separate files.
107 format: "cjs",
108 outDir: "dist-electron",
109 dts: false,
110 sourcemap: true,
111 outExtensions: () => ({ js: ".cjs" }),
112 entry: ["src/boot.ts", "src/compileCache.ts", "src/serverCompileCache.ts"],
113 clean: false,
114 deps: {
115 neverBundle: (id) => id === "./main.cjs" || id === "./compileCache.cjs",
116 },
117 },
118 {
119 format: "cjs",
120 outDir: "dist-electron",
121 dts: false,
122 sourcemap: true,
123 outExtensions: () => ({ js: ".cjs" }),
124 define: publicConfigDefine,
125 entry: ["src/preload.ts"],
126 deps: {
127 // Sandboxed preloads cannot resolve imports inside ASAR; bundle Clerk's bridge.
128 alwaysBundle: (id) => id === "@clerk/electron" || id.startsWith("@clerk/electron/"),
129 },
130 },
131 {
132 format: "cjs",
133 outDir: "dist-electron",
134 dts: false,
135 sourcemap: true,
136 outExtensions: () => ({ js: ".cjs" }),
137 entry: ["src/preview-pick-preload.ts"],
138 deps: {
139 alwaysBundle: (id) =>
140 id === "react-grab" ||
141 id.startsWith("react-grab/") ||
142 id === "@t3tools/shared/keybindingMatching",
143 },
144 },
145 {
146 format: "cjs",
147 outDir: "dist-electron",
148 dts: false,
149 sourcemap: true,
150 outExtensions: () => ({ js: ".cjs" }),
151 entry: ["src/preview-pip-preload.ts"],
152 },
153 {
154 // Sandboxed preloads must be self-contained, without shared runtime chunks.
155 format: "cjs",
156 outDir: "dist-electron",
157 dts: false,
158 sourcemap: true,
159 outExtensions: () => ({ js: ".cjs" }),
160 entry: ["src/mac-permission-preload.ts"],
161 },
162 ],
163 test: {
164 // The Windows lane runs workspace suites concurrently; filesystem-heavy
165 // desktop integration tests can exceed Vitest's 5 second default there.
166 testTimeout: 15_000,
167 projects: [
168 {
169 extends: true,
170 test: {
171 name: "unit",
172 include: [...defaultInclude, "../../native/kde-snap-shot/src/*.test.ts"],
173 exclude: ["**/node_modules/**", ...domTests],
174 setupFiles: [
175 "../../packages/shared/src/testing/longTempDir.ts",
176 "../../packages/shared/src/testing/providerEnv.ts",
177 ],
178 },
179 },
180 {
181 extends: true,
182 test: {
183 name: "dom",
184 include: domTests,
185 // Guest preloads run in the page; these tests drive them against a DOM.
186 environment: "jsdom",
187 setupFiles: ["../../packages/shared/src/testing/providerEnv.ts"],
188 },
189 },
190 ],
191 },
192});