SOURCE / PINNED RELEASE
Made of little things.
Browser Side Quest
- Release
- b9d42f5768e4…
- Author-recorded commit
- c267690145fa…
- License
- LICENSE
- Author’s source reference
- nostr://npub1ye5ptcxfyyxl5vjvdjar2ua3f0hynkjzpx552mu5snj3qmx5pzjscpknpr/wss%3A%2F%2Fgit.shakespeare.diy%2F/browser-side-quest
Archive hash verified: 6d4b90b8a5f328f7…. The source-to-build association is the author’s claim; it has not been independently rebuilt.
// Node module hooks so tests can import the TypeScript sim directly:
// map './x.js' to './x.ts' when only the .ts exists, and transpile .ts with the
// project's TypeScript (no type checking; `pnpm type-check` covers that).
import { existsSync } from 'node:fs';
import { readFile } from 'node:fs/promises';
import { fileURLToPath } from 'node:url';
import ts from 'typescript';
export async function resolve(specifier, context, nextResolve) {
if (specifier.endsWith('.js') && context.parentURL?.startsWith('file:') && (specifier.startsWith('.') || specifier.startsWith('/'))) {
const tsUrl = new URL(specifier.replace(/\.js$/, '.ts'), context.parentURL);
if (existsSync(fileURLToPath(tsUrl))) return { url: tsUrl.href, shortCircuit: true };
}
return nextResolve(specifier, context);
}
export async function load(url, context, nextLoad) {
if (url.endsWith('.ts')) {
const source = await readFile(fileURLToPath(url), 'utf8');
const { outputText } = ts.transpileModule(source, {
compilerOptions: { module: ts.ModuleKind.ESNext, target: ts.ScriptTarget.ES2022, verbatimModuleSyntax: true },
fileName: fileURLToPath(url),
});
return { format: 'module', source: outputText, shortCircuit: true };
}
return nextLoad(url, context);
}
