@@ -4,37 +4,44 @@ import { getConfigFilePathFromCompilerOptions } from './config';
4
4
import { typescript } from './typescript' ;
5
5
import { config } from './worker-config' ;
6
6
7
- // write this type as it's available only starting from TypeScript 4.1.0
7
+ // these types are internal in TypeScript, so reproduce them here
8
+ type TracingMode = 'project' | 'build' | 'server' ;
8
9
interface Tracing {
9
- startTracing ( configFilePath : string , traceDirPath : string , isBuildMode : boolean ) : void ;
10
- stopTracing ( typeCatalog : unknown ) : void ;
11
- dumpLegend ( ) : void ;
10
+ startTracing ?: ( tracingMode : TracingMode , traceDir : string , configFilePath ?: string ) => void ;
11
+
12
+ tracing ?: {
13
+ stopTracing ( ) : void ;
14
+ dumpLegend ( ) : void ;
15
+ } ;
12
16
}
13
17
14
18
// eslint-disable-next-line @typescript-eslint/no-explicit-any
15
- const tracing : Tracing | undefined = ( typescript as any ) . tracing ;
19
+ const traceableTypescript : Tracing = typescript as any ;
16
20
17
21
export function startTracingIfNeeded ( compilerOptions : ts . CompilerOptions ) {
18
- if ( compilerOptions . generateTrace && tracing ) {
19
- tracing . startTracing (
20
- getConfigFilePathFromCompilerOptions ( compilerOptions ) ,
21
- compilerOptions . generateTrace as string ,
22
- config . build
22
+ if (
23
+ typeof compilerOptions . generateTrace === 'string' &&
24
+ typeof traceableTypescript . startTracing === 'function'
25
+ ) {
26
+ traceableTypescript . startTracing (
27
+ config . build ? 'build' : 'project' ,
28
+ compilerOptions . generateTrace ,
29
+ getConfigFilePathFromCompilerOptions ( compilerOptions )
23
30
) ;
24
31
}
25
32
}
26
33
27
- export function stopTracingIfNeeded ( program : ts . BuilderProgram ) {
34
+ export function stopTracingIfNeeded ( program : ts . Program | ts . BuilderProgram ) {
28
35
const compilerOptions = program . getCompilerOptions ( ) ;
29
36
30
- if ( compilerOptions . generateTrace && tracing ) {
31
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
32
- tracing . stopTracing ( ( program . getProgram ( ) as any ) . getTypeCatalog ( ) ) ;
37
+ if (
38
+ typeof compilerOptions . generateTrace === 'string' &&
39
+ typeof traceableTypescript . tracing ?. stopTracing === 'function'
40
+ ) {
41
+ traceableTypescript . tracing . stopTracing ( ) ;
33
42
}
34
43
}
35
44
36
45
export function dumpTracingLegendIfNeeded ( ) {
37
- if ( tracing ) {
38
- tracing . dumpLegend ( ) ;
39
- }
46
+ traceableTypescript . tracing ?. dumpLegend ( ) ;
40
47
}
0 commit comments