(compiler: HybridCompiler, options: RunOptions)
| 52 | } |
| 53 | |
| 54 | export async function run(compiler: HybridCompiler, options: RunOptions): Promise<void> { |
| 55 | const {outDir = null, rootDir = '', tsconfigPath} = options; |
| 56 | const tracer = options.tracer ?? compiler.tracer; |
| 57 | const optimized = compiler.optimize && !compiler.emitDeclarationOnly; |
| 58 | const chunks = optimized ? compiler.analyzeOptimized() : compiler.analyze(); |
| 59 | const results = tracer.enabled ? timeEachNext(tracer, chunks) : chunks; |
| 60 | try { |
| 61 | for await (const chunk of results) { |
| 62 | // Pre-bind all files and analyze cycles in the chunk |
| 63 | const chunkContext = await compiler.prepareChunk(chunk); |
| 64 | |
| 65 | await Promise.all( |
| 66 | chunk.files.map((file) => |
| 67 | processFile(file, outDir, compiler, options, chunkContext, rootDir, tracer), |
| 68 | ), |
| 69 | ); |
| 70 | } |
| 71 | // Unconditional: even when the analyzer produced no chunks, option diagnostics (which don't |
| 72 | // depend on any file) still have to make it into the `.ngdiag.json`. |
| 73 | await tracer.sliceAsync(SpanKind.WriteDiagnostics, () => |
| 74 | writeDiagnosticsFile(compiler, tsconfigPath), |
| 75 | ); |
| 76 | } finally { |
| 77 | const {analyzer} = compiler; |
| 78 | if (tracer.enabled && analyzer.takePerf) { |
| 79 | try { |
| 80 | tracer.addAnalyzerPerf( |
| 81 | await tracer.sliceAsync(SpanKind.TakePerf, () => analyzer.takePerf!()), |
| 82 | ); |
| 83 | } catch { |
| 84 | // The sidecar may already have exited (e.g. after a fatal error). |
| 85 | } |
| 86 | } |
| 87 | if (!options.keepAnalyzerAlive) { |
| 88 | tracer.slice(SpanKind.Close, () => analyzer.close()); |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Records each wait on `source.next()` as an `AwaitAnalysis` slice. Nothing else runs on the |
no test coverage detected