Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

vite.config.ts

534 lines19.1 KB

1import "vite-plus/test/config";
2import { defineConfig } from "vite-plus";
3import * as NodeURL from "node:url";
4​
5const DOM_TEST_ENVIRONMENT_ALLOWLIST: Array<string> = [];
6​
7const TEST_EXCLUDE = [
8 "**/.repos/**",
9 "**/.t3/**",
10 "**/node_modules/**",
11 "**/dist/**",
12 "**/dist-electron/**",
13 "**/.{idea,git,cache,output,temp}/**",
14];
15​
16// Directories whose tests belong to a package's own test config. desktop also
17// owns the kde-snap-shot tests through its `include`.
18const TEST_CONFIG_PACKAGES = [
19 "apps/desktop",
20 "apps/mobile",
21 "apps/server",
22 "apps/web",
23 "packages/client-runtime",
24];
25​
26// `vp test run <file>` from the repo root hands each file to its package's
27// config. Packages that borrow this config (`--config ../../vite.config.ts`) run
28// from their own directory, as CI does, so they keep one plain project.
29const isRepoRootTestRun = process.cwd() === import.meta.dirname;
30​
31const RESTRICTED_IMPORT_PATHS = [
32 {
33 name: "@t3tools/client-runtime",
34 message:
35 "Import from an explicit @t3tools/client-runtime/* subpath. The package has no root export.",
36 },
37 {
38 name: "@pierre/diffs/react",
39 importNames: ["CodeView"],
40 message: "Use StyledDiffCodeView so web diff surfaces share styling and virtualized geometry.",
41 },
42];
43​
44const RESTRICTED_UI_VARIANT_PATTERNS = [
45 {
46 group: ["**/components/ui/*", "**/ui/*", "./ui/*"],
47 importNames: ["buttonVariants", "toggleVariants", "badgeVariants", "selectTriggerVariants"],
48 message:
49 "Render the components/ui export instead of borrowing its class recipe (render={<Button …/>}, SelectButton, ToggleGroup).",
50 },
51];
52​
53const RESTRICTED_PULL_REQUEST_GLYPH_IMPORTS = {
54 name: "lucide-react",
55 importNames: [
56 "GitMerge",
57 "GitMergeIcon",
58 "GitPullRequest",
59 "GitPullRequestIcon",
60 "GitPullRequestArrow",
61 "GitPullRequestArrowIcon",
62 "GitPullRequestClosed",
63 "GitPullRequestClosedIcon",
64 "GitPullRequestDraft",
65 "GitPullRequestDraftIcon",
66 "GitPullRequestCreate",
67 "GitPullRequestCreateIcon",
68 "GitPullRequestCreateArrow",
69 "GitPullRequestCreateArrowIcon",
70 ],
71 message:
72 "Pick a glyph by meaning from PullRequestGlyph in apps/web/src/components/pullRequest/pullRequestIcons.tsx so every surface draws the same pull request the same way.",
73};
74​
75export default defineConfig({
76 resolve: {
77 alias: {
78 "~": NodeURL.fileURLToPath(new URL("./apps/web/src", import.meta.url)),
79 },
80 },
81 test: {
82 environment: "node",
83 exclude: TEST_EXCLUDE,
84 hookTimeout: 60_000,
85 testTimeout: 60_000,
86 allowOnly: !process.env.CI,
87 // Flaky tests are fixed, not retried.
88 retry: 0,
89 fakeTimers: {
90 toFake: [
91 "setTimeout",
92 "clearTimeout",
93 "setInterval",
94 "clearInterval",
95 "setImmediate",
96 "clearImmediate",
97 "Date",
98 "performance",
99 "requestAnimationFrame",
100 "cancelAnimationFrame",
101 "requestIdleCallback",
102 "cancelIdleCallback",
103 ],
104 },
105 setupFiles: [
106 NodeURL.fileURLToPath(
107 new URL("./packages/shared/src/testing/longTempDir.ts", import.meta.url),
108 ),
109 NodeURL.fileURLToPath(
110 new URL("./packages/shared/src/testing/providerEnv.ts", import.meta.url),
111 ),
112 ],
113 ...(isRepoRootTestRun
114 ? {
115 projects: [
116 ...TEST_CONFIG_PACKAGES,
117 {
118 extends: true,
119 test: {
120 name: "root",
121 exclude: [
122 ...TEST_EXCLUDE,
123 ...TEST_CONFIG_PACKAGES.map((dir) => `${dir}/**`),
124 "native/kde-snap-shot/**",
125 ],
126 },
127 },
128 ],
129 }
130 : {}),
131 },
132 staged: {
133 "*": "vp fmt --no-error-on-unmatched-pattern",
134 },
135 fmt: {
136 ignorePatterns: [
137 ".repos/**",
138 // Macroscope's glob-per-line ignore grammar, not Markdown: formatting
139 // it rewrites `*` as `_` and joins lines.
140 ".macroscope/ignore.md",
141 ".alchemy",
142 "dist",
143 "dist-electron",
144 "node_modules",
145 "pnpm-lock.yaml",
146 "*.tsbuildinfo",
147 "**/routeTree.gen.ts",
148 "**/*.graphql.ts",
149 "packages/source-control-github/schema/**",
150 "apps/server/schema/**",
151 "apps/mobile/android/**",
152 "apps/mobile/ios/**",
153 "apps/mobile/uniwind-types.d.ts",
154 "*.icon/**",
155 ],
156 sortPackageJson: {},
157 overrides: [
158 {
159 files: [".devcontainer/devcontainer.json"],
160 options: {
161 trailingComma: "none",
162 },
163 },
164 ],
165 },
166 lint: {
167 ignorePatterns: [
168 ".repos",
169 ".repos/**",
170 "dist",
171 "dist-electron",
172 "node_modules",
173 "pnpm-lock.yaml",
174 "*.tsbuildinfo",
175 "**/routeTree.gen.ts",
176 "**/*.graphql.ts",
177 "packages/source-control-github/schema/**",
178 "apps/server/schema/**",
179 "apps/mobile/android/**",
180 "apps/mobile/ios/**",
181 "apps/mobile/uniwind-types.d.ts",
182 ],
183 plugins: ["eslint", "oxc", "react", "unicorn", "typescript"],
184 jsPlugins: ["./oxlint-plugin-t3code/index.ts", "@shadcn/lint"],
185 settings: {
186 shadcn: { ui: "~/components/ui" },
187 },
188 categories: {
189 correctness: "warn",
190 suspicious: "warn",
191 perf: "warn",
192 },
193 rules: {
194 "unicorn/no-array-sort": "off",
195 "unicorn/consistent-function-scoping": "off",
196 "oxc/no-map-spread": "off",
197 "react-in-jsx-scope": "off",
198 "react-hooks/exhaustive-deps": "off",
199 "eslint/no-shadow": "off",
200 "eslint/no-await-in-loop": "off",
201 "eslint/no-underscore-dangle": "off",
202 "typescript/consistent-return": "off",
203 "typescript/no-base-to-string": "off",
204 "typescript/no-duplicate-type-constituents": "off",
205 "typescript/no-floating-promises": "off",
206 "typescript/no-implied-eval": "off",
207 "typescript/no-meaningless-void-operator": "off",
208 "typescript/no-redundant-type-constituents": "off",
209 "typescript/no-unnecessary-boolean-literal-compare": "off",
210 "typescript/no-unnecessary-type-conversion": "off",
211 "typescript/no-unnecessary-type-arguments": "off",
212 "typescript/no-unnecessary-type-assertion": "off",
213 "typescript/no-unnecessary-type-parameters": "off",
214 "typescript/no-unsafe-type-assertion": "off",
215 "typescript/await-thenable": "off",
216 "typescript/require-array-sort-compare": "off",
217 "typescript/restrict-template-expressions": "off",
218 "typescript/unbound-method": "off",
219 "eslint/no-restricted-imports": [
220 "error",
221 { paths: [...RESTRICTED_IMPORT_PATHS, RESTRICTED_PULL_REQUEST_GLYPH_IMPORTS] },
222 ],
223 "t3code/no-global-process-runtime": "error",
224 "t3code/no-inline-schema-compile": "warn",
225 "t3code/no-low-value-comments": "error",
226 "t3code/no-manual-effect-runtime-in-tests": "error",
227 "t3code/no-native-title-tooltip": "error",
228 // Test files only (the rule checks the filename). Becomes an error once existing polls are converted.
229 "t3code/no-polling-loop-in-tests": "warn",
230 "t3code/no-raw-mcp-registration": "error",
231 "t3code/no-real-time-wait-in-tests": "error",
232 "t3code/no-test-in-loop": "error",
233 "t3code/no-test-timeout-or-unreasoned-skip": "error",
234 "t3code/no-rpc-permission-bypass": ["error", { allowRawClientAccess: true }],
235 "t3code/no-unscoped-has": "error",
236 "t3code/no-wall-clock-in-tests": "error",
237 "t3code/namespace-node-imports": "error",
238 "t3code/prefer-catch-tags": "error",
239 "t3code/prefer-effect-fn": "error",
240 "t3code/require-centered-scroll-gutter": "error",
241 "t3code/require-suppression-reason": "error",
242 },
243 overrides: [
244 {
245 files: [
246 "**/*.{test,spec,testkit}.{ts,tsx}",
247 "**/{test,tests,testkit,testing,fixtures,integration}/**",
248 "packages/provider-testing/**",
249 ],
250 rules: { "t3code/prefer-effect-fn": "off" },
251 },
252 {
253 files: ["apps/web/**/*.test.{ts,tsx}"],
254 rules: { "t3code/require-disposable-render": "error" },
255 },
256 {
257 files: ["apps/web/src/**/*.browser.test.{ts,tsx}"],
258 rules: { "t3code/no-frame-waits-in-browser-tests": "error" },
259 },
260 {
261 files: ["**/*.browser.test.*"],
262 rules: { "t3code/no-real-time-wait-in-tests": "off" },
263 },
264 {
265 files: ["apps/**/src/**", "packages/**/src/**"],
266 excludeFiles: DOM_TEST_ENVIRONMENT_ALLOWLIST,
267 rules: { "t3code/no-dom-test-environment": "error" },
268 },
269 {
270 files: ["packages/client-runtime/src/state/**", "apps/{web,mobile,desktop}/src/**"],
271 rules: { "t3code/no-rpc-permission-bypass": ["error", { allowRawClientAccess: false }] },
272 },
273 {
274 files: [
275 "packages/client-runtime/src/state/runtime.ts",
276 "packages/client-runtime/src/state/vcsAction.ts",
277 ],
278 rules: {
279 "t3code/no-rpc-permission-bypass": [
280 "error",
281 { allowGuardInstallation: true, allowRawClientAccess: false },
282 ],
283 },
284 },
285 {
286 files: [
287 "apps/web/src/components/settings/AuthorizedClientsSettings.tsx",
288 "apps/web/src/components/settings/ConnectionsSettings.tsx",
289 "apps/mobile/src/features/updates/app-updates.ts",
290 "apps/web/src/components/device/DevicePhoneViewport.tsx",
291 "apps/web/src/components/device/DeviceDuoViewport.tsx",
292 ],
293 rules: { "t3code/no-rpc-permission-bypass": ["error", { allowRawClientAccess: true }] },
294 },
295 {
296 files: ["packages/client-runtime/src/connection/outdatedHostUpdate.ts"],
297 rules: { "t3code/no-rpc-permission-bypass": "off" },
298 },
299 {
300 files: [
301 "packages/client-runtime/src/rpc/**",
302 "**/*.{test,spec}.{ts,tsx,js,jsx,mts,cts,mjs,cjs}",
303 ],
304 rules: { "t3code/no-rpc-permission-bypass": "off" },
305 },
306 {
307 files: ["packages/shared/src/HostProcess.ts"],
308 rules: { "t3code/no-global-process-runtime": "off" },
309 },
310 {
311 // The `t3` npm launcher is published as plain, dependency-free Node.
312 files: ["scripts/npm-launcher/**"],
313 rules: {
314 "t3code/no-global-process-runtime": "off",
315 "t3code/namespace-node-imports": "off",
316 },
317 },
318 {
319 files: ["apps/server/src/mcp/McpHttpServer.ts"],
320 rules: { "t3code/no-raw-mcp-registration": "off" },
321 },
322 {
323 files: ["apps/web/src/**"],
324 excludeFiles: ["apps/web/src/components/ui/**"],
325 rules: {
326 "eslint/no-restricted-imports": [
327 "error",
328 {
329 paths: [...RESTRICTED_IMPORT_PATHS, RESTRICTED_PULL_REQUEST_GLYPH_IMPORTS],
330 patterns: RESTRICTED_UI_VARIANT_PATTERNS,
331 },
332 ],
333 },
334 },
335 {
336 files: ["apps/web/src/components/pullRequest/pullRequestIcons.tsx"],
337 rules: { "eslint/no-restricted-imports": ["error", { paths: RESTRICTED_IMPORT_PATHS }] },
338 },
339 {
340 files: ["apps/mobile/src/**"],
341 rules: { "t3code/no-mobile-uniwind-theme-escape-hatches": "error" },
342 },
343 {
344 files: ["apps/mobile/src/**"],
345 excludeFiles: [
346 "apps/mobile/src/components/ui/AppSymbol.tsx",
347 "apps/mobile/src/components/ui/AppSymbol.ios.tsx",
348 "apps/mobile/src/features/pull-requests/pullRequestGlyphs.ts",
349 ],
350 rules: { "t3code/no-mobile-pull-request-glyph-literals": "error" },
351 },
352 {
353 // React commits state set in a raw ResizeObserver callback after the paint, so derived
354 // layout lands a frame late. observeResize flushes every observed resize in one render.
355 files: ["apps/web/src/**"],
356 excludeFiles: [
357 "apps/web/src/lib/observeResize.ts",
358 "**/*.{test,spec}.{ts,tsx,js,jsx,mts,cts,mjs,cjs}",
359 ],
360 rules: { "t3code/no-raw-resize-observer": "error" },
361 },
362 {
363 files: ["apps/web/src/**"],
364 rules: { "shadcn/no-unknown-classes": "error" },
365 },
366 {
367 files: ["apps/web/src/**"],
368 rules: { "t3code/no-outset-state-indicators": "error" },
369 },
370 {
371 files: ["apps/*/src/**", "packages/*/src/**"],
372 excludeFiles: [
373 "**/*.{test,spec}.{ts,tsx,js,jsx,mts,cts,mjs,cjs}",
374 "**/testkit/**",
375 "**/_generated/**",
376 // Real user quotes stay verbatim.
377 "apps/marketing/src/lib/tweets.ts",
378 ],
379 rules: { "t3code/no-em-dash-copy": "error" },
380 },
381 {
382 files: ["apps/web/src/**"],
383 rules: { "shadcn/no-raw-colors": "error" },
384 },
385 {
386 // Third-party marks (brand logos, the macOS permission panes, Codex's Computer Use
387 // mark) must keep their exact colors, so the files that hold them are exempt.
388 files: ["apps/web/src/components/Icons.tsx", "apps/web/src/components/JetBrainsIcons.tsx"],
389 rules: { "shadcn/no-raw-colors": "off" },
390 },
391 {
392 files: ["apps/web/src/**"],
393 excludeFiles: ["apps/web/src/components/ui/**"],
394 rules: {
395 "shadcn/require-static-classes": "error",
396 "shadcn/no-arbitrary-values": [
397 "error",
398 {
399 allow: [
400 "layout",
401 "transition",
402 "rounded-[inherit]",
403 "gap-[0.33em]",
404 "px-[0.5em]",
405 "rounded-[0.5em]",
406 "text-[0.86em]",
407 "rounded-[25%]",
408 "text-[length:80cqh]",
409 "bg-[Highlight]",
410 "fill-[#26251E]",
411 "fill-[#EDECEC]",
412 "fill-[#0F0F0F]",
413 "fill-[#F5F5F5]",
414 "fill-[#d97757]",
415 "text-[#d97757]",
416 ],
417 },
418 ],
419 "shadcn/no-restyle": [
420 "error",
421 {
422 allow: ["layout"],
423 contracts: [
424 {
425 // CollapsibleTrigger is a bare button with no styled counterpart
426 // (a disclosure row is not a Button), so its className is the API.
427 // Every other trigger has one: style them with render={<Button …/>}.
428 pattern: "^CollapsibleTrigger$",
429 allow: ["layout", "color", "typography", "spacing", "shape", "effects", "motion"],
430 },
431 ],
432 },
433 ],
434 },
435 },
436 {
437 // Every web file must compile under the React Compiler. Its bailout rules are errors here,
438 // and manual memoization is redundant. No upstream rule bans useMemo/useCallback, hence
439 // t3code/no-manual-memo.
440 files: ["apps/web/src/**/*.{ts,tsx}"],
441 rules: {
442 "react/exhaustive-effect-dependencies": "error",
443 "react/globals": "error",
444 "react/hooks": "error",
445 "react/immutability": "error",
446 // The compiler memoizes context values; this rule would ask for useMemo.
447 "react/jsx-no-constructed-context-values": "off",
448 "react/memo-dependencies": "error",
449 "react/preserve-manual-memoization": "error",
450 // oxlint 1.88 treats `new Date()` as impure (oxc#26894) and also flags it inside event
451 // handlers (oxc#27309). The compiler we ship (oxc-transform-react) still compiles
452 // those files, and reactCompilerCoverage.test.ts fails on real bailouts.
453 "react/purity": "warn",
454 "react/refs": "error",
455 "react/set-state-in-effect": "error",
456 "react/set-state-in-render": "error",
457 "react/static-components": "error",
458 "react/unsupported-syntax": "error",
459 "t3code/no-manual-memo": "error",
460 },
461 },
462 {
463 // The sign-in masthead is T3 brand artwork: fixed gradients, not theme surfaces.
464 files: ["apps/web/src/components/auth/AuthSurfaceShell.tsx"],
465 rules: { "shadcn/no-arbitrary-values": "off" },
466 },
467 {
468 // Shared client code must not call APIs missing from Hermes. Our ESNext
469 // TypeScript target accepts them even when they would crash mobile at launch.
470 // Tests run on Node and are exempt.
471 files: [
472 "apps/mobile/src/**",
473 "packages/client-runtime/src/**",
474 "packages/contracts/src/**",
475 "packages/shared/src/**",
476 ],
477 excludeFiles: ["**/*.test.ts", "**/*.test.tsx"],
478 rules: { "t3code/no-hermes-unsupported-apis": "error" },
479 },
480 {
481 // Mobile is ratcheting toward full React Compiler coverage
482 // (apps/mobile/src/reactCompilerCoverage.test.ts). Directives would hide bailouts from it;
483 // the manual memo hooks go once the allowlist there is empty.
484 files: ["apps/mobile/src/**/*.{ts,tsx}"],
485 rules: { "t3code/no-manual-memo": ["error", { allowMemoHooks: true }] },
486 },
487 {
488 // The compiler only compiles a use* function that calls a hook; one that calls none is
489 // silently left as a plain function, so whatever it returns loses its caching.
490 files: ["apps/web/src/**/*.{ts,tsx}", "apps/mobile/src/**/*.{ts,tsx}"],
491 excludeFiles: ["**/*.test.ts", "**/*.test.tsx"],
492 rules: { "t3code/no-hookless-use-function": "error" },
493 },
494 {
495 files: [
496 "apps/mobile/src/features/archive/ArchivedThreadsScreen.tsx",
497 "apps/mobile/src/features/connection/ConnectionsNewRouteScreen.tsx",
498 "apps/mobile/src/features/files/FileMarkdownPreview.tsx",
499 "apps/mobile/src/features/files/SourceFileSurface.tsx",
500 "apps/mobile/src/features/files/AttachmentFileScreen.tsx",
501 "apps/mobile/src/features/files/ThreadFilesRouteScreen.tsx",
502 "apps/mobile/src/features/files/thread-file-navigator-pane.tsx",
503 "apps/mobile/src/features/home/HomeHeader.tsx",
504 "apps/mobile/src/features/review/ReviewSheet.tsx",
505 "apps/mobile/src/features/review/useNativeReviewDiffBridge.ts",
506 "apps/mobile/src/features/settings/SettingsEnvironmentsRouteScreen.tsx",
507 "apps/mobile/src/features/threads/GitActionProgressOverlay.tsx",
508 "apps/mobile/src/features/threads/NewTaskDraftScreen.tsx",
509 "apps/mobile/src/features/threads/ThreadComposer.tsx",
510 "apps/mobile/src/features/threads/ThreadFeed.tsx",
511 "apps/mobile/src/features/settings/appearance/components/FontSizeSliderRow.tsx",
512 "apps/mobile/src/features/threads/NewTaskContextPickerScreens.tsx",
513 "apps/mobile/src/features/threads/ThreadQueueControl.tsx",
514 "apps/mobile/src/features/review/ReviewCommentCard.tsx",
515 "apps/mobile/src/features/threads/ThreadSettingsSheet.tsx",
516 "apps/mobile/src/features/threads/thread-list-items.tsx",
517 "apps/mobile/src/features/threads/thread-list-v2-items.tsx",
518 "apps/mobile/src/lib/useMobileNavigationTheme.ts",
519 "apps/mobile/src/native/T3ComposerEditor.ios.tsx",
520 "apps/mobile/src/native/T3ComposerEditor.native.tsx",
521 "apps/mobile/src/native/SelectableMarkdownText.tsx",
522 ],
523 rules: {
524 "t3code/no-mobile-uniwind-theme-escape-hatches": ["error", { allowUniwindTheme: true }],
525 },
526 },
527 ],
528 options: {
529 reportUnusedDisableDirectives: "error",
530 typeAware: false,
531 typeCheck: false,
532 },
533 },
534});