5
5
* Use of this source code is governed by an MIT-style license that can be
6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
- import { Path , dirname , getSystemPath , normalize , resolve , virtualFs } from '@angular-devkit/core' ;
8
+ import {
9
+ Path ,
10
+ dirname ,
11
+ getSystemPath ,
12
+ logging ,
13
+ normalize ,
14
+ resolve ,
15
+ virtualFs ,
16
+ } from '@angular-devkit/core' ;
17
+ import { createConsoleLogger } from '@angular-devkit/core/node' ;
9
18
import {
10
19
CompilerHost ,
11
20
CompilerOptions ,
@@ -45,7 +54,15 @@ import {
45
54
replaceServerBootstrap ,
46
55
} from './transformers' ;
47
56
import { collectDeepNodes } from './transformers/ast_helpers' ;
48
- import { AUTO_START_ARG , InitMessage , UpdateMessage } from './type_checker' ;
57
+ import {
58
+ AUTO_START_ARG ,
59
+ } from './type_checker' ;
60
+ import {
61
+ InitMessage ,
62
+ LogMessage ,
63
+ MESSAGE_KIND ,
64
+ UpdateMessage ,
65
+ } from './type_checker_messages' ;
49
66
import {
50
67
VirtualFileSystemDecorator ,
51
68
VirtualWatchFileSystemDecorator ,
@@ -59,7 +76,7 @@ import { WebpackInputHost } from './webpack-input-host';
59
76
60
77
const treeKill = require ( 'tree-kill' ) ;
61
78
62
- export interface ContextElementDependency { }
79
+ export interface ContextElementDependency { }
63
80
64
81
export interface ContextElementDependencyConstructor {
65
82
new ( modulePath : string , name : string ) : ContextElementDependency ;
@@ -85,6 +102,7 @@ export interface AngularCompilerPluginOptions {
85
102
missingTranslation ?: string ;
86
103
platform ?: PLATFORM ;
87
104
nameLazyFiles ?: boolean ;
105
+ logger ?: logging . Logger ;
88
106
89
107
// added to the list of lazy routes
90
108
additionalLazyModules ?: { [ module : string ] : string } ;
@@ -141,6 +159,9 @@ export class AngularCompilerPlugin {
141
159
private _typeCheckerProcess : ChildProcess | null ;
142
160
private _forkedTypeCheckerInitialized = false ;
143
161
162
+ // Logging.
163
+ private _logger : logging . Logger ;
164
+
144
165
private get _ngCompilerSupportsNewApi ( ) {
145
166
if ( this . _JitMode ) {
146
167
return false ;
@@ -179,6 +200,8 @@ export class AngularCompilerPlugin {
179
200
180
201
private _setupOptions ( options : AngularCompilerPluginOptions ) {
181
202
time ( 'AngularCompilerPlugin._setupOptions' ) ;
203
+ this . _logger = options . logger || createConsoleLogger ( ) ;
204
+
182
205
// Fill in the missing options.
183
206
if ( ! options . hasOwnProperty ( 'tsConfigPath' ) ) {
184
207
throw new Error ( 'Must specify "tsConfigPath" in the configuration of @ngtools/webpack.' ) ;
@@ -415,7 +438,7 @@ export class AngularCompilerPlugin {
415
438
} ) ,
416
439
// TODO: fix compiler-cli typings; entryModule should not be string, but also optional.
417
440
// tslint:disable-next-line:no-non-null-assertion
418
- entryModule : this . _entryModule ! ,
441
+ entryModule : this . _entryModule ! ,
419
442
} ) ;
420
443
timeEnd ( 'AngularCompilerPlugin._getLazyRoutesFromNgtools' ) ;
421
444
@@ -542,6 +565,18 @@ export class AngularCompilerPlugin {
542
565
forkArgs ,
543
566
forkOptions ) ;
544
567
568
+ // Handle child messages.
569
+ this . _typeCheckerProcess . on ( 'message' , message => {
570
+ switch ( message . kind ) {
571
+ case MESSAGE_KIND . Log :
572
+ const logMessage = message as LogMessage ;
573
+ this . _logger . log ( logMessage . level , logMessage . message ) ;
574
+ break ;
575
+ default :
576
+ throw new Error ( `TypeChecker: Unexpected message received: ${ message } .` ) ;
577
+ }
578
+ } ) ;
579
+
545
580
// Handle child process exit.
546
581
this . _typeCheckerProcess . once ( 'exit' , ( _ , signal ) => {
547
582
this . _typeCheckerProcess = null ;
@@ -748,10 +783,10 @@ export class AngularCompilerPlugin {
748
783
const name = request . request ;
749
784
const issuer = request . contextInfo . issuer ;
750
785
if ( name . endsWith ( '.ts' ) || name . endsWith ( '.tsx' )
751
- || ( issuer && / \. t s | n g f a c t o r y \. j s $ / . test ( issuer ) ) ) {
786
+ || ( issuer && / \. t s | n g f a c t o r y \. j s $ / . test ( issuer ) ) ) {
752
787
try {
753
788
await this . done ;
754
- } catch { }
789
+ } catch { }
755
790
}
756
791
}
757
792
0 commit comments