MCPcopy Index your code
hub / github.com/TypeScriptToLua/TypeScriptToLua / requireOverride

Function requireOverride

src/transpilation/bundle.ts:15–43  ·  view source on GitHub ↗
(options: CompilerOptions)

Source from the content-addressed store, hash-verified

13
14// Override `require` to read from ____modules table.
15function requireOverride(options: CompilerOptions) {
16 const runModule =
17 options.luaTarget === LuaTarget.Lua50
18 ? "if (table.getn(arg) > 0) then value = module(unpack(arg)) else value = module(file) end"
19 : 'if (select("#", ...) > 0) then value = module(...) else value = module(file) end';
20 return `
21local ____modules = {}
22local ____moduleCache = {}
23local ____originalRequire = require
24local function require(file, ...)
25 if ____moduleCache[file] then
26 return ____moduleCache[file].value
27 end
28 if ____modules[file] then
29 local module = ____modules[file]
30 local value = nil
31 ${runModule}
32 ____moduleCache[file] = { value = value }
33 return value
34 else
35 if ____originalRequire then
36 return ____originalRequire(file)
37 else
38 error("module '" .. file .. "' not found")
39 end
40 end
41end
42`;
43}
44
45export const sourceMapTracebackBundlePlaceholder = "{#SourceMapTracebackBundle}";
46

Callers 1

getBundleResultFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected