11// @ignoreDep typescript
2- import * as process from 'process' ;
32import * as ts from 'typescript' ;
43import chalk from 'chalk' ;
5-
6- import { WebpackCompilerHost } from './compiler_host' ;
7- import { time , timeEnd } from './benchmark' ;
8- import { CancellationToken , gatherDiagnostics } from './gather_diagnostics' ;
94import {
105 Program ,
116 CompilerOptions ,
@@ -14,12 +9,19 @@ import {
149 createCompilerHost ,
1510 formatDiagnostics ,
1611} 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
1718
1819// Force basic color support on terminals with no color support.
1920// Chalk typings don't have the correct constructor parameters.
2021const chalkCtx = new ( chalk . constructor as any ) ( chalk . supportsColor ? { } : { level : 1 } ) ;
2122const { bold, red, yellow } = chalkCtx ;
2223
24+
2325export enum MESSAGE_KIND {
2426 Init ,
2527 Update
@@ -46,43 +48,9 @@ export class UpdateMessage extends TypeCheckerMessage {
4648 }
4749}
4850
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' ;
8452
85- class TypeChecker {
53+ export class TypeChecker {
8654 private _program : ts . Program | Program ;
8755 private _compilerHost : WebpackCompilerHost & CompilerHost ;
8856
@@ -171,3 +139,4 @@ class TypeChecker {
171139 this . _diagnose ( cancellationToken ) ;
172140 }
173141}
142+
0 commit comments