(
program: ts.Program,
diagnostics: ts.Diagnostic[],
files: ProcessedFile[],
plugins: Plugin[]
)
| 108 | } |
| 109 | |
| 110 | protected getEmitPlan( |
| 111 | program: ts.Program, |
| 112 | diagnostics: ts.Diagnostic[], |
| 113 | files: ProcessedFile[], |
| 114 | plugins: Plugin[] |
| 115 | ): { emitPlan: EmitFile[] } { |
| 116 | performance.startSection("getEmitPlan"); |
| 117 | const options = program.getCompilerOptions() as CompilerOptions; |
| 118 | |
| 119 | if (options.tstlVerbose) { |
| 120 | console.log("Constructing emit plan"); |
| 121 | } |
| 122 | |
| 123 | // Resolve imported modules and modify output Lua requires |
| 124 | const resolutionResult = resolveDependencies(program, files, this.emitHost, plugins); |
| 125 | diagnostics.push(...resolutionResult.diagnostics); |
| 126 | |
| 127 | const lualibRequired = resolutionResult.resolvedFiles.some(f => f.fileName === "lualib_bundle"); |
| 128 | if (lualibRequired) { |
| 129 | // Remove lualib placeholders from resolution result |
| 130 | resolutionResult.resolvedFiles = resolutionResult.resolvedFiles.filter(f => f.fileName !== "lualib_bundle"); |
| 131 | |
| 132 | if (options.tstlVerbose) { |
| 133 | console.log("Including lualib bundle"); |
| 134 | } |
| 135 | // Add lualib bundle to source dir 'virtually', will be moved to correct output dir in emitPlan |
| 136 | const fileName = normalizeSlashes(path.resolve(getSourceDir(program), "lualib_bundle.lua")); |
| 137 | const code = this.getLuaLibBundleContent(options, resolutionResult.resolvedFiles); |
| 138 | resolutionResult.resolvedFiles.unshift({ fileName, code }); |
| 139 | } |
| 140 | |
| 141 | let emitPlan: EmitFile[]; |
| 142 | if (isBundleEnabled(options)) { |
| 143 | const [bundleDiagnostics, bundleFile] = getBundleResult(program, resolutionResult.resolvedFiles); |
| 144 | diagnostics.push(...bundleDiagnostics); |
| 145 | emitPlan = [bundleFile]; |
| 146 | } else { |
| 147 | const outputPathMap = new Map<string, string>(); |
| 148 | emitPlan = resolutionResult.resolvedFiles.map(file => { |
| 149 | const outputPath = getEmitPath(file.fileName, program); |
| 150 | const existing = outputPathMap.get(outputPath); |
| 151 | if (existing) { |
| 152 | diagnostics.push(emitPathCollision(outputPath, existing, file.fileName)); |
| 153 | } else { |
| 154 | outputPathMap.set(outputPath, file.fileName); |
| 155 | } |
| 156 | return { ...file, outputPath }; |
| 157 | }); |
| 158 | } |
| 159 | |
| 160 | performance.endSection("getEmitPlan"); |
| 161 | |
| 162 | return { emitPlan }; |
| 163 | } |
| 164 | |
| 165 | private getLuaLibBundleContent(options: CompilerOptions, resolvedFiles: ProcessedFile[]) { |
| 166 | const luaTarget = options.luaTarget ?? LuaTarget.Universal; |
no test coverage detected