@@ -115,6 +115,7 @@ export class AngularCompilerPlugin implements Tapable {
115
115
// TypeChecker process.
116
116
private _forkTypeChecker = true ;
117
117
private _typeCheckerProcess : ChildProcess ;
118
+ private _forkedTypeCheckerInitialized = false ;
118
119
119
120
private get _ngCompilerSupportsNewApi ( ) {
120
121
if ( this . _JitMode ) {
@@ -323,7 +324,7 @@ export class AngularCompilerPlugin implements Tapable {
323
324
324
325
// Update the forked type checker with all changed compilation files.
325
326
// This includes templates, that also need to be reloaded on the type checker.
326
- if ( this . _forkTypeChecker && ! this . _firstRun ) {
327
+ if ( this . _forkTypeChecker && this . _typeCheckerProcess && ! this . _firstRun ) {
327
328
this . _updateForkedTypeChecker ( this . _rootNames , this . _getChangedCompilationFiles ( ) ) ;
328
329
}
329
330
@@ -500,44 +501,42 @@ export class AngularCompilerPlugin implements Tapable {
500
501
path . resolve ( __dirname , typeCheckerFile ) ,
501
502
forkArgs ,
502
503
forkOptions ) ;
503
- this . _typeCheckerProcess . send ( new InitMessage ( this . _compilerOptions , this . _basePath ,
504
- this . _JitMode , this . _rootNames ) ) ;
505
-
506
- // Cleanup.
507
- const killTypeCheckerProcess = ( ) => {
508
- if ( this . _typeCheckerProcess && this . _typeCheckerProcess . pid ) {
509
- treeKill ( this . _typeCheckerProcess . pid , 'SIGTERM' ) ;
510
- this . _typeCheckerProcess = undefined ;
511
- this . _forkTypeChecker = false ;
512
- }
513
- } ;
514
504
515
505
// Handle child process exit.
516
506
const handleChildProcessExit = ( ) => {
517
- killTypeCheckerProcess ( ) ;
507
+ this . _killForkedTypeChecker ( ) ;
518
508
const msg = 'AngularCompilerPlugin: Forked Type Checker exited unexpectedly. ' +
519
- 'Falling back to typechecking on main thread.' ;
509
+ 'Falling back to type checking on main thread.' ;
520
510
this . _warnings . push ( msg ) ;
521
511
} ;
522
512
this . _typeCheckerProcess . once ( 'exit' , handleChildProcessExit ) ;
523
513
this . _typeCheckerProcess . once ( 'SIGINT' , handleChildProcessExit ) ;
524
514
this . _typeCheckerProcess . once ( 'uncaughtException' , handleChildProcessExit ) ;
525
515
526
516
// Handle parent process exit.
527
- const handleParentProcessExit = ( ) => {
528
- killTypeCheckerProcess ( ) ;
529
- process . exit ( ) ;
530
- } ;
517
+ const handleParentProcessExit = ( ) => this . _killForkedTypeChecker ( ) ;
531
518
process . once ( 'exit' , handleParentProcessExit ) ;
532
519
process . once ( 'SIGINT' , handleParentProcessExit ) ;
533
520
process . once ( 'uncaughtException' , handleParentProcessExit ) ;
534
521
}
535
522
523
+ private _killForkedTypeChecker ( ) {
524
+ if ( this . _typeCheckerProcess && this . _typeCheckerProcess . pid ) {
525
+ treeKill ( this . _typeCheckerProcess . pid , 'SIGTERM' ) ;
526
+ this . _typeCheckerProcess = undefined ;
527
+ this . _forkTypeChecker = false ;
528
+ }
529
+ }
530
+
536
531
private _updateForkedTypeChecker ( rootNames : string [ ] , changedCompilationFiles : string [ ] ) {
532
+ if ( ! this . _forkedTypeCheckerInitialized ) {
533
+ this . _typeCheckerProcess . send ( new InitMessage ( this . _compilerOptions , this . _basePath ,
534
+ this . _JitMode , this . _rootNames ) ) ;
535
+ this . _forkedTypeCheckerInitialized = true ;
536
+ }
537
537
this . _typeCheckerProcess . send ( new UpdateMessage ( rootNames , changedCompilationFiles ) ) ;
538
538
}
539
539
540
-
541
540
// Registration hook for webpack plugin.
542
541
apply ( compiler : any ) {
543
542
// Decorate inputFileSystem to serve contents of CompilerHost.
@@ -608,6 +607,15 @@ export class AngularCompilerPlugin implements Tapable {
608
607
} ) ;
609
608
} ) ;
610
609
610
+ // Create and destroy forked type checker on watch mode.
611
+ compiler . plugin ( 'watch-run' , ( _compiler : any , callback : any ) => {
612
+ if ( this . _forkTypeChecker && ! this . _typeCheckerProcess ) {
613
+ this . _createForkedTypeChecker ( ) ;
614
+ }
615
+ callback ( ) ;
616
+ } ) ;
617
+ compiler . plugin ( 'watch-close' , ( ) => this . _killForkedTypeChecker ( ) ) ;
618
+
611
619
// Remake the plugin on each compilation.
612
620
compiler . plugin ( 'make' , ( compilation : any , cb : any ) => this . _make ( compilation , cb ) ) ;
613
621
compiler . plugin ( 'invalid' , ( ) => this . _firstRun = false ) ;
@@ -663,11 +671,6 @@ export class AngularCompilerPlugin implements Tapable {
663
671
// Update the resource loader with the new webpack compilation.
664
672
this . _resourceLoader . update ( compilation ) ;
665
673
666
- // Create a new process for the type checker on the second build if there isn't one yet.
667
- if ( this . _forkTypeChecker && ! this . _firstRun && ! this . _typeCheckerProcess ) {
668
- this . _createForkedTypeChecker ( ) ;
669
- }
670
-
671
674
this . _donePromise = Promise . resolve ( )
672
675
. then ( ( ) => this . _update ( ) )
673
676
. then ( ( ) => {
0 commit comments