import { fileURLToPath } from "node:url"; import { defineConfig } from "vitest/config"; import react from "@vitejs/plugin-react"; // The binder splits into a pure headless core (bindings, active-state reducer, // rect-registry) that is node-safe, and a React surface (provider, form // renderer, overlay, registry hooks) exercised in a DOM. Tests whose filename // ends in `.dom.test.{ts,tsx}` run under happy-dom; everything else runs in // Node, which is faster. The react plugin lets the `.tsx` sources compile. // // The one runtime dependency, `@citation-evidence/engine`, resolves through its // package `exports` map (`.` and `./shared`) via the sibling-checkout link. The // engine ships raw TypeScript that uses its own `@shared/*` / `@engine/*` path // aliases internally; tsc honours those via tsconfig `paths`, but Vite does // not read tsconfig, so we mirror them here as resolve aliases. Nothing in this // package imports `citation-evidence` internals — the aliases only exist so the // linked engine source resolves. const enginePath = (rel: string) => fileURLToPath(new URL(`../citation-engine/src/${rel}`, import.meta.url)); export default defineConfig({ plugins: [react()], resolve: { alias: [ { find: /^@shared\//, replacement: `${enginePath("shared")}/` }, { find: /^@engine\//, replacement: `${enginePath("engine")}/` }, ], }, test: { environmentMatchGlobs: [["**/*.dom.test.{ts,tsx}", "happy-dom"]], globals: false, }, });