Files
ECC/tests/fixtures/opencode-ts-loader.mjs
T
Yusuf Efeandhaelyra 0f34fdcc14 fix: resolve installed OpenCode skill paths consistently
Carry forward PR #3115 ef475c79 and 780dfb78 onto current main. Preserve the newer hook-consent transforms during install and repair. Main already includes the source import fix from #3167.
2026-10-09 15:40:12 -04:00

19 lines
654 B
JavaScript

import { readFile } from "node:fs/promises"
import ts from "typescript"
// Emulate OpenCode's in-place TypeScript loading without remapping missing
// .js specifiers to .ts files. Such remapping would hide issue #3112.
export async function load(url, context, nextLoad) {
if (!url.endsWith(".ts")) return nextLoad(url, context)
const source = await readFile(new URL(url), "utf8")
const result = ts.transpileModule(source, {
compilerOptions: {
target: ts.ScriptTarget.ES2022,
module: ts.ModuleKind.ESNext,
verbatimModuleSyntax: true,
},
})
return { format: "module", source: result.outputText, shortCircuit: true }
}