fix(ngcc): handle compilation diagnostics (#31996)
Previously, any diagnostics reported during the compilation of an entry-point would not be shown to the user, but either be ignored or cause a hard crash in case of a `FatalDiagnosticError`. This is unfortunate, as such error instances contain information on which code was responsible for producing the error, whereas only its error message would not. Therefore, it was quite hard to determine where the error originates from. This commit introduces behavior to deal with error diagnostics in a more graceful way. Such diagnostics will still cause the compilation to fail, however the error message now contains formatted diagnostics. Closes #31977 Resolves FW-1374 PR Close #31996
This commit is contained in:
@ -5,6 +5,8 @@
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {AbsoluteFsPath, FileSystem, absoluteFrom, dirname, getFileSystem, resolve} from '../../src/ngtsc/file_system';
|
||||
|
||||
import {CommonJsDependencyHost} from './dependencies/commonjs_dependency_host';
|
||||
@ -27,7 +29,6 @@ import {FileWriter} from './writing/file_writer';
|
||||
import {InPlaceFileWriter} from './writing/in_place_file_writer';
|
||||
import {NewEntryPointFileWriter} from './writing/new_entry_point_file_writer';
|
||||
|
||||
|
||||
/**
|
||||
* The options to configure the ngcc compiler.
|
||||
*/
|
||||
@ -171,8 +172,17 @@ export function mainNgcc(
|
||||
|
||||
logger.info(`Compiling ${entryPoint.name} : ${formatProperty} as ${format}`);
|
||||
|
||||
const transformedFiles = transformer.transform(bundle);
|
||||
fileWriter.writeBundle(bundle, transformedFiles, formatPropertiesToMarkAsProcessed);
|
||||
const result = transformer.transform(bundle);
|
||||
if (result.success) {
|
||||
if (result.diagnostics.length > 0) {
|
||||
logger.warn(ts.formatDiagnostics(result.diagnostics, bundle.src.host));
|
||||
}
|
||||
fileWriter.writeBundle(bundle, result.transformedFiles, formatPropertiesToMarkAsProcessed);
|
||||
} else {
|
||||
const errors = ts.formatDiagnostics(result.diagnostics, bundle.src.host);
|
||||
throw new Error(
|
||||
`Failed to compile entry-point ${entryPoint.name} due to compilation errors:\n${errors}`);
|
||||
}
|
||||
|
||||
onTaskCompleted(task, TaskProcessingOutcome.Processed);
|
||||
};
|
||||
|
Reference in New Issue
Block a user