Repository navigation
Expand file tree
/
Copy pathvite.config.ts
More file actions
207 lines (198 loc) · 7.16 KB
/
Copy pathvite.config.ts
File metadata and controls
207 lines (198 loc) · 7.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
import { foldkit } from "@foldkit/vite-plugin";
import foldkitRecommended from "@foldkit/oxlint-plugin/recommended.json" with { type: "json" };
import effectRecommended from "@effect/tsgo/oxlint-presets/recommended.json" with { type: "json" };
import { defineConfig, type PluginOption } from "vite-plus";
const effectRules = Object.fromEntries(
Object.entries(effectRecommended.rules).map(
([name, severity]): readonly [string, "error" | "warn"] => [
name,
severity === "error" ? "error" : "warn",
],
),
);
const foldkitRules = Object.fromEntries(
Object.entries(foldkitRecommended.rules).map(
([name, severity]): readonly [string, "error" | "off"] => [
name,
severity === "error" ? "error" : "off",
],
),
);
const foldkitOff = Object.fromEntries(
Object.keys(foldkitRecommended.rules).map((name): readonly [string, "off"] => [name, "off"]),
);
/** Keep developer Git configuration out of subprocess-backed test results. */
const gitConfig = {
GIT_CONFIG_GLOBAL: "/dev/null",
GIT_CONFIG_NOSYSTEM: "1",
GIT_CONFIG_SYSTEM: "/dev/null",
};
const root = dirname(fileURLToPath(import.meta.url));
const ui = join(root, "src", "ui");
/**
* `@pierre/diffs` registers its web component from a file its exports map does
* not expose. Keep the workaround in one resolver until the package exports
* the side-effect entry itself.
*/
const diffsWebComponents = join(
dirname(fileURLToPath(import.meta.resolve("@pierre/diffs"))),
"components",
"web-components.js",
);
/**
* Foldkit's plugin, on the Vite the Vite+ toolchain already brings.
*
* One `vite@8.2.2` is installed and `@foldkit/vite-plugin` peers on
* `^7 || ^8`, so a single module registry runs the dev server and the build.
* `Sources.test.ts` asserts both, because a second copy would give the plugin
* a different registry from the one building: two HMR graphs in development,
* and a production build that silently drops the plugin's transform.
*
* SAFETY: the *types* are two declarations of that one runtime. Foldkit
* declares its plugins against the `vite` package's `Plugin`, and Vite+ ships
* its own `interface Plugin extends Rolldown.Plugin` inside
* `@voidzero-dev/vite-plus-core`. They describe the same objects, but each is
* large enough that asking the checker to relate them exhausts its
* instantiation depth rather than answering — so the equivalence is asserted
* once, here, at the only point where the two toolchains meet. The invariant
* behind it is the single installed Vite, which is checked in CI rather than
* assumed.
*/
const foldkitPlugins = foldkit() as PluginOption[];
export default defineConfig(({ mode }) => ({
appType: "custom",
base: "/hub/",
build: {
cssCodeSplit: false,
emptyOutDir: true,
minify: mode !== "development" ? "oxc" : false,
outDir: join(root, "dist", "ui"),
rolldownOptions: {
output: {
assetFileNames: (asset) =>
asset.names.some((name) => name.endsWith(".css")) ? "main.css" : "[name]-[hash][extname]",
chunkFileNames: "[name]-[hash].js",
entryFileNames: "main.js",
},
},
sourcemap: true,
target: "es2022",
},
define: {
"process.env.NODE_ENV": mode === "development" ? '"development"' : '"production"',
},
fmt: { ignorePatterns: [] },
lint: {
jsPlugins: [
{ name: "anti-slop", specifier: "./tools/oxlint/anti-slop/index.ts" },
{ name: "foldkit", specifier: "@foldkit/oxlint-plugin" },
],
options: { typeAware: true, typeCheck: true },
plugins: ["unicorn", "typescript", "oxc", "effecttsgo"],
overrides: [
// Foldkit's rules describe Model/Command/view discipline. They are
// noise on git, trust, artifacts and the Worker — those are not a
// Foldkit application. The UI's TEA surface is.
{
files: [
"src/ui/app.ts",
"src/ui/app.*.ts",
"src/ui/view.*.ts",
"src/ui/mount.*.ts",
"src/ui/element.*.ts",
"src/ui/main.ts",
],
rules: foldkitRules,
},
{
files: ["src/**/*.test.ts", "src/**/*.integration.ts"],
rules: { "typescript/no-floating-promises": "off", ...foldkitOff },
},
],
rules: {
...effectRules,
// Effect rule overrides
"effecttsgo/async-function": "off",
"effecttsgo/crypto-random-uuid": "off",
"effecttsgo/crypto-random-uuid-in-effect": "off",
"effecttsgo/global-console": "off",
"effecttsgo/global-console-in-effect": "off",
"effecttsgo/global-date": "off",
"effecttsgo/global-date-in-effect": "off",
"effecttsgo/global-fetch": "off",
"effecttsgo/global-fetch-in-effect": "off",
"effecttsgo/global-random": "off",
"effecttsgo/global-random-in-effect": "off",
"effecttsgo/global-timers": "off",
"effecttsgo/global-timers-in-effect": "off",
"effecttsgo/new-promise": "off",
"effecttsgo/node-builtin-import": "off",
"effecttsgo/prefer-schema-over-json": "off",
"effecttsgo/process-env": "off",
"effecttsgo/process-env-in-effect": "off",
// Anti-slop rules
"anti-slop/no-chained-type-assertions": "error",
"anti-slop/no-conditional-empty-object-spread": "error",
"anti-slop/no-known-value-widening": "error",
"anti-slop/no-module-mocking": "error",
"anti-slop/no-object-parameters": "error",
"anti-slop/no-reflect-apply": "error",
"anti-slop/no-reflect-get": "error",
"anti-slop/no-runtime-typeof": "error",
"anti-slop/no-shape-in-symbol-names": "error",
"anti-slop/no-unknown-parameters": "error",
"anti-slop/no-unknown-returns": "error",
"anti-slop/no-unknown-type-aliases": "error",
"anti-slop/no-unsafe-dictionary-type": "error",
"anti-slop/no-widen-then-assert": "error",
"anti-slop/require-safety-comment-for-type-assertion": "error",
},
},
plugins: foldkitPlugins,
resolve: {
alias: { "@pierre/diffs/components/web-components": diffsWebComponents },
},
// Test projects resolve `src/**` from the repository; the UI build resolves
// its HTML entry from `src/ui`.
root: mode === "test" ? root : ui,
test: {
env: gitConfig,
projects: [
{
test: {
// Real `git`, Chromium and a bundler all appear here. The suites
// run in parallel, so this is the allowance for a loaded machine.
exclude: ["src/**/*.interop.test.ts"],
env: gitConfig,
hookTimeout: 120_000,
include: ["src/**/*.test.ts"],
name: "unit",
testTimeout: 120_000,
},
},
{
test: {
// One workerd instance, shared by this file's tests.
env: gitConfig,
fileParallelism: false,
hookTimeout: 120_000,
include: ["src/**/*.integration.ts"],
name: "integration",
testTimeout: 120_000,
},
},
{
test: {
env: gitConfig,
fileParallelism: false,
hookTimeout: 120_000,
include: ["src/**/*.interop.test.ts"],
name: "interop",
testTimeout: 120_000,
},
},
],
},
}));