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:
@ -406,6 +406,41 @@ runInEachFileSystem(() => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('diagnostics', () => {
|
||||
it('should fail with formatted diagnostics when an error diagnostic is produced', () => {
|
||||
loadTestFiles([
|
||||
{
|
||||
name: _('/node_modules/fatal-error/package.json'),
|
||||
contents: '{"name": "fatal-error", "es2015": "./index.js", "typings": "./index.d.ts"}',
|
||||
},
|
||||
{name: _('/node_modules/fatal-error/index.metadata.json'), contents: 'DUMMY DATA'},
|
||||
{
|
||||
name: _('/node_modules/fatal-error/index.js'),
|
||||
contents: `
|
||||
import {Component} from '@angular/core';
|
||||
export class FatalError {}
|
||||
FatalError.decorators = [
|
||||
{type: Component, args: [{selector: 'fatal-error'}]}
|
||||
];
|
||||
`,
|
||||
},
|
||||
{
|
||||
name: _('/node_modules/fatal-error/index.d.ts'),
|
||||
contents: `
|
||||
export declare class FatalError {}
|
||||
`,
|
||||
},
|
||||
]);
|
||||
expect(() => mainNgcc({
|
||||
basePath: '/node_modules',
|
||||
targetEntryPointPath: 'fatal-error',
|
||||
propertiesToConsider: ['es2015']
|
||||
}))
|
||||
.toThrowError(
|
||||
/^Failed to compile entry-point fatal-error due to compilation errors:\nnode_modules\/fatal-error\/index\.js\(5,17\): error TS-992001: component is missing a template\r?\n$/);
|
||||
});
|
||||
});
|
||||
|
||||
describe('logger', () => {
|
||||
it('should log info message to the console by default', () => {
|
||||
const consoleInfoSpy = spyOn(console, 'info');
|
||||
|
Reference in New Issue
Block a user