@@ -3,12 +3,12 @@ import { SourceNode } from "source-map";
33import * as ts from "typescript" ;
44import { couldNotFindBundleEntryPoint } from "./diagnostics" ;
55import { EmitHost , TranspiledFile } from "./Transpile" ;
6- import { formatPathToLuaPath , trimExtension } from "./utils" ;
6+ import { formatPathToLuaPath , trimExtension , normalizeSlashes } from "./utils" ;
77import { escapeString } from "./TSHelper" ;
88import { CompilerOptions } from "./CompilerOptions" ;
99
10- const formatPath = ( path : string ) => escapeString ( formatPathToLuaPath ( trimExtension ( path ) ) ) ;
11- const modulePath = ( baseDir : string , pathToResolve : string ) => formatPath ( path . relative ( baseDir , pathToResolve ) ) ;
10+ const createModulePath = ( baseDir : string , pathToResolve : string ) =>
11+ escapeString ( formatPathToLuaPath ( trimExtension ( path . relative ( baseDir , pathToResolve ) ) ) ) ;
1212
1313export function bundleTranspiledFiles (
1414 bundleFile : string ,
@@ -37,7 +37,7 @@ export function bundleTranspiledFiles(
3737
3838 // For each file: ["<module path>"] = function() <lua content> end,
3939 const moduleTableEntries : SourceChunk [ ] = transpiledFiles . map ( f =>
40- moduleSourceNode ( f , modulePath ( sourceRootDir , f . fileName ) )
40+ moduleSourceNode ( f , createModulePath ( sourceRootDir , f . fileName ) )
4141 ) ;
4242
4343 // If any of the modules contains a require for lualib_bundle, add it to the module table.
@@ -55,31 +55,34 @@ export function bundleTranspiledFiles(
5555local ____moduleCache = {}
5656local ____originalRequire = require
5757function require(file)
58- if ____moduleCache[file] then return ____moduleCache[file] end
58+ if ____moduleCache[file] then
59+ return ____moduleCache[file]
60+ end
5961 if ____modules[file] then
6062 ____moduleCache[file] = ____modules[file]()
6163 return ____moduleCache[file]
6264 else
63- print("Could not find module '"..file.."' to require.")
64- return ____originalRequire(file)
65+ if ____originalRequire then
66+ return ____originalRequire(file)
67+ else
68+ print("Could not find module '" .. file .. "' to require.")
69+ end
6570 end
6671end\n` ;
6772
6873 // return require("<entry module path>")
69- const entryPoint = `return require("${ modulePath ( sourceRootDir , resolvedEntryModule ) } ")\n` ;
74+ const entryPoint = `return require("${ createModulePath ( sourceRootDir , resolvedEntryModule ) } ")\n` ;
7075
7176 const bundleNode = joinSourceChunks ( [ moduleTable , requireOverride , entryPoint ] ) ;
7277 const { code, map } = bundleNode . toStringWithSourceMap ( ) ;
7378
7479 return [
7580 diagnostics ,
7681 {
77- fileName : resolvedBundleFile ,
82+ fileName : normalizeSlashes ( resolvedBundleFile ) ,
7883 lua : code ,
7984 sourceMap : map . toString ( ) ,
8085 sourceMapNode : moduleTable ,
81- declaration : undefined ,
82- declarationMap : undefined ,
8386 } ,
8487 ] ;
8588}
0 commit comments