From 4a0dc3c712d86cd6c93051acf3ce57901ccbb682 Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Tue, 5 Nov 2024 13:52:58 +0000 Subject: [PATCH] refactor(migrations): enable debug printing of compiler diagnostics (#58515) This is useful for some migrations and eases debugging, so we are building an environment-guarded debug print. PR Close #58515 --- .../schematics/utils/tsurge/helpers/ngtsc_program.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/core/schematics/utils/tsurge/helpers/ngtsc_program.ts b/packages/core/schematics/utils/tsurge/helpers/ngtsc_program.ts index dcd76d1b041..5fcaf4e71ce 100644 --- a/packages/core/schematics/utils/tsurge/helpers/ngtsc_program.ts +++ b/packages/core/schematics/utils/tsurge/helpers/ngtsc_program.ts @@ -16,6 +16,7 @@ import { } from '@angular/compiler-cli/src/ngtsc/file_system'; import {NgtscProgram} from '@angular/compiler-cli/src/ngtsc/program'; import {BaseProgramInfo} from '../program_info'; +import ts from 'typescript'; /** Code of the error raised by TypeScript when a tsconfig doesn't match any files. */ const NO_INPUTS_ERROR_CODE = 18003; @@ -54,12 +55,20 @@ export function createNgtscProgram( // Avoid checking libraries to speed up migrations. skipLibCheck: true, skipDefaultLibCheck: true, + noEmit: true, // Additional override options. ...optionOverrides, }, tsHost, ); + // Expose an easy way to debug-print ng semantic diagnostics. + if (process.env['DEBUG_NG_SEMANTIC_DIAGNOSTICS'] === '1') { + console.error( + ts.formatDiagnosticsWithColorAndContext(ngtscProgram.getNgSemanticDiagnostics(), tsHost), + ); + } + return { ngCompiler: ngtscProgram.compiler, program: ngtscProgram.getTsProgram(),