@@ -106,9 +106,9 @@ export class AngularCompilerPlugin implements Tapable {
106
106
// Webpack plugin.
107
107
private _firstRun = true ;
108
108
private _donePromise : Promise < void > | null ;
109
- private _compiler : any = null ;
110
- private _compilation : any = null ;
111
109
private _normalizedLocale : string ;
110
+ private _warnings : ( string | Error ) [ ] = [ ] ;
111
+ private _errors : ( string | Error ) [ ] = [ ] ;
112
112
113
113
// TypeChecker process.
114
114
private _forkTypeChecker = true ;
@@ -447,7 +447,7 @@ export class AngularCompilerPlugin implements Tapable {
447
447
if ( moduleKey in this . _lazyRoutes ) {
448
448
if ( this . _lazyRoutes [ moduleKey ] !== modulePath ) {
449
449
// Found a duplicate, this is an error.
450
- this . _compilation . warnings . push (
450
+ this . _warnings . push (
451
451
new Error ( `Duplicated path in loadChildren detected during a rebuild. `
452
452
+ `We will take the latest version detected and override it to save rebuild time. `
453
453
+ `You should perform a full build to validate that your routes don't overlap.` )
@@ -483,12 +483,32 @@ export class AngularCompilerPlugin implements Tapable {
483
483
484
484
// Cleanup.
485
485
const killTypeCheckerProcess = ( ) => {
486
- treeKill ( this . _typeCheckerProcess . pid , 'SIGTERM' ) ;
486
+ if ( this . _typeCheckerProcess && this . _typeCheckerProcess . pid ) {
487
+ treeKill ( this . _typeCheckerProcess . pid , 'SIGTERM' ) ;
488
+ this . _typeCheckerProcess = undefined ;
489
+ this . _forkTypeChecker = false ;
490
+ }
491
+ } ;
492
+
493
+ // Handle child process exit.
494
+ const handleChildProcessExit = ( ) => {
495
+ killTypeCheckerProcess ( ) ;
496
+ const msg = 'AngularCompilerPlugin: Forked Type Checker exited unexpectedly. ' +
497
+ 'Falling back to typechecking on main thread.' ;
498
+ this . _warnings . push ( msg ) ;
499
+ } ;
500
+ this . _typeCheckerProcess . once ( 'exit' , handleChildProcessExit ) ;
501
+ this . _typeCheckerProcess . once ( 'SIGINT' , handleChildProcessExit ) ;
502
+ this . _typeCheckerProcess . once ( 'uncaughtException' , handleChildProcessExit ) ;
503
+
504
+ // Handle parent process exit.
505
+ const handleParentProcessExit = ( ) => {
506
+ killTypeCheckerProcess ( ) ;
487
507
process . exit ( ) ;
488
508
} ;
489
- process . once ( 'exit' , killTypeCheckerProcess ) ;
490
- process . once ( 'SIGINT' , killTypeCheckerProcess ) ;
491
- process . once ( 'uncaughtException' , killTypeCheckerProcess ) ;
509
+ process . once ( 'exit' , handleParentProcessExit ) ;
510
+ process . once ( 'SIGINT' , handleParentProcessExit ) ;
511
+ process . once ( 'uncaughtException' , handleParentProcessExit ) ;
492
512
}
493
513
494
514
private _updateForkedTypeChecker ( rootNames : string [ ] , changedCompilationFiles : string [ ] ) {
@@ -498,8 +518,6 @@ export class AngularCompilerPlugin implements Tapable {
498
518
499
519
// Registration hook for webpack plugin.
500
520
apply ( compiler : any ) {
501
- this . _compiler = compiler ;
502
-
503
521
// Decorate inputFileSystem to serve contents of CompilerHost.
504
522
// Use decorated inputFileSystem in watchFileSystem.
505
523
compiler . plugin ( 'environment' , ( ) => {
@@ -573,7 +591,6 @@ export class AngularCompilerPlugin implements Tapable {
573
591
} ) ;
574
592
compiler . plugin ( 'done' , ( ) => {
575
593
this . _donePromise = null ;
576
- this . _compilation = null ;
577
594
} ) ;
578
595
579
596
// TODO: consider if it's better to remove this plugin and instead make it wait on the
@@ -604,14 +621,13 @@ export class AngularCompilerPlugin implements Tapable {
604
621
605
622
private _make ( compilation : any , cb : ( err ?: any , request ?: any ) => void ) {
606
623
time ( 'AngularCompilerPlugin._make' ) ;
607
- this . _compilation = compilation ;
608
624
this . _emitSkipped = true ;
609
- if ( this . _compilation . _ngToolsWebpackPluginInstance ) {
625
+ if ( compilation . _ngToolsWebpackPluginInstance ) {
610
626
return cb ( new Error ( 'An @ngtools/webpack plugin already exist for this compilation.' ) ) ;
611
627
}
612
628
613
629
// Set a private variable for this plugin instance.
614
- this . _compilation . _ngToolsWebpackPluginInstance = this ;
630
+ compilation . _ngToolsWebpackPluginInstance = this ;
615
631
616
632
// Update the resource loader with the new webpack compilation.
617
633
this . _resourceLoader . update ( compilation ) ;
@@ -624,15 +640,24 @@ export class AngularCompilerPlugin implements Tapable {
624
640
this . _donePromise = Promise . resolve ( )
625
641
. then ( ( ) => this . _update ( ) )
626
642
. then ( ( ) => {
643
+ this . pushCompilationErrors ( compilation ) ;
627
644
timeEnd ( 'AngularCompilerPlugin._make' ) ;
628
645
cb ( ) ;
629
646
} , ( err : any ) => {
630
647
compilation . errors . push ( err . stack ) ;
648
+ this . pushCompilationErrors ( compilation ) ;
631
649
timeEnd ( 'AngularCompilerPlugin._make' ) ;
632
650
cb ( ) ;
633
651
} ) ;
634
652
}
635
653
654
+ private pushCompilationErrors ( compilation : any ) {
655
+ compilation . errors . push ( ...this . _errors ) ;
656
+ compilation . warnings . push ( ...this . _warnings ) ;
657
+ this . _errors = [ ] ;
658
+ this . _warnings = [ ] ;
659
+ }
660
+
636
661
private _makeTransformers ( ) {
637
662
638
663
const isAppPath = ( fileName : string ) =>
@@ -730,18 +755,18 @@ export class AngularCompilerPlugin implements Tapable {
730
755
731
756
if ( errors . length > 0 ) {
732
757
const message = formatDiagnostics ( errors ) ;
733
- this . _compilation . errors . push ( message ) ;
758
+ this . _errors . push ( message ) ;
734
759
}
735
760
736
761
if ( warnings . length > 0 ) {
737
762
const message = formatDiagnostics ( warnings ) ;
738
- this . _compilation . warnings . push ( message ) ;
763
+ this . _warnings . push ( message ) ;
739
764
}
740
765
741
766
this . _emitSkipped = ! emitResult || emitResult . emitSkipped ;
742
767
743
768
// Reset changed files on successful compilation.
744
- if ( ! this . _emitSkipped && this . _compilation . errors . length === 0 ) {
769
+ if ( ! this . _emitSkipped && this . _errors . length === 0 ) {
745
770
this . _compilerHost . resetChangedFileTracker ( ) ;
746
771
}
747
772
timeEnd ( 'AngularCompilerPlugin._update' ) ;
0 commit comments