(ctx context.Context, options compiler.EmitOptions)
| 276 | } |
| 277 | |
| 278 | func (p *Program) emitBuildInfo(ctx context.Context, options compiler.EmitOptions) *compiler.EmitResult { |
| 279 | if tr := p.program.Tracing(); tr != nil { |
| 280 | defer tr.Push(tracing.PhaseEmit, "emitBuildInfo", nil, true)() |
| 281 | } |
| 282 | buildInfoFileName := outputpaths.GetBuildInfoFileName(p.snapshot.options, tspath.ComparePathsOptions{ |
| 283 | CurrentDirectory: p.program.GetCurrentDirectory(), |
| 284 | UseCaseSensitiveFileNames: p.program.UseCaseSensitiveFileNames(), |
| 285 | }) |
| 286 | if buildInfoFileName == "" || p.program.IsEmitBlocked(buildInfoFileName) { |
| 287 | return nil |
| 288 | } |
| 289 | if p.snapshot.hasErrors == core.TSUnknown { |
| 290 | p.ensureHasErrorsForState(ctx, p.program) |
| 291 | if p.snapshot.hasErrors != p.snapshot.hasErrorsFromOldState || p.snapshot.hasSemanticErrors != p.snapshot.hasSemanticErrorsFromOldState { |
| 292 | p.snapshot.buildInfoEmitPending.Store(true) |
| 293 | } |
| 294 | } |
| 295 | if p.snapshot.packageJsons == nil { |
| 296 | p.ensurePackageJsonsForState() |
| 297 | if !slices.Equal(p.snapshot.packageJsons, p.snapshot.packageJsonsFromOldState) || |
| 298 | !slices.Equal(p.snapshot.missingPackageJsons, p.snapshot.missingPackageJsonsFromOldState) { |
| 299 | p.snapshot.buildInfoEmitPending.Store(true) |
| 300 | } |
| 301 | } |
| 302 | if !p.snapshot.buildInfoEmitPending.Load() { |
| 303 | return nil |
| 304 | } |
| 305 | if ctx.Err() != nil { |
| 306 | return nil |
| 307 | } |
| 308 | buildInfo := snapshotToBuildInfo(p.snapshot, p.program, buildInfoFileName) |
| 309 | text, err := json.Marshal(buildInfo) |
| 310 | if err != nil { |
| 311 | panic(fmt.Sprintf("Failed to marshal build info: %v", err)) |
| 312 | } |
| 313 | if options.WriteFile != nil { |
| 314 | err = options.WriteFile(buildInfoFileName, string(text), &compiler.WriteFileData{ |
| 315 | BuildInfo: buildInfo, |
| 316 | }) |
| 317 | } else { |
| 318 | err = p.program.Host().FS().WriteFile(buildInfoFileName, string(text)) |
| 319 | } |
| 320 | if err != nil { |
| 321 | return &compiler.EmitResult{ |
| 322 | EmitSkipped: true, |
| 323 | Diagnostics: []*ast.Diagnostic{ |
| 324 | ast.NewCompilerDiagnostic(diagnostics.Could_not_write_file_0_Colon_1, buildInfoFileName, err.Error()), |
| 325 | }, |
| 326 | } |
| 327 | } |
| 328 | p.snapshot.buildInfoEmitPending.Store(false) |
| 329 | return &compiler.EmitResult{ |
| 330 | EmitSkipped: false, |
| 331 | EmittedFiles: []string{buildInfoFileName}, |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | func (p *Program) ensureHasErrorsForState(ctx context.Context, program *compiler.Program) { |
no test coverage detected