/* * glyph-raw-loader.mjs — the Node-side twin of Vite's `?raw` import suffix. * ---------------------------------------------------------------------------- * glyphs.ts imports the committed SVGs with Vite's `?raw` (the single-source * law). Plain Node cannot load .svg modules, so the guidance-surface suite * registers this `load` hook (node:module register) before its dynamic * imports: any specifier ending in `?raw` resolves to the real file on disk * and exports its text as the module default — byte-identical to what Vite * ships, so the tests exercise the SAME glyph strings the app renders. * The hook only intercepts `?raw` specifiers; every other import falls * through to the default loader (type stripping included). */ import { readFileSync } from "node:fs"; import { fileURLToPath } from "node:url"; export async function load(url, context, nextLoad) { if (url.endsWith("?raw")) { const content = readFileSync(fileURLToPath(new URL(url)), "utf8"); return { format: "module", source: `export default ${JSON.stringify(content)};\n`, shortCircuit: true, }; } return nextLoad(url, context); }