Something went wrong. Try again.
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546// Run the app's real TypeScript under plain Node, with no second implementation to drift.//// Two things stop `node src/lib/player/detect.ts` from working, and both are build-tool habits rather// than properties of the detector: the app's imports are extensionless (Vite resolves them), and// `trace.ts` reads `import.meta.env.DEV`, which only exists after Vite has replaced it. This hooks// Node's resolver to put the extension back, and its loader to give the one env object a value, and// nothing else about the code is touched.//// It matters that the harness imports the shipping module instead of reimplementing the search in// JavaScript: the whole point of the bake-off is that the same `search()` that arms a loop in the// browser is what scores each candidate representation. A reimplementation would be a second detector// whose agreement with the first would itself need calibrating — which is the trap `parity.mjs` had to// build an ONNX-vs-torch check to get out of.import { existsSync } from "node:fs";import { registerHooks } from "node:module";import { fileURLToPath } from "node:url";
registerHooks({ resolve(specifier, context, next) { if (specifier.startsWith(".") && !/\.[cm]?[jt]sx?$/.test(specifier)) { const base = new URL(specifier, context.parentURL); for (const candidate of [`${base.href}.ts`, `${base.href}.tsx`, `${base.href}/index.ts`]) { try { if (existsSync(fileURLToPath(new URL(candidate)))) return next(candidate, context); } catch { // Not a file URL, or not ours to resolve: leave it to the default. } } } return next(specifier, context); }, load(specifier, context, next) { const result = next(specifier, context); const source = result?.source; const text = typeof source === "string" ? source : source ? Buffer.from(source).toString("utf8") : ""; if (text.includes("import.meta.env")) { return { ...result, source: `import.meta.env ??= { DEV: true, PROD: false };\n${text}`, }; } return result; },});