import { fileURLToPath, URL } from "node:url"; import { defineConfig } from "vitest/config"; // The editor renderer is its own Vite app (root = apps/editor, own index.html). // The main process loads the built renderer from dist/renderer/ over a local // HTTP server (see src/main.ts), so no fs-shim middleware is needed here. // `@nengine/core` aliases to source for dev/test speed; E1 used core TYPES only, // E2 (map editing) also needs runtime `mapSchema`/`UNWALKABLE_TILES`. The full // core barrel is NOT browser-safe (loader/mods import node:fs) — E2–E4 import it // via two editor-only synthetic facets that alias core's PURE source modules // (schema/ and systems/ — no node builtins): `@nengine/core-schema` and // `@nengine/core-systems` (mirrored by "paths" in tsconfig.renderer.json). E5 // (playtest) brings the FULL `@nengine/core` barrel into the renderer and // neutralizes its node:fs/node:path/node:url imports with the dev-app-proven // in-memory shim aliases (src/shim/ — bundle mode performs ZERO fs calls at // runtime, D30/D36, so the stubs are never invoked). `@nengine/render` (PixiJS // viewport + connectLocal) is browser-safe and aliased to source like core. // The node shim aliases are scoped to non-test builds: vitest (mode "test") // runs in Node where the real `node:*` builtins must stay intact (tests use // mkdtemp/writeFile on real tmp dirs). export default defineConfig(({ mode }) => { const shimAliases: Record = mode === "test" ? {} : { "node:fs/promises": fileURLToPath(new URL("./src/shim/fs-promises.ts", import.meta.url)), "node:fs": fileURLToPath(new URL("./src/shim/fs.ts", import.meta.url)), "node:path": fileURLToPath(new URL("./src/shim/path.ts", import.meta.url)), "node:url": fileURLToPath(new URL("./src/shim/url.ts", import.meta.url)), }; return { root: fileURLToPath(new URL(".", import.meta.url)), resolve: { alias: { "@nengine/core": fileURLToPath(new URL("../../packages/core/src/index.ts", import.meta.url)), "@nengine/render": fileURLToPath(new URL("../../packages/render/src/index.ts", import.meta.url)), "@nengine/ui": fileURLToPath(new URL("../../packages/ui/src/index.ts", import.meta.url)), "@nengine/core-schema": fileURLToPath(new URL("../../packages/core/src/schema/index.ts", import.meta.url)), "@nengine/core-systems": fileURLToPath(new URL("../../packages/core/src/systems/index.ts", import.meta.url)), ...shimAliases, }, }, build: { outDir: "dist/renderer", emptyOutDir: true, rollupOptions: { input: fileURLToPath(new URL("./index.html", import.meta.url)), }, }, test: { include: ["test/**/*.test.ts"], environment: "node", testTimeout: 20000, }, }; });