// Node module hooks for running TypeScript tests with `node --test`: resolves the // "@/..." path alias (tsconfig "paths") to src/, adding the ".ts" extension that the // bundler normally infers. Registered by scripts/register-alias.mjs. const SRC = new URL("../src/", import.meta.url); export async function resolve(specifier, context, nextResolve) { if (specifier.startsWith("@/")) { const base = new URL(specifier.slice(2), SRC).href; for (const candidate of [base, `${base}.ts`, `${base}.tsx`, `${base}/index.ts`]) { try { return await nextResolve(candidate, context); } catch { // try the next candidate } } } return nextResolve(specifier, context); } // The bundler imports locale JSON (src/i18n) without `with { type: "json" }`; Node requires the // attribute, so add it here. This lets tests import modules that depend on @/i18n (e.g. @/lib/utils). export async function load(url, context, nextLoad) { if (url.endsWith(".json") && context.importAttributes?.type !== "json") { return nextLoad(url, { ...context, importAttributes: { ...context.importAttributes, type: "json" } }); } return nextLoad(url, context); }