1
1
// @ignoreDep typescript
2
- import * as process from 'process' ;
3
2
import * as ts from 'typescript' ;
4
3
import chalk from 'chalk' ;
5
-
6
- import { WebpackCompilerHost } from './compiler_host' ;
7
- import { time , timeEnd } from './benchmark' ;
8
- import { CancellationToken , gatherDiagnostics } from './gather_diagnostics' ;
9
4
import {
10
5
Program ,
11
6
CompilerOptions ,
@@ -14,12 +9,19 @@ import {
14
9
createCompilerHost ,
15
10
formatDiagnostics ,
16
11
} from './ngtools_api' ;
12
+ import { WebpackCompilerHost } from './compiler_host' ;
13
+ import { time , timeEnd } from './benchmark' ;
14
+ import { CancellationToken , gatherDiagnostics } from './gather_diagnostics' ;
15
+
16
+
17
+ // This file should run in a child process with the AUTO_START_ARG argument
17
18
18
19
// Force basic color support on terminals with no color support.
19
20
// Chalk typings don't have the correct constructor parameters.
20
21
const chalkCtx = new ( chalk . constructor as any ) ( chalk . supportsColor ? { } : { level : 1 } ) ;
21
22
const { bold, red, yellow } = chalkCtx ;
22
23
24
+
23
25
export enum MESSAGE_KIND {
24
26
Init ,
25
27
Update
@@ -46,43 +48,9 @@ export class UpdateMessage extends TypeCheckerMessage {
46
48
}
47
49
}
48
50
49
- let typeChecker : TypeChecker ;
50
- let lastCancellationToken : CancellationToken ;
51
-
52
- process . on ( 'message' , ( message : TypeCheckerMessage ) => {
53
- time ( 'TypeChecker.message' ) ;
54
- switch ( message . kind ) {
55
- case MESSAGE_KIND . Init :
56
- const initMessage = message as InitMessage ;
57
- typeChecker = new TypeChecker (
58
- initMessage . compilerOptions ,
59
- initMessage . basePath ,
60
- initMessage . jitMode ,
61
- initMessage . rootNames ,
62
- ) ;
63
- break ;
64
- case MESSAGE_KIND . Update :
65
- if ( ! typeChecker ) {
66
- throw new Error ( 'TypeChecker: update message received before initialization' ) ;
67
- }
68
- if ( lastCancellationToken ) {
69
- // This cancellation token doesn't seem to do much, messages don't seem to be processed
70
- // before the diagnostics finish.
71
- lastCancellationToken . requestCancellation ( ) ;
72
- }
73
- const updateMessage = message as UpdateMessage ;
74
- lastCancellationToken = new CancellationToken ( ) ;
75
- typeChecker . update ( updateMessage . rootNames , updateMessage . changedCompilationFiles ,
76
- lastCancellationToken ) ;
77
- break ;
78
- default :
79
- throw new Error ( `TypeChecker: Unexpected message received: ${ message } .` ) ;
80
- }
81
- timeEnd ( 'TypeChecker.message' ) ;
82
- } ) ;
83
-
51
+ export const AUTO_START_ARG = '9d93e901-158a-4cf9-ba1b-2f0582ffcfeb' ;
84
52
85
- class TypeChecker {
53
+ export class TypeChecker {
86
54
private _program : ts . Program | Program ;
87
55
private _compilerHost : WebpackCompilerHost & CompilerHost ;
88
56
@@ -171,3 +139,4 @@ class TypeChecker {
171
139
this . _diagnose ( cancellationToken ) ;
172
140
}
173
141
}
142
+
0 commit comments