( file: AnalysisResult, outDir: string | null, compiler: HybridCompiler, options: RunOptions, chunkContext: ChunkContext, rootDir: string, tracer: Tracer, fileId: number, )
| 154 | } |
| 155 | |
| 156 | async function emitFile( |
| 157 | file: AnalysisResult, |
| 158 | outDir: string | null, |
| 159 | compiler: HybridCompiler, |
| 160 | options: RunOptions, |
| 161 | chunkContext: ChunkContext, |
| 162 | rootDir: string, |
| 163 | tracer: Tracer, |
| 164 | fileId: number, |
| 165 | ) { |
| 166 | const {filePath} = file; |
| 167 | const content = |
| 168 | compiler.fileCache.get(filePath)?.sourceContent ?? (await fs.readFile(filePath, 'utf-8')); |
| 169 | const processed = await compiler.processFile(filePath, content, file, chunkContext, fileId); |
| 170 | const s = processed.magicString; |
| 171 | |
| 172 | const writeOutput = outDir || options.inPlace; |
| 173 | const emitsTcb = compiler.optimize && !compiler.emitDeclarationOnly; |
| 174 | |
| 175 | if (options.inPlace && !outDir && !s.hasChanged() && !processed.tcb?.code) { |
| 176 | return; |
| 177 | } |
| 178 | |
| 179 | if (writeOutput) { |
| 180 | if (tracer.enabled && !s.hasChanged()) { |
| 181 | tracer.count(Counter.UnchangedFilesEmitted); |
| 182 | } |
| 183 | let outputPath: string; |
| 184 | let relativeSourcePath: string; |
| 185 | |
| 186 | if (outDir) { |
| 187 | const normalizedRoot = |
| 188 | process.platform === 'win32' || process.platform === 'darwin' |
| 189 | ? rootDir.toLowerCase() |
| 190 | : rootDir; |
| 191 | const normalizedFile = |
| 192 | process.platform === 'win32' || process.platform === 'darwin' |
| 193 | ? filePath.toLowerCase() |
| 194 | : filePath; |
| 195 | const relativePath = path.relative(normalizedRoot, normalizedFile); |
| 196 | outputPath = path.join(outDir, relativePath); |
| 197 | relativeSourcePath = relativePath; |
| 198 | } else { |
| 199 | outputPath = filePath.replace(/\.ts$/, '.ng.ts'); |
| 200 | relativeSourcePath = path.basename(filePath); |
| 201 | } |
| 202 | |
| 203 | const outputDir = path.dirname(outputPath); |
| 204 | const mapPath = outputPath + '.map'; |
| 205 | |
| 206 | if (outDir) { |
| 207 | await fs.mkdir(outputDir, {recursive: true}); |
| 208 | } |
| 209 | |
| 210 | const outputBase = path.basename(outputPath); |
| 211 | const mapCacheKey = `${relativeSourcePath}\0${outputBase}`; |
| 212 | let mapEntry = reusedSourceMapCache.get(processed); |
| 213 | if (!mapEntry || mapEntry.key !== mapCacheKey) { |
no test coverage detected