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

vite.config.ts

300 lines11.7 KB

1import "vite-plus/test/config";
2import { defineConfig } from "vite-plus";
3import * as NodeURL from "node:url";
4​
5/** Import restrictions every file keeps, including the one module exempt from the glyph rule. */
6const RESTRICTED_IMPORT_PATHS = [
7 {
8 name: "@t3tools/client-runtime",
9 message:
10 "Import from an explicit @t3tools/client-runtime/* subpath. The package has no root export.",
11 },
12 {
13 name: "@pierre/diffs/react",
14 importNames: ["CodeView"],
15 message: "Use StyledDiffCodeView so web diff surfaces share styling and virtualized geometry.",
16 },
17];
18​
19/**
20 * The cva functions behind components/ui exports. They style a foreign element to look
21 * like a Button or Toggle, which bypasses the component's variants; render the component
22 * instead (`render={<Button …/>}`, or `SelectButton` for a picker trigger).
23 */
24const RESTRICTED_UI_VARIANT_PATTERNS = [
25 {
26 group: ["**/components/ui/*", "**/ui/*", "./ui/*"],
27 importNames: ["buttonVariants", "toggleVariants", "badgeVariants", "selectTriggerVariants"],
28 message:
29 "Render the components/ui export instead of borrowing its class recipe (render={<Button …/>}, SelectButton, ToggleGroup).",
30 },
31];
32​
33/** Lucide's pull-request glyphs, which only `pullRequestIcons.tsx` may name. */
34const RESTRICTED_PULL_REQUEST_GLYPH_IMPORTS = {
35 name: "lucide-react",
36 importNames: [
37 "GitMerge",
38 "GitMergeIcon",
39 "GitPullRequest",
40 "GitPullRequestIcon",
41 "GitPullRequestArrow",
42 "GitPullRequestArrowIcon",
43 "GitPullRequestClosed",
44 "GitPullRequestClosedIcon",
45 "GitPullRequestDraft",
46 "GitPullRequestDraftIcon",
47 "GitPullRequestCreate",
48 "GitPullRequestCreateIcon",
49 "GitPullRequestCreateArrow",
50 "GitPullRequestCreateArrowIcon",
51 ],
52 message:
53 "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.",
54};
55​
56export default defineConfig({
57 resolve: {
58 alias: {
59 "~": NodeURL.fileURLToPath(new URL("./apps/web/src", import.meta.url)),
60 },
61 },
62 test: {
63 environment: "node",
64 exclude: [
65 "**/.repos/**",
66 "**/node_modules/**",
67 "**/dist/**",
68 "**/dist-electron/**",
69 "**/.{idea,git,cache,output,temp}/**",
70 ],
71 hookTimeout: 60_000,
72 testTimeout: 60_000,
73 setupFiles: [
74 NodeURL.fileURLToPath(
75 new URL("./packages/shared/src/testing/longTempDir.ts", import.meta.url),
76 ),
77 ],
78 },
79 staged: {
80 // Formatter only for now — no lint or typecheck on commit.
81 "*": "vp fmt --no-error-on-unmatched-pattern",
82 },
83 fmt: {
84 ignorePatterns: [
85 ".repos/**",
86 // Macroscope's glob-per-line ignore grammar, not Markdown: formatting
87 // it rewrites `*` as `_` and joins lines.
88 ".macroscope/ignore.md",
89 ".alchemy",
90 "dist",
91 "dist-electron",
92 "node_modules",
93 "pnpm-lock.yaml",
94 "*.tsbuildinfo",
95 "**/routeTree.gen.ts",
96 "apps/mobile/android/**",
97 "apps/mobile/ios/**",
98 "apps/mobile/uniwind-types.d.ts",
99 "*.icon/**",
100 ],
101 sortPackageJson: {},
102 overrides: [
103 {
104 files: [".devcontainer/devcontainer.json"],
105 options: {
106 trailingComma: "none",
107 },
108 },
109 ],
110 },
111 lint: {
112 ignorePatterns: [
113 ".repos",
114 ".repos/**",
115 "dist",
116 "dist-electron",
117 "node_modules",
118 "pnpm-lock.yaml",
119 "*.tsbuildinfo",
120 "**/routeTree.gen.ts",
121 "apps/mobile/android/**",
122 "apps/mobile/ios/**",
123 "apps/mobile/uniwind-types.d.ts",
124 ],
125 plugins: ["eslint", "oxc", "react", "unicorn", "typescript"],
126 jsPlugins: ["./oxlint-plugin-t3code/index.ts", "@shadcn/lint"],
127 settings: {
128 shadcn: { ui: "~/components/ui" },
129 },
130 categories: {
131 correctness: "warn",
132 suspicious: "warn",
133 perf: "warn",
134 },
135 rules: {
136 "unicorn/no-array-sort": "off",
137 "unicorn/consistent-function-scoping": "off",
138 "oxc/no-map-spread": "off",
139 "react-in-jsx-scope": "off",
140 "react-hooks/exhaustive-deps": "off",
141 "eslint/no-shadow": "off",
142 "eslint/no-await-in-loop": "off",
143 "eslint/no-underscore-dangle": "off",
144 "typescript/consistent-return": "off",
145 "typescript/no-base-to-string": "off",
146 "typescript/no-duplicate-type-constituents": "off",
147 "typescript/no-floating-promises": "off",
148 "typescript/no-implied-eval": "off",
149 "typescript/no-meaningless-void-operator": "off",
150 "typescript/no-redundant-type-constituents": "off",
151 "typescript/no-unnecessary-boolean-literal-compare": "off",
152 "typescript/no-unnecessary-type-conversion": "off",
153 "typescript/no-unnecessary-type-arguments": "off",
154 "typescript/no-unnecessary-type-assertion": "off",
155 "typescript/no-unnecessary-type-parameters": "off",
156 "typescript/no-unsafe-type-assertion": "off",
157 "typescript/await-thenable": "off",
158 "typescript/require-array-sort-compare": "off",
159 "typescript/restrict-template-expressions": "off",
160 "typescript/unbound-method": "off",
161 "eslint/no-restricted-imports": [
162 "error",
163 { paths: [...RESTRICTED_IMPORT_PATHS, RESTRICTED_PULL_REQUEST_GLYPH_IMPORTS] },
164 ],
165 "t3code/no-global-process-runtime": "error",
166 "t3code/no-inline-schema-compile": "warn",
167 "t3code/no-manual-effect-runtime-in-tests": "error",
168 "t3code/no-native-title-tooltip": "error",
169 "t3code/namespace-node-imports": "error",
170 },
171 overrides: [
172 {
173 // The one place that reads the host platform to seed the injected references.
174 files: ["packages/shared/src/hostProcess.ts"],
175 rules: { "t3code/no-global-process-runtime": "off" },
176 },
177 {
178 files: ["apps/web/src/**"],
179 excludeFiles: ["apps/web/src/components/ui/**"],
180 rules: {
181 "eslint/no-restricted-imports": [
182 "error",
183 {
184 paths: [...RESTRICTED_IMPORT_PATHS, RESTRICTED_PULL_REQUEST_GLYPH_IMPORTS],
185 patterns: RESTRICTED_UI_VARIANT_PATTERNS,
186 },
187 ],
188 },
189 },
190 {
191 // The one module allowed to name lucide's pull-request glyphs; everything else picks
192 // from its vocabulary. The other import restrictions still apply here.
193 files: ["apps/web/src/components/pullRequest/pullRequestIcons.tsx"],
194 rules: { "eslint/no-restricted-imports": ["error", { paths: RESTRICTED_IMPORT_PATHS }] },
195 },
196 {
197 files: ["apps/mobile/src/**"],
198 rules: { "t3code/no-mobile-uniwind-theme-escape-hatches": "error" },
199 },
200 {
201 // components/ui exports own their look. App code picks a variant or size instead
202 // of restyling with className; layout classes (width, flex, margin, position) stay
203 // allowed because placement belongs to the parent. components/ui is for generic
204 // primitives: a look that belongs to one feature stays in that feature's component.
205 files: ["apps/web/src/**"],
206 excludeFiles: ["apps/web/src/components/ui/**"],
207 rules: {
208 "shadcn/no-restyle": [
209 "error",
210 {
211 allow: ["layout"],
212 contracts: [
213 {
214 // CollapsibleTrigger is a bare button with no styled counterpart
215 // (a disclosure row is not a Button), so its className is the API.
216 // Every other trigger has one: style them with render={<Button …/>}.
217 pattern: "^CollapsibleTrigger$",
218 allow: ["layout", "color", "typography", "spacing", "shape", "effects", "motion"],
219 },
220 ],
221 },
222 ],
223 },
224 },
225 {
226 // Shared client code must not call APIs missing from Hermes. Our ESNext
227 // TypeScript target accepts them even when they would crash mobile at launch.
228 // Tests run on Node and are exempt.
229 files: [
230 "apps/mobile/src/**",
231 "packages/client-runtime/src/**",
232 "packages/contracts/src/**",
233 "packages/shared/src/**",
234 ],
235 excludeFiles: ["**/*.test.ts", "**/*.test.tsx"],
236 rules: { "t3code/no-hermes-unsupported-apis": "error" },
237 },
238 {
239 // Reviewed native and third-party interop boundaries that cannot consume a className.
240 files: [
241 "apps/mobile/src/features/archive/ArchivedThreadsScreen.tsx",
242 "apps/mobile/src/features/connection/ConnectionsNewRouteScreen.tsx",
243 "apps/mobile/src/features/files/FileMarkdownPreview.tsx",
244 "apps/mobile/src/features/files/SourceFileSurface.tsx",
245 "apps/mobile/src/features/files/AttachmentFileScreen.tsx",
246 "apps/mobile/src/features/files/ThreadFilesRouteScreen.tsx",
247 "apps/mobile/src/features/files/thread-file-navigator-pane.tsx",
248 "apps/mobile/src/features/home/HomeHeader.tsx",
249 "apps/mobile/src/features/review/ReviewSheet.tsx",
250 "apps/mobile/src/features/review/useNativeReviewDiffBridge.ts",
251 "apps/mobile/src/features/settings/SettingsEnvironmentsRouteScreen.tsx",
252 "apps/mobile/src/features/threads/GitActionProgressOverlay.tsx",
253 "apps/mobile/src/features/threads/NewTaskDraftScreen.tsx",
254 "apps/mobile/src/features/threads/ThreadComposer.tsx",
255 "apps/mobile/src/features/threads/ThreadFeed.tsx",
256 "apps/mobile/src/features/review/ReviewCommentCard.tsx",
257 "apps/mobile/src/features/threads/ThreadSettingsSheet.tsx",
258 "apps/mobile/src/features/threads/git/GitOverviewSheet.tsx",
259 "apps/mobile/src/features/threads/thread-list-items.tsx",
260 "apps/mobile/src/features/threads/thread-list-v2-items.tsx",
261 "apps/mobile/src/lib/useMobileNavigationTheme.ts",
262 "apps/mobile/src/native/T3ComposerEditor.ios.tsx",
263 "apps/mobile/src/native/T3ComposerEditor.native.tsx",
264 "apps/mobile/src/native/SelectableMarkdownText.android.tsx",
265 ],
266 rules: {
267 "t3code/no-mobile-uniwind-theme-escape-hatches": ["error", { allowUniwindTheme: true }],
268 },
269 },
270 // Legacy manual Effect runners tracked as debt: no net-new occurrences.
271 // Lower a ceiling when you migrate a file, and delete its entry at zero.
272 ...Object.entries({
273 "apps/server/src/orchestration/Layers/CheckpointReactor.test.ts": 42,
274 "apps/server/src/orchestration/Layers/OrchestrationEngine.test.ts": 5,
275 "apps/server/src/orchestration/Layers/OrchestrationReactor.test.ts": 4,
276 "apps/server/src/orchestration/Layers/ProviderCommandReactor.test.ts": 66,
277 "apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.test.ts": 29,
278 "apps/server/src/orchestration/Layers/ThreadDeletionReactor.test.ts": 2,
279 "apps/server/src/orchestration/commandInvariants.test.ts": 5,
280 "apps/server/src/orchestration/projector.test.ts": 20,
281 "apps/server/src/provider/Layers/CodexAdapter.test.ts": 1,
282 "apps/server/src/provider/Layers/CodexSessionRuntime.test.ts": 5,
283 "apps/server/src/provider/Layers/CursorAdapter.test.ts": 1,
284 "apps/server/src/provider/Layers/CursorProvider.test.ts": 1,
285 "apps/server/src/provider/Layers/ProviderService.test.ts": 2,
286 "apps/server/src/provider/Layers/ProviderSessionReaper.test.ts": 12,
287 "apps/server/src/provider/acp/CursorAcpSupport.test.ts": 1,
288 }).map(([file, maxOccurrences]) => {
289 const rule: ["error", { maxOccurrences: number }] = ["error", { maxOccurrences }];
290 return { files: [file], rules: { "t3code/no-manual-effect-runtime-in-tests": rule } };
291 }),
292 ],
293 options: {
294 reportUnusedDisableDirectives: "error",
295 // Revisit once Oxlint's tsgolint path can integrate with @effect/tsgo diagnostics.
296 typeAware: false,
297 typeCheck: false,
298 },
299 },
300});