@@ -9,7 +9,7 @@ import * as ts from "typescript";
99import * as vm from "vm" ;
1010import * as tstl from "../src" ;
1111import { createEmitOutputCollector } from "../src/transpilation/output-collector" ;
12- import { getEmitOutDir , transpileProject } from "../src" ;
12+ import { EmitHost , getEmitOutDir , transpileProject } from "../src" ;
1313import { formatPathToLuaPath , normalizeSlashes } from "../src/utils" ;
1414
1515const jsonLib = fs . readFileSync ( path . join ( __dirname , "json.lua" ) , "utf8" ) ;
@@ -190,11 +190,22 @@ export abstract class TestBuilder {
190190 ) ;
191191 }
192192
193+ private getEmitHost ( ) : EmitHost {
194+ return {
195+ fileExists : ( path : string ) => normalizeSlashes ( path ) in this . extraFiles ,
196+ directoryExists : ( path : string ) =>
197+ Object . keys ( this . extraFiles ) . some ( f => f . startsWith ( normalizeSlashes ( path ) ) ) ,
198+ getCurrentDirectory : ( ) => "." ,
199+ readFile : ( path : string ) => this . extraFiles [ normalizeSlashes ( path ) ] ?? ts . sys . readFile ( path ) ,
200+ writeFile ( ) { } ,
201+ } ;
202+ }
203+
193204 @memoize
194205 public getLuaResult ( ) : tstl . TranspileVirtualProjectResult {
195206 const program = this . getProgram ( ) ;
196207 const collector = createEmitOutputCollector ( ) ;
197- const { diagnostics : transpileDiagnostics } = new tstl . Transpiler ( ) . emit ( {
208+ const { diagnostics : transpileDiagnostics } = new tstl . Transpiler ( { emitHost : this . getEmitHost ( ) } ) . emit ( {
198209 program,
199210 customTransformers : this . customTransformers ,
200211 writeFile : collector . writeFile ,
0 commit comments