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,13 @@ 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
+ InitMessage ,
60
+ LogMessage ,
61
+ MESSAGE_KIND ,
62
+ UpdateMessage ,
63
+ } from './type_checker' ;
49
64
import {
50
65
VirtualFileSystemDecorator ,
51
66
VirtualWatchFileSystemDecorator ,
@@ -59,7 +74,7 @@ import { WebpackInputHost } from './webpack-input-host';
59
74
60
75
const treeKill = require ( 'tree-kill' ) ;
61
76
62
- export interface ContextElementDependency { }
77
+ export interface ContextElementDependency { }
63
78
64
79
export interface ContextElementDependencyConstructor {
65
80
new ( modulePath : string , name : string ) : ContextElementDependency ;
@@ -85,6 +100,7 @@ export interface AngularCompilerPluginOptions {
85
100
missingTranslation ?: string ;
86
101
platform ?: PLATFORM ;
87
102
nameLazyFiles ?: boolean ;
103
+ logger ?: logging . Logger ;
88
104
89
105
// added to the list of lazy routes
90
106
additionalLazyModules ?: { [ module : string ] : string } ;
@@ -141,6 +157,9 @@ export class AngularCompilerPlugin {
141
157
private _typeCheckerProcess : ChildProcess | null ;
142
158
private _forkedTypeCheckerInitialized = false ;
143
159
160
+ // Logging.
161
+ private _logger : logging . Logger ;
162
+
144
163
private get _ngCompilerSupportsNewApi ( ) {
145
164
if ( this . _JitMode ) {
146
165
return false ;
@@ -179,6 +198,8 @@ export class AngularCompilerPlugin {
179
198
180
199
private _setupOptions ( options : AngularCompilerPluginOptions ) {
181
200
time ( 'AngularCompilerPlugin._setupOptions' ) ;
201
+ this . _logger = options . logger || createConsoleLogger ( ) ;
202
+
182
203
// Fill in the missing options.
183
204
if ( ! options . hasOwnProperty ( 'tsConfigPath' ) ) {
184
205
throw new Error ( 'Must specify "tsConfigPath" in the configuration of @ngtools/webpack.' ) ;
@@ -415,7 +436,7 @@ export class AngularCompilerPlugin {
415
436
} ) ,
416
437
// TODO: fix compiler-cli typings; entryModule should not be string, but also optional.
417
438
// tslint:disable-next-line:no-non-null-assertion
418
- entryModule : this . _entryModule ! ,
439
+ entryModule : this . _entryModule ! ,
419
440
} ) ;
420
441
timeEnd ( 'AngularCompilerPlugin._getLazyRoutesFromNgtools' ) ;
421
442
@@ -542,6 +563,18 @@ export class AngularCompilerPlugin {
542
563
forkArgs ,
543
564
forkOptions ) ;
544
565
566
+ // Handle child messages.
567
+ this . _typeCheckerProcess . on ( 'message' , message => {
568
+ switch ( message . kind ) {
569
+ case MESSAGE_KIND . Log :
570
+ const logMessage = message as LogMessage ;
571
+ this . _logger . log ( logMessage . level , logMessage . message ) ;
572
+ break ;
573
+ default :
574
+ throw new Error ( `TypeChecker: Unexpected message received: ${ message } .` ) ;
575
+ }
576
+ } ) ;
577
+
545
578
// Handle child process exit.
546
579
this . _typeCheckerProcess . once ( 'exit' , ( _ , signal ) => {
547
580
this . _typeCheckerProcess = null ;
@@ -748,10 +781,10 @@ export class AngularCompilerPlugin {
748
781
const name = request . request ;
749
782
const issuer = request . contextInfo . issuer ;
750
783
if ( name . endsWith ( '.ts' ) || name . endsWith ( '.tsx' )
751
- || ( issuer && / \. t s | n g f a c t o r y \. j s $ / . test ( issuer ) ) ) {
784
+ || ( issuer && / \. t s | n g f a c t o r y \. j s $ / . test ( issuer ) ) ) {
752
785
try {
753
786
await this . done ;
754
- } catch { }
787
+ } catch { }
755
788
}
756
789
}
757
790
0 commit comments