@@ -18,7 +18,8 @@ import {
1818 isImport ,
1919 isRequire ,
2020} from "./util" ;
21- import { createDiagnosticFactoryWithCode } from "../utils" ;
21+ import { createDiagnosticFactoryWithCode , normalizeSlashes } from "../utils" ;
22+ import type { CompilerOptions } from ".." ;
2223
2324export const lualibDiagnostic = createDiagnosticFactoryWithCode ( 200000 , ( message : string , file ?: ts . SourceFile ) => ( {
2425 messageText : message ,
@@ -168,6 +169,27 @@ class LuaLibPlugin implements tstl.Plugin {
168169 }
169170 return { result : result as LuaLibModulesInfo , diagnostics } ;
170171 }
172+
173+ public moduleResolution (
174+ moduleIdentifier : string ,
175+ requiringFile : string ,
176+ _options : CompilerOptions ,
177+ emitHost : EmitHost
178+ ) : string | undefined {
179+ const tstlRoot = path . resolve ( __dirname , "../.." ) ;
180+ const relativeRequiringFile = normalizeSlashes ( path . relative ( tstlRoot , requiringFile ) ) ;
181+ if ( ! relativeRequiringFile . startsWith ( "src/lualib/" ) ) {
182+ return ;
183+ }
184+
185+ const tryingPaths = [ "./" , "./universal/" ] ;
186+ for ( const tryingPath of tryingPaths ) {
187+ const possiblePath = path . join ( tstlRoot , "src" , "lualib" , tryingPath , `${ moduleIdentifier } .ts` ) ;
188+ if ( emitHost . fileExists ( possiblePath ) ) {
189+ return possiblePath ;
190+ }
191+ }
192+ }
171193}
172194
173195class LuaLibPrinter extends tstl . LuaPrinter {
0 commit comments