Something went wrong. Try again.
opencode v2 mirror
Something went wrong. Try again.
1234567891011121314151617181920212223242526import { DiagnosticCategory, ModuleKind, ScriptTarget, flattenDiagnosticMessageText, transpileModule } from "typescript"
export interface TranspileResult { readonly outputText: string readonly error?: string}
// Full TypeScript transpilation on node/bun runtimes.export const transpile = (source: string): TranspileResult => { const transpiled = transpileModule(source, { reportDiagnostics: true, compilerOptions: { target: ScriptTarget.ESNext, module: ModuleKind.ESNext, }, }) const diagnostic = transpiled.diagnostics?.find((item) => item.category === DiagnosticCategory.Error) if (diagnostic) { return { outputText: transpiled.outputText, error: flattenDiagnosticMessageText(diagnostic.messageText, "\n"), } } return { outputText: transpiled.outputText }}