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
This commit is contained in:
Paul Gschwendtner 2024-11-05 13:52:58 +00:00 committed by Pawel Kozlowski
parent d4d76ead80
commit 4a0dc3c712

View file

@ -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(),