@@ -79,7 +79,9 @@ import {
79
79
NodeWatchFileSystemInterface ,
80
80
NormalModuleFactoryRequest ,
81
81
} from './webpack' ;
82
+ import { addError , addWarning } from './webpack-diagnostics' ;
82
83
import { createWebpackInputHost } from './webpack-input-host' ;
84
+ import { isWebpackFiveOrHigher } from './webpack-version' ;
83
85
84
86
export class AngularCompilerPlugin {
85
87
private _options : AngularCompilerPluginOptions ;
@@ -117,8 +119,8 @@ export class AngularCompilerPlugin {
117
119
private _firstRun = true ;
118
120
private _donePromise : Promise < void > | null = null ;
119
121
private _normalizedLocale : string | null = null ;
120
- private _warnings : ( string | Error ) [ ] = [ ] ;
121
- private _errors : ( string | Error ) [ ] = [ ] ;
122
+ private _warnings : string [ ] = [ ] ;
123
+ private _errors : string [ ] = [ ] ;
122
124
private _contextElementDependencyConstructor ! : ContextElementDependencyConstructor ;
123
125
124
126
// TypeChecker process.
@@ -270,24 +272,22 @@ export class AngularCompilerPlugin {
270
272
if ( this . _discoverLazyRoutes === false && this . options . additionalLazyModuleResources
271
273
&& this . options . additionalLazyModuleResources . length > 0 ) {
272
274
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.` ,
275
277
) ;
276
278
}
277
279
278
280
if ( this . _compilerOptions . strictMetadataEmit ) {
279
281
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.` ,
283
283
) ;
284
284
}
285
285
286
286
if ( this . _discoverLazyRoutes === false && this . options . additionalLazyModules
287
287
&& Object . keys ( this . options . additionalLazyModules ) . length > 0 ) {
288
288
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.` ,
291
291
) ;
292
292
}
293
293
@@ -544,9 +544,9 @@ export class AngularCompilerPlugin {
544
544
if ( this . _lazyRoutes [ moduleKey ] !== modulePath ) {
545
545
// Found a duplicate, this is an error.
546
546
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.` ,
550
550
) ;
551
551
}
552
552
} else {
@@ -679,9 +679,10 @@ export class AngularCompilerPlugin {
679
679
// Anything that remains is unused, because it wasn't referenced directly or transitively
680
680
// on the files in the compilation.
681
681
for ( const fileName of unusedSourceFileNames ) {
682
- compilation . warnings . push (
682
+ addWarning (
683
+ compilation ,
683
684
`${ 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.` ,
685
686
) ;
686
687
this . _unusedFiles . add ( fileName ) ;
687
688
// Remove the truly unused from the type dep list.
@@ -965,7 +966,9 @@ export class AngularCompilerPlugin {
965
966
}
966
967
}
967
968
968
- return request ;
969
+ if ( ! isWebpackFiveOrHigher ( ) ) {
970
+ return request ;
971
+ }
969
972
} ,
970
973
) ;
971
974
} ) ;
@@ -1010,16 +1013,16 @@ export class AngularCompilerPlugin {
1010
1013
await this . _update ( ) ;
1011
1014
this . pushCompilationErrors ( compilation ) ;
1012
1015
} catch ( err ) {
1013
- compilation . errors . push ( err ) ;
1016
+ addError ( compilation , err . message || err ) ;
1014
1017
this . pushCompilationErrors ( compilation ) ;
1015
1018
}
1016
1019
1017
1020
timeEnd ( 'AngularCompilerPlugin._make' ) ;
1018
1021
}
1019
1022
1020
1023
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 ) ) ;
1023
1026
this . _errors = [ ] ;
1024
1027
this . _warnings = [ ] ;
1025
1028
}
@@ -1160,7 +1163,7 @@ export class AngularCompilerPlugin {
1160
1163
// Report any diagnostics.
1161
1164
reportDiagnostics (
1162
1165
diagnostics ,
1163
- msg => this . _errors . push ( new Error ( msg ) ) ,
1166
+ msg => this . _errors . push ( msg ) ,
1164
1167
msg => this . _warnings . push ( msg ) ,
1165
1168
) ;
1166
1169
0 commit comments