@@ -48,22 +48,30 @@ export function emitTranspiledFiles(
4848 }
4949 }
5050
51- if ( ! luaBundle && ( luaLibImport === LuaLibImportKind . Require || luaLibImport === LuaLibImportKind . Always ) ) {
52- if ( lualibContent === undefined ) {
53- const lualibBundle = emitHost . readFile ( path . resolve ( __dirname , "../dist/lualib/lualib_bundle.lua" ) ) ;
54- if ( lualibBundle !== undefined ) {
55- lualibContent = lualibBundle ;
56- } else {
57- throw new Error ( "Could not load lualib bundle from ./dist/lualib/lualib_bundle.lua" ) ;
51+ if (
52+ ! luaBundle &&
53+ ( luaLibImport === undefined ||
54+ luaLibImport === LuaLibImportKind . Require ||
55+ luaLibImport === LuaLibImportKind . Always )
56+ ) {
57+ const lualibRequired = files . some ( f => f . text && f . text . includes ( `require("lualib_bundle")` ) ) ;
58+ if ( lualibRequired ) {
59+ if ( lualibContent === undefined ) {
60+ const lualibBundle = emitHost . readFile ( path . resolve ( __dirname , "../dist/lualib/lualib_bundle.lua" ) ) ;
61+ if ( lualibBundle !== undefined ) {
62+ lualibContent = lualibBundle ;
63+ } else {
64+ throw new Error ( "Could not load lualib bundle from ./dist/lualib/lualib_bundle.lua" ) ;
65+ }
5866 }
59- }
6067
61- let outPath = path . resolve ( rootDir , "lualib_bundle.lua" ) ;
62- if ( outDir !== rootDir ) {
63- outPath = path . join ( outDir , path . relative ( rootDir , outPath ) ) ;
64- }
68+ let outPath = path . resolve ( rootDir , "lualib_bundle.lua" ) ;
69+ if ( outDir !== rootDir ) {
70+ outPath = path . join ( outDir , path . relative ( rootDir , outPath ) ) ;
71+ }
6572
66- files . push ( { name : normalizeSlashes ( outPath ) , text : lualibContent } ) ;
73+ files . push ( { name : normalizeSlashes ( outPath ) , text : lualibContent } ) ;
74+ }
6775 }
6876
6977 return files ;
0 commit comments