Repository navigation
Expand file tree
/
Copy pathvite.config.ts
More file actions
398 lines (396 loc) · 14.9 KB
/
Copy pathvite.config.ts
File metadata and controls
398 lines (396 loc) · 14.9 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
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
import { defineConfig } from "vite-plus";
// Opt existing suites into the new conventions as they are migrated, rather
// than requiring unrelated legacy tests to change in this PR.
const componentTestFiles = [
"packages/react/src/components/SideMenu/**/*.browser.test.tsx",
"packages/core/src/blocks/Heading/Heading.browser.test.tsx",
"packages/react/src/components/FormattingToolbar/FormattingToolbar.browser.test.tsx",
"packages/react/src/components/FormattingToolbar/DesktopFormattingToolbarController.browser.test.tsx",
"packages/react/src/components/FormattingToolbar/DefaultButtons/BasicTextStyleButton.browser.test.tsx",
"packages/react/src/components/FormattingToolbar/DefaultButtons/ColorStyleButton.browser.test.tsx",
"packages/react/src/components/FormattingToolbar/DefaultButtons/CreateLinkButton.browser.test.tsx",
"packages/react/src/components/FormattingToolbar/DefaultButtons/NestBlockButtons.browser.test.tsx",
"packages/react/src/components/FormattingToolbar/DefaultButtons/TextAlignButton.browser.test.tsx",
"packages/react/src/components/FormattingToolbar/DefaultSelects/BlockTypeSelect.browser.test.tsx",
];
const testIdRestriction = {
property: "getByTestId",
message:
"Use accessible locators such as getByRole with a name or getByLabel in browser tests.",
};
const testSleepMessage =
"Wait for an observable condition (for example expect.element or expect.poll), not elapsed time. If testing timer behavior itself, document a targeted lint exception.";
const testSleepProperties = [
{ property: "waitForTimeout", message: testSleepMessage },
{ property: "setTimeout", message: testSleepMessage },
{ property: "sleep", message: testSleepMessage },
];
const browserTestImportPatterns = [
{
group: [
"**/utils/accessibility",
"**/utils/accessibility.*",
"**/utils/keyboard",
"**/utils/keyboard.*",
"**/screen-reader/screenReader",
"**/screen-reader/screenReader.*",
],
allowTypeImports: true,
message:
"Use the registered commands from tests/src/utils/context.ts instead of importing command implementations.",
},
{
group: ["timers", "timers/*", "node:timers", "node:timers/*"],
message: testSleepMessage,
},
];
export default defineConfig({
staged: {
// Format + fast lint (no type-aware) on pre-commit for speed.
// Full type-aware check runs in CI via `vp run lint`.
// Include the audit host even for CSS-only staged changes.
"*": "vp check --fix vite.config.ts",
},
run: {
// Cache package.json scripts by default (off by default in vp).
// Vite Task fingerprints files read by each build, including the upstream
// declarations TypeScript consumes. Exclude only task-owned outputs.
cache: { scripts: true },
tasks: {
// Docker owns image reuse. Always ask the daemon and execute browser runs:
// image state, installed browsers, and reports aren't task-cache inputs.
"e2e:image": {
command: "bash tests/docker-build.sh",
cache: false,
},
e2e: {
command:
"BLOCKNOTE_E2E_FULL=1 bash tests/docker-run.sh -e CI=1 -- --run",
cache: false,
},
"e2e:local": {
command: "vp test -c vite.config.browser.ts --mode browser-local --run",
cwd: "tests",
cache: false,
},
"e2e:updateSnaps": {
command: "bash tests/docker-run.sh -e CI=1 -- --run --update=true",
cache: false,
},
"e2e:report": {
command: "serve -l 4173 tests/playwright-report",
cache: false,
},
"test:screen-reader": {
command: "node tests/src/screen-reader/run-screen-reader.mjs",
cache: false,
},
"copy-package-readmes": {
command: "node scripts/copy-package-readmes.mjs",
// These copies are outputs, not inputs: automatic tracking of the
// destination checks would make a fresh checkout miss every time.
cache: {
input: ["README.md", "scripts/copy-package-readmes.mjs"],
output: ["packages/core/README.md", "packages/react/README.md"],
},
},
// The release script is interactive and produces only side-effects
// (git commit/tag/push, npm publish). It reads a stable file set
// (package.json files), so vp would fingerprint it as unchanged and
// replay stale cached stdout instead of running it. Always run fresh.
deploy: {
command: "node scripts/release.mjs",
cache: false,
},
},
},
// Workspace-level project list for tooling that discovers tests across the
// monorepo (e.g. the Vitest VSCode extension). Replaces the old
// `vitest.workspace.ts` — Vitest 4 dropped `defineWorkspace` in favour of
// declaring projects here. Each entry points at the package's
// `vite.config.ts`, which carries that package's own `test` block.
test: {
// Preserve Vitest 4 mock history during the toolchain upgrade.
clearMocks: false,
projects: [
"./packages/ariakit/vite.config.ts",
"./packages/code-block/vite.config.ts",
"./packages/core/vite.config.ts",
"./packages/diagram-block/vite.config.ts",
"./packages/mantine/vite.config.ts",
"./packages/math-block/vite.config.ts",
"./packages/react/vite.config.ts",
"./packages/server-util/vite.config.ts",
"./packages/shadcn/vite.config.ts",
"./packages/xl-ai/vite.config.ts",
"./packages/xl-ai-server/vite.config.ts",
"./packages/xl-docx-exporter/vite.config.ts",
"./packages/xl-email-exporter/vite.config.ts",
"./packages/xl-multi-column/vite.config.ts",
"./packages/xl-odt-exporter/vite.config.ts",
"./packages/xl-pdf-exporter/vite.config.ts",
"./packages/xl-typst-compiler/vite.config.ts",
"./packages/xl-typst-exporter/vite.config.ts",
"./tests/vite.config.ts",
"./tests/vite.config.browser.ts",
],
},
lint: {
plugins: ["typescript", "react", "import", "jsx-a11y"],
// ESLint compatibility rules and BlockNote-specific conventions.
jsPlugins: [
{ name: "import-eslint", specifier: "eslint-plugin-import" },
{
name: "blocknote-tests",
specifier: "./scripts/lint/component-browser-tests.mjs",
},
{ name: "blocknote", specifier: "./scripts/css-variable-plugin.mjs" },
{ name: "blocknote-dom", specifier: "./scripts/lint/detached-doc.mjs" },
],
options: {
typeAware: true,
typeCheck: true,
},
rules: {
// Enforce JSX accessibility correctness rules, with the exceptions below.
"jsx-a11y/alt-text": "error",
"jsx-a11y/anchor-has-content": "error",
"jsx-a11y/anchor-is-valid": "error",
"jsx-a11y/aria-activedescendant-has-tabindex": "error",
"jsx-a11y/aria-props": "error",
"jsx-a11y/aria-proptypes": "error",
"jsx-a11y/aria-role": "error",
"jsx-a11y/aria-unsupported-elements": "error",
"jsx-a11y/autocomplete-valid": "error",
"jsx-a11y/click-events-have-key-events": "error",
"jsx-a11y/control-has-associated-label": "error",
"jsx-a11y/heading-has-content": "error",
"jsx-a11y/html-has-lang": "error",
"jsx-a11y/iframe-has-title": "error",
"jsx-a11y/img-redundant-alt": "error",
"jsx-a11y/interactive-supports-focus": "error",
"jsx-a11y/label-has-associated-control": "error",
"jsx-a11y/lang": "error",
// Media comes from user content; static linting cannot enforce caption availability.
"jsx-a11y/media-has-caption": "off",
"jsx-a11y/mouse-events-have-key-events": "error",
"jsx-a11y/no-access-key": "error",
"jsx-a11y/no-aria-hidden-on-focusable": "error",
// Opening a popover or entering edit mode intentionally moves focus.
// Keyboard/focus tests verify these interactions.
"jsx-a11y/no-autofocus": "off",
"jsx-a11y/no-distracting-elements": "error",
"jsx-a11y/no-interactive-element-to-noninteractive-role": "error",
"jsx-a11y/no-noninteractive-element-interactions": "error",
"jsx-a11y/no-noninteractive-element-to-interactive-role": "error",
"jsx-a11y/no-noninteractive-tabindex": "error",
"jsx-a11y/no-redundant-roles": "error",
"jsx-a11y/no-static-element-interactions": "error",
// Custom widgets, live regions, and inline diagrams legitimately use ARIA
// roles. Keep the role/attribute validity checks enabled.
"jsx-a11y/prefer-tag-over-role": "off",
"jsx-a11y/role-has-required-aria-props": "error",
"jsx-a11y/role-supports-aria-props": "error",
"jsx-a11y/scope": "error",
"jsx-a11y/tabindex-no-positive": "error",
"blocknote/css-variable-layering": "error",
"blocknote-dom/no-realm-dependent-dom-instanceof": "error",
"no-console": "error",
curly: "warn",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/ban-ts-comment": "off",
"import-eslint/no-extraneous-dependencies": [
"error",
{
devDependencies: true,
peerDependencies: true,
optionalDependencies: false,
bundledDependencies: false,
},
],
"import-eslint/extensions": ["error", "always", { ignorePackages: true }],
// Native oxlint dependency cycle rule to replace previous ESLint rule.
// Disabled for now: there is a large set of known, pre-existing
// dependency cycles in core (hubbed around BlockNoteEditor/schema/api).
// Leaving this enabled (even at "warn") dumps a large volume of output
// that adds noise and can crash the git pre-commit hook while printing to
// stdout ("Resource temporarily unavailable"). All other (error-level)
// lint rules still run on staging via `vp check`.
// TODO: Refactor to break the cycles, then re-enable as an error.
"import/no-cycle": "off",
},
overrides: [
{
// Pilot on the component examples
files: componentTestFiles,
rules: {
"blocknote-tests/component-browser-structure": "error",
},
},
{
files: ["packages/*/src/**/*.{ts,tsx}"],
excludeFiles: ["**/*.test.{ts,tsx}"],
rules: {
"no-restricted-imports": [
"error",
{
patterns: [
{
group: ["**/*.test", "**/*.test.*"],
message: "Production code must not import test files.",
},
],
},
],
},
},
{
// Content from outside the editor: see scripts/lint/README.md.
files: ["packages/core/src/**/*.{ts,tsx}"],
excludeFiles: ["**/*.test.{ts,tsx}"],
rules: { "blocknote-dom/no-active-document": "error" },
},
{
files: [
"**/*.browser.test.{ts,tsx}",
"**/*.screen-reader.test.{ts,tsx}",
],
plugins: ["vitest"],
rules: {
// The plugin enables these defaults, which do not fit our test conventions.
// Assertions can live in shared helpers outside a test callback.
"vitest/expect-expect": "off",
"vitest/no-standalone-expect": "off",
// Browser-specific coverage and documented known failures are intentional.
"vitest/no-conditional-expect": "off",
"vitest/no-conditional-tests": "off",
"vitest/no-disabled-tests": "off",
// Existing mocks do not all provide explicit type parameters.
"vitest/require-mock-type-parameters": "off",
"vitest/no-focused-tests": "error",
"vitest/valid-expect": ["error", { maxArgs: 2 }],
"vitest/require-awaited-expect-poll": "error",
"typescript/no-floating-promises": [
"error",
{ ignoreVoid: false, checkThenables: true },
],
"no-restricted-imports": [
"error",
{
patterns: browserTestImportPatterns,
},
],
"no-restricted-properties": [
"error",
testIdRestriction,
{
property: "waitForTimeout",
message:
"Wait for observable readiness with expect.element or expect.poll instead of sleeping.",
},
{
property: "sleep",
message:
"Wait for observable readiness with expect.element or expect.poll instead of sleeping.",
},
],
},
},
{
files: componentTestFiles,
rules: {
"no-restricted-globals": [
"error",
{ name: "setTimeout", message: testSleepMessage },
],
"no-restricted-properties": [
"error",
...testSleepProperties,
testIdRestriction,
],
"no-restricted-imports": [
"error",
{
// Overrides replace rule options, so retain the shared safeguards.
patterns: [
...browserTestImportPatterns,
{
group: ["**/utils/editor.js", "**/utils/editor"],
importNames: ["sleep"],
message: testSleepMessage,
},
],
},
],
},
},
{
files: [
"**/scripts/**",
"**/*.mjs",
"docs/lib/**",
"docs/app/api/**",
"packages/dev-scripts/**",
"packages/xl-ai-server/**",
],
rules: {
"no-console": "off",
},
},
],
ignorePatterns: [
"**/dist/**",
"**/types/**",
"**/.next/**",
"**/build/**",
"**/coverage/**",
"**/__snapshots__/**",
"**/snapshots/**",
"**/node_modules/**",
"**/ui/**",
"**/.source/**",
// Non-library directories: skip all linting here.
// - docs/ and tests/nextjs-test-app/ need Next.js type generation
// (next-env.d.ts / .next) before they can be type-checked.
// - examples/ has 91 separate tsconfigs that each spin up a tsgolint
// instance, adding ~20s to the type-aware pass; it's demo code.
"docs/**",
"examples/**",
"playground/**",
"tests/nextjs-test-app/**",
"fumadocs/**",
],
},
fmt: {
semi: true,
singleQuote: false,
tabWidth: 2,
printWidth: 80,
trailingComma: "all",
bracketSpacing: true,
arrowParens: "always",
endOfLine: "lf",
sortTailwindcss: {},
sortPackageJson: false,
ignorePatterns: [
"**/dist/**",
"**/types/**",
"**/.next/**",
"**/build/**",
"**/coverage/**",
"**/__snapshots__/**",
"**/snapshots/**",
"**/*-snapshots/**",
"**/node_modules/**",
"**/.source/**",
"**/test-results/**",
"**/playwright-report/**",
"**/blob-report/**",
// Formatting captured clipboard HTML can change what the parser sees.
"packages/core/src/api/clipboard/fromClipboard/fixtures/*.html",
"**/*.mdx",
"pnpm-lock.yaml",
],
},
});