MCPcopy Index your code
hub / github.com/microsoft/typescript-go / emitBuildInfo

Method emitBuildInfo

internal/execute/incremental/program.go:278–333  ·  view source on GitHub ↗
(ctx context.Context, options compiler.EmitOptions)

Source from the content-addressed store, hash-verified

276}
277
278func (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
335func (p *Program) ensureHasErrorsForState(ctx context.Context, program *compiler.Program) {

Callers 1

EmitMethod · 0.95

Calls 15

GetBuildInfoFileNameFunction · 0.92
MarshalFunction · 0.92
NewCompilerDiagnosticFunction · 0.92
snapshotToBuildInfoFunction · 0.85
panicFunction · 0.85
TracingMethod · 0.80
StoreMethod · 0.80
EqualMethod · 0.80
HostMethod · 0.80
GetCurrentDirectoryMethod · 0.65

Tested by

no test coverage detected