Skip to content
Permalink
Browse files

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
  • Loading branch information
alxhub committed Nov 16, 2019
1 parent 30ddadc commit d92da1335d04f1f79537523f952f58f4ee1ef695
Showing with 21 additions and 13 deletions.
  1. +21 −13 packages/compiler-cli/src/main.ts
@@ -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);

0 comments on commit d92da13

Please sign in to comment.
You can’t perform that action at this time.