Repository navigation
Expand file tree
/
Copy pathvite.config.ts
More file actions
359 lines (349 loc) · 15.3 KB
/
Copy pathvite.config.ts
File metadata and controls
359 lines (349 loc) · 15.3 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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
import path from "node:path";
import { defineConfig } from "vite-plus";
import { randomUUID } from "node:crypto";
import { createOgHarfbuzzPlugin } from "./packages/vinext/src/plugins/og-harfbuzz.js";
const SHIMS_SRC = path.resolve(import.meta.dirname, "packages/vinext/src/shims");
const VINEXT_SRC = path.resolve(import.meta.dirname, "packages/vinext/src");
const CLOUDFLARE_SRC = path.resolve(import.meta.dirname, "packages/cloudflare/src");
const MSW_SETUP = path.resolve(import.meta.dirname, "tests/_msw/setup.ts");
const FLIGHT_CODEC_SETUP = path.resolve(import.meta.dirname, "tests/_setup/flight-codec.ts");
// Resolve own-workspace sources directly in tests so the vinext <->
// @vinext/cloudflare dependency edge points at source (single module instance,
// no prior build required). Shared by both test projects below.
const WORKSPACE_SRC_ALIAS = {
"vinext/shims": SHIMS_SRC,
"vinext/internal": VINEXT_SRC,
"@vinext/cloudflare/internal": CLOUDFLARE_SRC,
"@vinext/cloudflare/cache": path.resolve(import.meta.dirname, "packages/cloudflare/src/cache"),
"@vinext/cloudflare/images": path.resolve(import.meta.dirname, "packages/cloudflare/src/images"),
};
export default defineConfig({
staged: {
"*": "vp check --fix",
},
fmt: {
printWidth: 100,
tabWidth: 2,
useTabs: false,
semi: true,
singleQuote: false,
trailingComma: "all",
ignorePatterns: [
// Kept byte-for-byte comparable with Sentry's upstream Next.js fixture.
"tests/e2e/sentry-nextjs-16-static/fixture/**",
"tests/fixtures/ecosystem/**",
// Ported from next-intl's playground; kept in upstream style for diffing.
"tests/fixtures/cf-next-intl/**",
"tests/e2e/cloudflare-next-intl/**",
"tests/fixtures/cf-next-intl-example/**",
"tests/e2e/cloudflare-next-intl-example/**",
"examples/**",
"packages/types/next/upstream/**",
],
},
lint: {
ignorePatterns: [
"fixtures/ecosystem/**",
// Kept byte-for-byte comparable with Sentry's upstream Next.js fixture.
"tests/e2e/sentry-nextjs-16-static/fixture/**",
"tests/fixtures/**",
"tests/fixtures/ecosystem/**",
"examples/**",
"packages/types/next/upstream/**",
],
options: {
typeAware: true,
typeCheck: true,
denyWarnings: true,
},
plugins: ["typescript", "unicorn", "import", "react"],
jsPlugins: [
"./oxlint-plugins/prefer-import-alias.ts",
"./oxlint-plugins/prefer-shared-utils.ts",
],
rules: {
"@typescript-eslint/no-explicit-any": "error",
"typescript/consistent-type-definitions": ["error", "type"],
"@typescript-eslint/no-unsafe-function-type": "error",
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/no-redeclare": "error",
"@typescript-eslint/no-implied-eval": "error",
"unicorn/prefer-node-protocol": "error",
"import/first": "error",
"import/no-duplicates": "error",
"no-new-func": "error",
"no-implied-eval": "error",
"arrow-body-style": ["error", "as-needed"],
"react/exhaustive-deps": "error",
"react/no-array-index-key": "error",
"react/rules-of-hooks": "error",
"react/self-closing-comp": "error",
"vinext-utils/prefer-shared-utils": "error",
},
overrides: [
{
files: ["**.spec.ts", "**.test.ts"],
rules: {
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unsafe-function-type": "off",
"typescript/no-misused-promises": "error",
"typescript/switch-exhaustiveness-check": "error",
"import/no-self-import": "error",
"unicorn/throw-new-error": "error",
"unicorn/error-message": "error",
},
},
{
files: ["packages/vinext/src/**/*.{ts,tsx}"],
rules: {
"typescript/no-misused-promises": "error",
"typescript/switch-exhaustiveness-check": "error",
"typescript/restrict-template-expressions": "error",
"import/no-self-import": "error",
"unicorn/throw-new-error": "error",
"unicorn/error-message": "error",
// Source path handling goes through pathslash so every join/resolve/
// relative emits canonical forward-slash output on Windows. Files
// that genuinely work in native-separator space (build/standalone.ts)
// disable this inline with a reason.
"no-restricted-imports": [
"error",
{
paths: [
{
name: "node:path",
message: 'Import path from "pathslash" instead (canonical forward-slash output).',
},
{
name: "path",
message: 'Import path from "pathslash" instead (canonical forward-slash output).',
},
],
},
],
},
},
{
// Forces relative imports of own-package files inside vinext to use
// the tsconfig path alias (e.g. ../shims/X.js → vinext/shims/X).
// Originally added for #1001 — bare specifiers keep
// @vitejs/plugin-rsc's `packageSources` map populated, which avoids
// the broken absolute-fs-path proxy fallback.
files: ["packages/vinext/**"],
rules: {
"vinext-local/prefer-import-alias": "error",
},
},
],
},
test: {
// GitHub Actions reporter adds inline failure annotations in PR diffs.
// Agent reporter suppresses passing test noise when running inside AI agents.
reporters: process.env.CI ? ["default", "github-actions"] : ["default", "agent"],
// Shared env for all projects.
env: {
// Mirrors the Vite `define` in index.ts that inlines a build-time UUID.
// Setting it here means tests exercise the same code path as production.
__VINEXT_DRAFT_SECRET: randomUUID(),
},
// Coverage activated only via --coverage flag (or CLI/config override).
// Istanbul provider is required because vinext source loads through Vite's
// module runner (helpers.ts:15 imports from packages/vinext/src directly,
// and integration tests start in-process Vite servers via createServer()).
// V8 coverage misses code under that runner.
coverage: {
provider: "istanbul",
include: ["packages/vinext/src/**/*.{ts,tsx}"],
exclude: ["**/*.d.ts", "**/*.test.ts", "**/*.spec.ts"],
reporter: ["text", "html", "json-summary", "lcov"],
reportsDirectory: "coverage",
clean: true,
skipFull: true,
// Always emit the report, even if some test files failed. A failing
// integration test (e.g. timing-sensitive teardown) shouldn't suppress
// coverage data we already collected.
reportOnFailure: true,
},
projects: [
{
plugins: [createOgHarfbuzzPlugin()],
resolve: {
alias: WORKSPACE_SRC_ALIAS,
},
test: {
name: "unit",
server: { deps: { inline: ["@vercel/og"] } },
setupFiles: [MSW_SETUP, FLIGHT_CODEC_SETUP],
// `scripts/**` covers the release-tooling unit tests
// (scripts/create-changeset.test.ts, scripts/version.test.ts), which
// are pure-logic and have no fixture/server dependencies.
include: ["tests/**/*.test.ts", "scripts/**/*.test.ts"],
exclude: [
"tests/**/node_modules/**",
"tests/e2e/**",
// Integration tests spin up Vite dev servers against shared fixture
// dirs and use per-worker optimizer caches in their own project.
// When adding a test that calls startFixtureServer() or createServer(),
// move it here.
"tests/app-router-client-preloading.test.ts",
"tests/app-router-deployment-id.test.ts",
"tests/app-router-dev-server.test.ts",
"tests/app-router-dev-externals.test.ts",
"tests/app-router-external-rewrite.test.ts",
"tests/app-router-font-google-prod.test.ts",
"tests/app-router-isr-codegen.test.ts",
"tests/app-router-malformed-url.test.ts",
"tests/app-router-metadata-routes.test.ts",
"tests/app-router-middleware-next-request.test.ts",
"tests/app-router-next-config-codegen.test.ts",
"tests/app-router-next-config-dev.test.ts",
"tests/app-router-origin-check.test.ts",
"tests/app-router-proxy-conventions.test.ts",
"tests/app-router-production-build.test.ts",
"tests/app-router-production-server.test.ts",
"tests/app-router-route-file-collision.test.ts",
"tests/app-router-rsc-flight-hint.test.ts",
"tests/app-router-rsc-plugin.test.ts",
"tests/app-router-static-export.test.ts",
"tests/app-router-worker-entry.test.ts",
"tests/app-search-params-gate-production.test.ts",
"tests/api-handler.test.ts",
"tests/cjs-globals-runtime.test.ts",
"tests/cjs.test.ts",
"tests/client-global-define.test.ts",
"tests/connection-probe-worker.test.ts",
"tests/dep-scan-bundled-deps.test.ts",
"tests/dev-route-discovery.test.ts",
"tests/dynamic-requests-build.test.ts",
"tests/ecosystem.test.ts",
"tests/entry-templates.test.ts",
"tests/esm-externals.test.ts",
"tests/features.test.ts",
"tests/favicon-short-circuit.test.ts",
"tests/hybrid-i18n-api-handoff.test.ts",
"tests/skip-trailing-slash-redirect.test.ts",
"tests/image-optimization-parity.test.ts",
"tests/instrumentation-dev.test.ts",
"tests/invalid-static-asset-404.test.ts",
"tests/middleware-matcher-auth.test.ts",
"tests/next-intl-cloudflare.test.ts",
"tests/node-modules-css.test.ts",
"tests/node-request-cancellation.test.ts",
"tests/optimize-deps-jsx-in-js.test.ts",
"tests/optimize-imports-integration.test.ts",
"tests/pages-i18n-prod.test.ts",
"tests/pages-isr-query-context.test.ts",
"tests/pages-router-concurrency.test.ts",
"tests/pages-router-nitro.test.ts",
"tests/pages-router.test.ts",
"tests/pages-server-only-use-server.test.ts",
"tests/process-browser-define.test.ts",
"tests/postcss-resolve.test.ts",
"tests/prerender.test.ts",
"tests/sass-tsconfig-paths.test.ts",
"tests/standalone-workspace-versions.test.ts",
"tests/static-export.test.ts",
"tests/tsconfig-path-alias-resolution.test.ts",
"tests/vite-hmr-websocket.test.ts",
"tests/nextjs-compat/**/*.test.ts",
// Flaky under parallelism due to 1 MiB buffer allocation pressure.
"tests/kv-cache-handler.test.ts",
],
},
},
{
plugins: [createOgHarfbuzzPlugin()],
resolve: {
alias: WORKSPACE_SRC_ALIAS,
},
test: {
name: "integration",
server: { deps: { inline: ["@vercel/og"] } },
env: {
VINEXT_PARALLEL_INTEGRATION: "true",
},
// MSW is intentionally NOT installed in the integration project.
// Integration tests spin up in-process HTTP servers and fixture
// dev servers and exercise them via `fetch("http://127.0.0.1:<port>/...")`.
// The @mswjs/interceptors layer interferes with that loopback
// traffic in subtle ways even when handlers `passthrough()`
// (e.g. 5xx response bodies stall, fixture-startup readiness
// probes time out). MSW's value here is mocking external HTTP
// for unit tests of fetch wrappers — integration tests already
// talk to real local servers, not to the network, so the
// unhandled-request guard buys little. If a future integration
// test needs to mock an external fetch, wire MSW per-file with
// `setupServer` rather than reverting this exclusion.
include: [
"tests/app-router-client-preloading.test.ts",
"tests/app-router-deployment-id.test.ts",
"tests/app-router-dev-server.test.ts",
"tests/app-router-dev-externals.test.ts",
"tests/app-router-external-rewrite.test.ts",
"tests/app-router-font-google-prod.test.ts",
"tests/app-router-isr-codegen.test.ts",
"tests/app-router-malformed-url.test.ts",
"tests/app-router-metadata-routes.test.ts",
"tests/app-router-middleware-next-request.test.ts",
"tests/app-router-next-config-codegen.test.ts",
"tests/app-router-next-config-dev.test.ts",
"tests/app-router-origin-check.test.ts",
"tests/app-router-proxy-conventions.test.ts",
"tests/app-router-production-build.test.ts",
"tests/app-router-production-server.test.ts",
"tests/app-router-route-file-collision.test.ts",
"tests/app-router-rsc-flight-hint.test.ts",
"tests/app-router-rsc-plugin.test.ts",
"tests/app-router-static-export.test.ts",
"tests/app-router-worker-entry.test.ts",
"tests/app-search-params-gate-production.test.ts",
"tests/api-handler.test.ts",
"tests/cjs-globals-runtime.test.ts",
"tests/cjs.test.ts",
"tests/client-global-define.test.ts",
"tests/connection-probe-worker.test.ts",
"tests/dep-scan-bundled-deps.test.ts",
"tests/dev-route-discovery.test.ts",
"tests/dynamic-requests-build.test.ts",
"tests/ecosystem.test.ts",
"tests/entry-templates.test.ts",
"tests/esm-externals.test.ts",
"tests/favicon-short-circuit.test.ts",
"tests/features.test.ts",
"tests/hybrid-i18n-api-handoff.test.ts",
"tests/skip-trailing-slash-redirect.test.ts",
"tests/image-optimization-parity.test.ts",
"tests/instrumentation-dev.test.ts",
"tests/invalid-static-asset-404.test.ts",
"tests/kv-cache-handler.test.ts",
"tests/middleware-matcher-auth.test.ts",
"tests/next-intl-cloudflare.test.ts",
"tests/node-modules-css.test.ts",
"tests/node-request-cancellation.test.ts",
"tests/optimize-deps-jsx-in-js.test.ts",
"tests/optimize-imports-integration.test.ts",
"tests/pages-i18n-prod.test.ts",
"tests/pages-isr-query-context.test.ts",
"tests/pages-router-concurrency.test.ts",
"tests/pages-router-nitro.test.ts",
"tests/pages-router.test.ts",
"tests/pages-server-only-use-server.test.ts",
"tests/process-browser-define.test.ts",
"tests/postcss-resolve.test.ts",
"tests/prerender.test.ts",
"tests/sass-tsconfig-paths.test.ts",
"tests/standalone-workspace-versions.test.ts",
"tests/static-export.test.ts",
"tests/tsconfig-path-alias-resolution.test.ts",
"tests/vite-hmr-websocket.test.ts",
"tests/nextjs-compat/**/*.test.ts",
],
testTimeout: 30000,
fileParallelism: true,
maxWorkers: 3,
sequence: { groupOrder: 1 },
},
},
],
},
});