Repository navigation
Expand file tree
/
Copy pathvite.config.ts
More file actions
308 lines (303 loc) · 8.4 KB
/
Copy pathvite.config.ts
File metadata and controls
308 lines (303 loc) · 8.4 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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
import * as path from "node:path";
import fs from "node:fs";
import { fileURLToPath } from "node:url";
import { createGenerator } from "ts-json-schema-generator";
import { defineConfig } from "vite-plus";
import { ALL_HELPER_NAMES, RUNTIME_SOURCE } from "./src/unplugin/virtual.js";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
/**
* Ships the lean-mode runtime as a real module at `dist/runtime.js`.
*
* Lean-mode output imports its shared helpers from one module so a bundle holds
* one copy. Hosts with resolve hooks answer that import from memory, but a
* webpack loader (Turbopack) has none — for it the specifier has to resolve as
* an ordinary package subpath, which means a file on disk.
*
* Emitted rather than committed: the source comes from the same decl registries
* inline mode emits, so there is one producer and no second copy to drift. It
* has to land during the build, not after, because publint checks every
* `exports` target before the build finishes. A one-shot build is the only thing
* this covers — `vp pack --watch` reuses the source captured when the config was
* evaluated, so a registry edit needs a full rebuild to reach dist.
*/
function emitRuntimeModule() {
const declarations = [
"// Generated at build time from zod-compiler's helper registries.",
"// Imported by lean-mode generated code, never written by hand — `any`",
"// because a caller would otherwise have to cast every helper to call it.",
...ALL_HELPER_NAMES.map((name) => `export declare const ${name}: any;`),
].join("\n");
return {
name: "zod-compiler:emit-runtime",
generateBundle(this: { emitFile: (file: Record<string, string>) => void }) {
this.emitFile({ type: "asset", fileName: "runtime.js", source: `${RUNTIME_SOURCE}\n` });
this.emitFile({ type: "asset", fileName: "runtime.d.ts", source: `${declarations}\n` });
},
};
}
/** Keep the editor schema in lockstep with the register config type on every package build. */
function generateRegisterSchema() {
return {
name: "zod-compiler:generate-register-schema",
buildStart() {
const schema = createGenerator({
path: path.resolve(__dirname, "src/register/config.ts"),
tsconfig: path.resolve(__dirname, "tsconfig.json"),
type: "ZodCompilerRegisterConfig",
topRef: false,
}).createSchema("ZodCompilerRegisterConfig");
fs.writeFileSync(
path.resolve(__dirname, "schema.json"),
`${JSON.stringify(schema, null, 2)}\n`,
);
},
};
}
export default defineConfig({
resolve: {
conditions: ["source"],
// Explicit alias: the test pipeline does not reliably honor custom
// conditions for `#`-subpath imports, and the package-imports fallback
// would resolve #src through a (possibly stale) dist build.
alias: {
"#src": path.resolve(__dirname, "src"),
},
},
test: {
include: ["tests/**/*.test.ts"],
coverage: {
provider: "v8",
},
server: {
deps: {
inline: ["zod"],
},
},
},
pack: {
entry: ["src/**/*.ts"],
plugins: [generateRegisterSchema(), emitRuntimeModule()],
format: ["esm"],
unbundle: true,
sourcemap: true,
dts: {
sourcemap: true,
},
fixedExtension: false,
target: "es2022",
deps: {
neverBundle: true,
},
logLevel: "warn",
publint: true,
report: false,
},
run: {
tasks: {
ci: {
command: ["vp pack", "vp check", "knip", "vp test"],
input: [
{ auto: true },
"!.tmp/**",
"!.vite-hooks",
"!.vite-hooks/**",
"!coverage",
"!coverage/**",
"!node_modules/.cache/**",
"!node_modules/.modules.yaml",
"!node_modules/.vite/vitest",
"!node_modules/.vite/vitest/**",
"!**/.next",
"!**/.next/**",
"!tests/fixtures/.*",
"!tests/fixtures/.*/**",
"!tests/fixtures/__*",
"!tests/fixtures/__*/**",
],
output: [
{ auto: true },
"!.tmp/**",
"!.vite-hooks",
"!.vite-hooks/**",
"!coverage",
"!coverage/**",
"!node_modules/.cache/**",
"!node_modules/.modules.yaml",
"!node_modules/.vite/vitest",
"!node_modules/.vite/vitest/**",
"!**/.next",
"!**/.next/**",
"!tests/fixtures/.*",
"!tests/fixtures/.*/**",
"!tests/fixtures/__*",
"!tests/fixtures/__*/**",
],
},
},
},
staged: {
"*": "vp check --fix",
},
fmt: {
useTabs: false,
tabWidth: 2,
printWidth: 100,
singleQuote: false,
jsxSingleQuote: false,
quoteProps: "as-needed",
trailingComma: "all",
semi: true,
arrowParens: "always",
bracketSameLine: false,
bracketSpacing: true,
ignorePatterns: [
"node_modules",
"dist",
"**/dist",
"coverage",
"schema.json",
"*.compiled.ts",
"*.compiled.js",
".agents",
".claude",
"**/.next",
],
},
lint: {
plugins: ["import", "typescript", "unicorn", "oxc", "promise"],
categories: {
correctness: "error",
},
rules: {
"no-unused-vars": "error",
"no-undef": "off",
"typescript/no-explicit-any": "error",
"no-empty": "error",
"no-console": "warn",
"no-var": "error",
"import/no-cycle": "warn",
"prefer-const": "error",
"typescript/consistent-type-imports": [
"error",
{
disallowTypeAnnotations: false,
},
],
"no-param-reassign": "error",
"typescript/no-non-null-assertion": "warn",
"typescript/no-namespace": "error",
"no-else-return": "warn",
"typescript/prefer-as-const": "error",
"unicorn/no-static-only-class": "warn",
"typescript/no-useless-empty-export": "error",
"typescript/no-floating-promises": "error",
"typescript/no-misused-promises": "error",
"typescript/no-implied-eval": "off",
"vite-plus/prefer-vite-plus-imports": "error",
},
overrides: [
{
files: ["src/**", "tests/**"],
rules: {
"import/no-nodejs-modules": "error",
},
},
{
files: [
"src/cli/**",
"src/loader.ts",
"src/register/**",
"src/swc.ts",
"src/turbopack.ts",
"src/static-filter.ts",
"tests/cli/**",
"tests/discovery.test.ts",
"tests/loader.test.ts",
"tests/register.test.ts",
"tests/swc.test.ts",
"tests/turbopack.test.ts",
"src/unplugin/**",
"tests/unplugin/**",
"tests/zod-version.ts",
],
rules: {
"import/no-nodejs-modules": "off",
},
},
{
files: ["src/core/**"],
rules: {
"no-restricted-imports": [
"error",
{
patterns: [
{
group: ["#src/cli/**", "#src/unplugin/**", "#src/discovery.*", "#src/loader.*"],
message: "core/ must not depend on cli/, unplugin/, discovery, or loader",
},
],
},
],
},
},
{
files: ["src/cli/**"],
rules: {
"no-restricted-imports": [
"error",
{
patterns: [
{
group: ["#src/unplugin/**"],
message: "cli/ must not depend on unplugin/",
},
],
},
],
},
},
{
files: ["src/unplugin/**"],
rules: {
"no-restricted-imports": [
"error",
{
patterns: [
{
group: ["#src/cli/**"],
message: "unplugin/ must not depend on cli/",
},
],
},
],
},
},
{
files: ["apps/hono/**"],
globals: {
Bun: "readonly",
},
},
],
ignorePatterns: [
"node_modules",
"dist",
"**/dist",
"**/*.compiled.ts",
"**/*.compiled.js",
"**/.next",
"smoke/node_modules",
"tests/fixtures",
],
options: {
typeAware: true,
typeCheck: true,
},
jsPlugins: [
{
name: "vite-plus",
specifier: "vite-plus/oxlint-plugin",
},
],
},
});