@@ -79,7 +79,9 @@ import {
7979 NodeWatchFileSystemInterface ,
8080 NormalModuleFactoryRequest ,
8181} from './webpack' ;
82+ import { addError , addWarning } from './webpack-diagnostics' ;
8283import { createWebpackInputHost } from './webpack-input-host' ;
84+ import { isWebpackFiveOrHigher } from './webpack-version' ;
8385
8486export class AngularCompilerPlugin {
8587 private _options : AngularCompilerPluginOptions ;
@@ -117,8 +119,8 @@ export class AngularCompilerPlugin {
117119 private _firstRun = true ;
118120 private _donePromise : Promise < void > | null = null ;
119121 private _normalizedLocale : string | null = null ;
120- private _warnings : ( string | Error ) [ ] = [ ] ;
121- private _errors : ( string | Error ) [ ] = [ ] ;
122+ private _warnings : string [ ] = [ ] ;
123+ private _errors : string [ ] = [ ] ;
122124 private _contextElementDependencyConstructor ! : ContextElementDependencyConstructor ;
123125
124126 // TypeChecker process.
@@ -270,24 +272,22 @@ export class AngularCompilerPlugin {
270272 if ( this . _discoverLazyRoutes === false && this . options . additionalLazyModuleResources
271273 && this . options . additionalLazyModuleResources . length > 0 ) {
272274 this . _warnings . push (
273- new Error ( `Lazy route discovery is disabled but additional Lazy Module Resources were`
274- + ` provided. These will be ignored.` ) ,
275+ `Lazy route discovery is disabled but additional Lazy Module Resources were` +
276+ ` provided. These will be ignored.` ,
275277 ) ;
276278 }
277279
278280 if ( this . _compilerOptions . strictMetadataEmit ) {
279281 this . _warnings . push (
280- new Error (
281- `Using Angular compiler option 'strictMetadataEmit' for applications might cause undefined behavior.` ,
282- ) ,
282+ `Using Angular compiler option 'strictMetadataEmit' for applications might cause undefined behavior.` ,
283283 ) ;
284284 }
285285
286286 if ( this . _discoverLazyRoutes === false && this . options . additionalLazyModules
287287 && Object . keys ( this . options . additionalLazyModules ) . length > 0 ) {
288288 this . _warnings . push (
289- new Error ( `Lazy route discovery is disabled but additional lazy modules were provided.`
290- + `These will be ignored.` ) ,
289+ `Lazy route discovery is disabled but additional lazy modules were provided.` +
290+ `These will be ignored.` ,
291291 ) ;
292292 }
293293
@@ -544,9 +544,9 @@ export class AngularCompilerPlugin {
544544 if ( this . _lazyRoutes [ moduleKey ] !== modulePath ) {
545545 // Found a duplicate, this is an error.
546546 this . _warnings . push (
547- new Error ( `Duplicated path in loadChildren detected during a rebuild. `
548- + `We will take the latest version detected and override it to save rebuild time. `
549- + `You should perform a full build to validate that your routes don't overlap.` ) ,
547+ `Duplicated path in loadChildren detected during a rebuild. ` +
548+ `We will take the latest version detected and override it to save rebuild time. ` +
549+ `You should perform a full build to validate that your routes don't overlap.` ,
550550 ) ;
551551 }
552552 } else {
@@ -679,9 +679,10 @@ export class AngularCompilerPlugin {
679679 // Anything that remains is unused, because it wasn't referenced directly or transitively
680680 // on the files in the compilation.
681681 for ( const fileName of unusedSourceFileNames ) {
682- compilation . warnings . push (
682+ addWarning (
683+ compilation ,
683684 `${ fileName } is part of the TypeScript compilation but it's unused.\n` +
684- `Add only entry points to the 'files' or 'include' properties in your tsconfig.` ,
685+ `Add only entry points to the 'files' or 'include' properties in your tsconfig.` ,
685686 ) ;
686687 this . _unusedFiles . add ( fileName ) ;
687688 // Remove the truly unused from the type dep list.
@@ -965,7 +966,9 @@ export class AngularCompilerPlugin {
965966 }
966967 }
967968
968- return request ;
969+ if ( ! isWebpackFiveOrHigher ( ) ) {
970+ return request ;
971+ }
969972 } ,
970973 ) ;
971974 } ) ;
@@ -1010,16 +1013,16 @@ export class AngularCompilerPlugin {
10101013 await this . _update ( ) ;
10111014 this . pushCompilationErrors ( compilation ) ;
10121015 } catch ( err ) {
1013- compilation . errors . push ( err ) ;
1016+ addError ( compilation , err . message || err ) ;
10141017 this . pushCompilationErrors ( compilation ) ;
10151018 }
10161019
10171020 timeEnd ( 'AngularCompilerPlugin._make' ) ;
10181021 }
10191022
10201023 private pushCompilationErrors ( compilation : compilation . Compilation ) {
1021- compilation . errors . push ( ... this . _errors ) ;
1022- compilation . warnings . push ( ... this . _warnings ) ;
1024+ this . _errors . forEach ( ( error ) => addError ( compilation , error ) ) ;
1025+ this . _warnings . forEach ( ( warning ) => addWarning ( compilation , warning ) ) ;
10231026 this . _errors = [ ] ;
10241027 this . _warnings = [ ] ;
10251028 }
@@ -1160,7 +1163,7 @@ export class AngularCompilerPlugin {
11601163 // Report any diagnostics.
11611164 reportDiagnostics (
11621165 diagnostics ,
1163- msg => this . _errors . push ( new Error ( msg ) ) ,
1166+ msg => this . _errors . push ( msg ) ,
11641167 msg => this . _warnings . push ( msg ) ,
11651168 ) ;
11661169
0 commit comments