fix(ivy): report watch mode diagnostics correctly (#33862)

This commit changes the reporting of watch mode diagnostics for ngtsc to use
the same formatting as non-watch mode diagnostics. This prints rich and
contextual errors even in watch mode, which previously was not the case.

Fixes #32213

PR Close #33862
This commit is contained in:
Alex Rickabaugh 2019-11-15 16:53:33 -08:00
parent 4be8929844
commit 97fbdab3b8
1 changed files with 21 additions and 13 deletions

View File

@ -223,28 +223,36 @@ function reportErrorsAndExit(
allDiagnostics: Diagnostics, options?: api.CompilerOptions,
consoleError: (s: string) => void = console.error): number {
const errorsAndWarnings = filterErrorsAndWarnings(allDiagnostics);
if (errorsAndWarnings.length) {
const formatHost = getFormatDiagnosticsHost(options);
if (options && options.enableIvy !== false) {
const ngDiagnostics = errorsAndWarnings.filter(api.isNgDiagnostic);
const tsDiagnostics = errorsAndWarnings.filter(api.isTsDiagnostic);
consoleError(replaceTsWithNgInErrors(
ts.formatDiagnosticsWithColorAndContext(tsDiagnostics, formatHost)));
consoleError(formatDiagnostics(ngDiagnostics, formatHost));
} else {
consoleError(formatDiagnostics(errorsAndWarnings, formatHost));
}
}
printDiagnostics(errorsAndWarnings, options, consoleError);
return exitCodeFromResult(allDiagnostics);
}
export function watchMode(
project: string, options: api.CompilerOptions, consoleError: (s: string) => void) {
return performWatchCompilation(createPerformWatchHost(project, diagnostics => {
consoleError(formatDiagnostics(diagnostics, getFormatDiagnosticsHost(options)));
printDiagnostics(diagnostics, options, consoleError);
}, options, options => createEmitCallback(options)));
}
function printDiagnostics(
diagnostics: ReadonlyArray<ts.Diagnostic|api.Diagnostic>,
options: api.CompilerOptions | undefined, consoleError: (s: string) => void): void {
if (diagnostics.length === 0) {
return;
}
const formatHost = getFormatDiagnosticsHost(options);
if (options && options.enableIvy !== false) {
const ngDiagnostics = diagnostics.filter(api.isNgDiagnostic);
const tsDiagnostics = diagnostics.filter(api.isTsDiagnostic);
consoleError(replaceTsWithNgInErrors(
ts.formatDiagnosticsWithColorAndContext(tsDiagnostics, formatHost)));
consoleError(formatDiagnostics(ngDiagnostics, formatHost));
} else {
consoleError(formatDiagnostics(diagnostics, formatHost));
}
}
// CLI entry point
if (require.main === module) {
const args = process.argv.slice(2);