1
- import * as ts from "./_namespaces/ts" ;
1
+ import {
2
+ BuilderProgramKind , createBuilderProgram , createRedirectedBuilderProgram , getBuilderCreationParameters ,
3
+ ReusableBuilderProgramState ,
4
+ } from "./builder" ;
5
+ import {
6
+ CancellationToken , CompilerHost , CompilerOptions , CustomTransformers , Diagnostic , DiagnosticWithLocation ,
7
+ EmitResult , Program , ProjectReference , SourceFile , WriteFileCallback ,
8
+ } from "./types" ;
2
9
3
- export type AffectedFileResult < T > = { result : T ; affected : ts . SourceFile | ts . Program ; } | undefined ;
10
+ export type AffectedFileResult < T > = { result : T ; affected : SourceFile | Program ; } | undefined ;
4
11
5
12
export interface BuilderProgramHost {
6
13
/**
@@ -15,7 +22,7 @@ export interface BuilderProgramHost {
15
22
* When emit or emitNextAffectedFile are called without writeFile,
16
23
* this callback if present would be used to write files
17
24
*/
18
- writeFile ?: ts . WriteFileCallback ;
25
+ writeFile ?: WriteFileCallback ;
19
26
/**
20
27
* disable using source file version as signature for testing
21
28
*/
@@ -33,20 +40,20 @@ export interface BuilderProgramHost {
33
40
*/
34
41
export interface BuilderProgram {
35
42
/*@internal */
36
- getState ( ) : ts . ReusableBuilderProgramState ;
43
+ getState ( ) : ReusableBuilderProgramState ;
37
44
/*@internal */
38
45
backupState ( ) : void ;
39
46
/*@internal */
40
47
restoreState ( ) : void ;
41
48
/**
42
49
* Returns current program
43
50
*/
44
- getProgram ( ) : ts . Program ;
51
+ getProgram ( ) : Program ;
45
52
/**
46
53
* Returns current program that could be undefined if the program was released
47
54
*/
48
55
/*@internal */
49
- getProgramOrUndefined ( ) : ts . Program | undefined ;
56
+ getProgramOrUndefined ( ) : Program | undefined ;
50
57
/**
51
58
* Releases reference to the program, making all the other operations that need program to fail.
52
59
*/
@@ -55,39 +62,39 @@ export interface BuilderProgram {
55
62
/**
56
63
* Get compiler options of the program
57
64
*/
58
- getCompilerOptions ( ) : ts . CompilerOptions ;
65
+ getCompilerOptions ( ) : CompilerOptions ;
59
66
/**
60
67
* Get the source file in the program with file name
61
68
*/
62
- getSourceFile ( fileName : string ) : ts . SourceFile | undefined ;
69
+ getSourceFile ( fileName : string ) : SourceFile | undefined ;
63
70
/**
64
71
* Get a list of files in the program
65
72
*/
66
- getSourceFiles ( ) : readonly ts . SourceFile [ ] ;
73
+ getSourceFiles ( ) : readonly SourceFile [ ] ;
67
74
/**
68
75
* Get the diagnostics for compiler options
69
76
*/
70
- getOptionsDiagnostics ( cancellationToken ?: ts . CancellationToken ) : readonly ts . Diagnostic [ ] ;
77
+ getOptionsDiagnostics ( cancellationToken ?: CancellationToken ) : readonly Diagnostic [ ] ;
71
78
/**
72
79
* Get the diagnostics that dont belong to any file
73
80
*/
74
- getGlobalDiagnostics ( cancellationToken ?: ts . CancellationToken ) : readonly ts . Diagnostic [ ] ;
81
+ getGlobalDiagnostics ( cancellationToken ?: CancellationToken ) : readonly Diagnostic [ ] ;
75
82
/**
76
83
* Get the diagnostics from config file parsing
77
84
*/
78
- getConfigFileParsingDiagnostics ( ) : readonly ts . Diagnostic [ ] ;
85
+ getConfigFileParsingDiagnostics ( ) : readonly Diagnostic [ ] ;
79
86
/**
80
87
* Get the syntax diagnostics, for all source files if source file is not supplied
81
88
*/
82
- getSyntacticDiagnostics ( sourceFile ?: ts . SourceFile , cancellationToken ?: ts . CancellationToken ) : readonly ts . Diagnostic [ ] ;
89
+ getSyntacticDiagnostics ( sourceFile ?: SourceFile , cancellationToken ?: CancellationToken ) : readonly Diagnostic [ ] ;
83
90
/**
84
91
* Get the declaration diagnostics, for all source files if source file is not supplied
85
92
*/
86
- getDeclarationDiagnostics ( sourceFile ?: ts . SourceFile , cancellationToken ?: ts . CancellationToken ) : readonly ts . DiagnosticWithLocation [ ] ;
93
+ getDeclarationDiagnostics ( sourceFile ?: SourceFile , cancellationToken ?: CancellationToken ) : readonly DiagnosticWithLocation [ ] ;
87
94
/**
88
95
* Get all the dependencies of the file
89
96
*/
90
- getAllDependencies ( sourceFile : ts . SourceFile ) : readonly string [ ] ;
97
+ getAllDependencies ( sourceFile : SourceFile ) : readonly string [ ] ;
91
98
92
99
/**
93
100
* Gets the semantic diagnostics from the program corresponding to this state of file (if provided) or whole program
@@ -97,7 +104,7 @@ export interface BuilderProgram {
97
104
* In case of SemanticDiagnosticsBuilderProgram if the source file is not provided,
98
105
* it will iterate through all the affected files, to ensure that cache stays valid and yet provide a way to get all semantic diagnostics
99
106
*/
100
- getSemanticDiagnostics ( sourceFile ?: ts . SourceFile , cancellationToken ?: ts . CancellationToken ) : readonly ts . Diagnostic [ ] ;
107
+ getSemanticDiagnostics ( sourceFile ?: SourceFile , cancellationToken ?: CancellationToken ) : readonly Diagnostic [ ] ;
101
108
/**
102
109
* Emits the JavaScript and declaration files.
103
110
* When targetSource file is specified, emits the files corresponding to that source file,
@@ -109,9 +116,9 @@ export interface BuilderProgram {
109
116
* The first of writeFile if provided, writeFile of BuilderProgramHost if provided, writeFile of compiler host
110
117
* in that order would be used to write the files
111
118
*/
112
- emit ( targetSourceFile ?: ts . SourceFile , writeFile ?: ts . WriteFileCallback , cancellationToken ?: ts . CancellationToken , emitOnlyDtsFiles ?: boolean , customTransformers ?: ts . CustomTransformers ) : ts . EmitResult ;
119
+ emit ( targetSourceFile ?: SourceFile , writeFile ?: WriteFileCallback , cancellationToken ?: CancellationToken , emitOnlyDtsFiles ?: boolean , customTransformers ?: CustomTransformers ) : EmitResult ;
113
120
/*@internal */
114
- emitBuildInfo ( writeFile ?: ts . WriteFileCallback , cancellationToken ?: ts . CancellationToken ) : ts . EmitResult ;
121
+ emitBuildInfo ( writeFile ?: WriteFileCallback , cancellationToken ?: CancellationToken ) : EmitResult ;
115
122
/**
116
123
* Get the current directory of the program
117
124
*/
@@ -128,7 +135,7 @@ export interface SemanticDiagnosticsBuilderProgram extends BuilderProgram {
128
135
* Gets the semantic diagnostics from the program for the next affected file and caches it
129
136
* Returns undefined if the iteration is complete
130
137
*/
131
- getSemanticDiagnosticsOfNextAffectedFile ( cancellationToken ?: ts . CancellationToken , ignoreSourceFile ?: ( sourceFile : ts . SourceFile ) => boolean ) : AffectedFileResult < readonly ts . Diagnostic [ ] > ;
138
+ getSemanticDiagnosticsOfNextAffectedFile ( cancellationToken ?: CancellationToken , ignoreSourceFile ?: ( sourceFile : SourceFile ) => boolean ) : AffectedFileResult < readonly Diagnostic [ ] > ;
132
139
}
133
140
134
141
/**
@@ -141,34 +148,34 @@ export interface EmitAndSemanticDiagnosticsBuilderProgram extends SemanticDiagno
141
148
* The first of writeFile if provided, writeFile of BuilderProgramHost if provided, writeFile of compiler host
142
149
* in that order would be used to write the files
143
150
*/
144
- emitNextAffectedFile ( writeFile ?: ts . WriteFileCallback , cancellationToken ?: ts . CancellationToken , emitOnlyDtsFiles ?: boolean , customTransformers ?: ts . CustomTransformers ) : AffectedFileResult < ts . EmitResult > ;
151
+ emitNextAffectedFile ( writeFile ?: WriteFileCallback , cancellationToken ?: CancellationToken , emitOnlyDtsFiles ?: boolean , customTransformers ?: CustomTransformers ) : AffectedFileResult < EmitResult > ;
145
152
}
146
153
147
154
/**
148
155
* Create the builder to manage semantic diagnostics and cache them
149
156
*/
150
- export function createSemanticDiagnosticsBuilderProgram ( newProgram : ts . Program , host : BuilderProgramHost , oldProgram ?: SemanticDiagnosticsBuilderProgram , configFileParsingDiagnostics ?: readonly ts . Diagnostic [ ] ) : SemanticDiagnosticsBuilderProgram ;
151
- export function createSemanticDiagnosticsBuilderProgram ( rootNames : readonly string [ ] | undefined , options : ts . CompilerOptions | undefined , host ?: ts . CompilerHost , oldProgram ?: SemanticDiagnosticsBuilderProgram , configFileParsingDiagnostics ?: readonly ts . Diagnostic [ ] , projectReferences ?: readonly ts . ProjectReference [ ] ) : SemanticDiagnosticsBuilderProgram ;
152
- export function createSemanticDiagnosticsBuilderProgram ( newProgramOrRootNames : ts . Program | readonly string [ ] | undefined , hostOrOptions : BuilderProgramHost | ts . CompilerOptions | undefined , oldProgramOrHost ?: ts . CompilerHost | SemanticDiagnosticsBuilderProgram , configFileParsingDiagnosticsOrOldProgram ?: readonly ts . Diagnostic [ ] | SemanticDiagnosticsBuilderProgram , configFileParsingDiagnostics ?: readonly ts . Diagnostic [ ] , projectReferences ?: readonly ts . ProjectReference [ ] ) {
153
- return ts . createBuilderProgram ( ts . BuilderProgramKind . SemanticDiagnosticsBuilderProgram , ts . getBuilderCreationParameters ( newProgramOrRootNames , hostOrOptions , oldProgramOrHost , configFileParsingDiagnosticsOrOldProgram , configFileParsingDiagnostics , projectReferences ) ) ;
157
+ export function createSemanticDiagnosticsBuilderProgram ( newProgram : Program , host : BuilderProgramHost , oldProgram ?: SemanticDiagnosticsBuilderProgram , configFileParsingDiagnostics ?: readonly Diagnostic [ ] ) : SemanticDiagnosticsBuilderProgram ;
158
+ export function createSemanticDiagnosticsBuilderProgram ( rootNames : readonly string [ ] | undefined , options : CompilerOptions | undefined , host ?: CompilerHost , oldProgram ?: SemanticDiagnosticsBuilderProgram , configFileParsingDiagnostics ?: readonly Diagnostic [ ] , projectReferences ?: readonly ProjectReference [ ] ) : SemanticDiagnosticsBuilderProgram ;
159
+ export function createSemanticDiagnosticsBuilderProgram ( newProgramOrRootNames : Program | readonly string [ ] | undefined , hostOrOptions : BuilderProgramHost | CompilerOptions | undefined , oldProgramOrHost ?: CompilerHost | SemanticDiagnosticsBuilderProgram , configFileParsingDiagnosticsOrOldProgram ?: readonly Diagnostic [ ] | SemanticDiagnosticsBuilderProgram , configFileParsingDiagnostics ?: readonly Diagnostic [ ] , projectReferences ?: readonly ProjectReference [ ] ) {
160
+ return createBuilderProgram ( BuilderProgramKind . SemanticDiagnosticsBuilderProgram , getBuilderCreationParameters ( newProgramOrRootNames , hostOrOptions , oldProgramOrHost , configFileParsingDiagnosticsOrOldProgram , configFileParsingDiagnostics , projectReferences ) ) ;
154
161
}
155
162
156
163
/**
157
164
* Create the builder that can handle the changes in program and iterate through changed files
158
165
* to emit the those files and manage semantic diagnostics cache as well
159
166
*/
160
- export function createEmitAndSemanticDiagnosticsBuilderProgram ( newProgram : ts . Program , host : BuilderProgramHost , oldProgram ?: EmitAndSemanticDiagnosticsBuilderProgram , configFileParsingDiagnostics ?: readonly ts . Diagnostic [ ] ) : EmitAndSemanticDiagnosticsBuilderProgram ;
161
- export function createEmitAndSemanticDiagnosticsBuilderProgram ( rootNames : readonly string [ ] | undefined , options : ts . CompilerOptions | undefined , host ?: ts . CompilerHost , oldProgram ?: EmitAndSemanticDiagnosticsBuilderProgram , configFileParsingDiagnostics ?: readonly ts . Diagnostic [ ] , projectReferences ?: readonly ts . ProjectReference [ ] ) : EmitAndSemanticDiagnosticsBuilderProgram ;
162
- export function createEmitAndSemanticDiagnosticsBuilderProgram ( newProgramOrRootNames : ts . Program | readonly string [ ] | undefined , hostOrOptions : BuilderProgramHost | ts . CompilerOptions | undefined , oldProgramOrHost ?: ts . CompilerHost | EmitAndSemanticDiagnosticsBuilderProgram , configFileParsingDiagnosticsOrOldProgram ?: readonly ts . Diagnostic [ ] | EmitAndSemanticDiagnosticsBuilderProgram , configFileParsingDiagnostics ?: readonly ts . Diagnostic [ ] , projectReferences ?: readonly ts . ProjectReference [ ] ) {
163
- return ts . createBuilderProgram ( ts . BuilderProgramKind . EmitAndSemanticDiagnosticsBuilderProgram , ts . getBuilderCreationParameters ( newProgramOrRootNames , hostOrOptions , oldProgramOrHost , configFileParsingDiagnosticsOrOldProgram , configFileParsingDiagnostics , projectReferences ) ) ;
167
+ export function createEmitAndSemanticDiagnosticsBuilderProgram ( newProgram : Program , host : BuilderProgramHost , oldProgram ?: EmitAndSemanticDiagnosticsBuilderProgram , configFileParsingDiagnostics ?: readonly Diagnostic [ ] ) : EmitAndSemanticDiagnosticsBuilderProgram ;
168
+ export function createEmitAndSemanticDiagnosticsBuilderProgram ( rootNames : readonly string [ ] | undefined , options : CompilerOptions | undefined , host ?: CompilerHost , oldProgram ?: EmitAndSemanticDiagnosticsBuilderProgram , configFileParsingDiagnostics ?: readonly Diagnostic [ ] , projectReferences ?: readonly ProjectReference [ ] ) : EmitAndSemanticDiagnosticsBuilderProgram ;
169
+ export function createEmitAndSemanticDiagnosticsBuilderProgram ( newProgramOrRootNames : Program | readonly string [ ] | undefined , hostOrOptions : BuilderProgramHost | CompilerOptions | undefined , oldProgramOrHost ?: CompilerHost | EmitAndSemanticDiagnosticsBuilderProgram , configFileParsingDiagnosticsOrOldProgram ?: readonly Diagnostic [ ] | EmitAndSemanticDiagnosticsBuilderProgram , configFileParsingDiagnostics ?: readonly Diagnostic [ ] , projectReferences ?: readonly ProjectReference [ ] ) {
170
+ return createBuilderProgram ( BuilderProgramKind . EmitAndSemanticDiagnosticsBuilderProgram , getBuilderCreationParameters ( newProgramOrRootNames , hostOrOptions , oldProgramOrHost , configFileParsingDiagnosticsOrOldProgram , configFileParsingDiagnostics , projectReferences ) ) ;
164
171
}
165
172
166
173
/**
167
174
* Creates a builder thats just abstraction over program and can be used with watch
168
175
*/
169
- export function createAbstractBuilder ( newProgram : ts . Program , host : BuilderProgramHost , oldProgram ?: BuilderProgram , configFileParsingDiagnostics ?: readonly ts . Diagnostic [ ] ) : BuilderProgram ;
170
- export function createAbstractBuilder ( rootNames : readonly string [ ] | undefined , options : ts . CompilerOptions | undefined , host ?: ts . CompilerHost , oldProgram ?: BuilderProgram , configFileParsingDiagnostics ?: readonly ts . Diagnostic [ ] , projectReferences ?: readonly ts . ProjectReference [ ] ) : BuilderProgram ;
171
- export function createAbstractBuilder ( newProgramOrRootNames : ts . Program | readonly string [ ] | undefined , hostOrOptions : BuilderProgramHost | ts . CompilerOptions | undefined , oldProgramOrHost ?: ts . CompilerHost | BuilderProgram , configFileParsingDiagnosticsOrOldProgram ?: readonly ts . Diagnostic [ ] | BuilderProgram , configFileParsingDiagnostics ?: readonly ts . Diagnostic [ ] , projectReferences ?: readonly ts . ProjectReference [ ] ) : BuilderProgram {
172
- const { newProgram, configFileParsingDiagnostics : newConfigFileParsingDiagnostics } = ts . getBuilderCreationParameters ( newProgramOrRootNames , hostOrOptions , oldProgramOrHost , configFileParsingDiagnosticsOrOldProgram , configFileParsingDiagnostics , projectReferences ) ;
173
- return ts . createRedirectedBuilderProgram ( ( ) => ( { program : newProgram , compilerOptions : newProgram . getCompilerOptions ( ) } ) , newConfigFileParsingDiagnostics ) ;
176
+ export function createAbstractBuilder ( newProgram : Program , host : BuilderProgramHost , oldProgram ?: BuilderProgram , configFileParsingDiagnostics ?: readonly Diagnostic [ ] ) : BuilderProgram ;
177
+ export function createAbstractBuilder ( rootNames : readonly string [ ] | undefined , options : CompilerOptions | undefined , host ?: CompilerHost , oldProgram ?: BuilderProgram , configFileParsingDiagnostics ?: readonly Diagnostic [ ] , projectReferences ?: readonly ProjectReference [ ] ) : BuilderProgram ;
178
+ export function createAbstractBuilder ( newProgramOrRootNames : Program | readonly string [ ] | undefined , hostOrOptions : BuilderProgramHost | CompilerOptions | undefined , oldProgramOrHost ?: CompilerHost | BuilderProgram , configFileParsingDiagnosticsOrOldProgram ?: readonly Diagnostic [ ] | BuilderProgram , configFileParsingDiagnostics ?: readonly Diagnostic [ ] , projectReferences ?: readonly ProjectReference [ ] ) : BuilderProgram {
179
+ const { newProgram, configFileParsingDiagnostics : newConfigFileParsingDiagnostics } = getBuilderCreationParameters ( newProgramOrRootNames , hostOrOptions , oldProgramOrHost , configFileParsingDiagnosticsOrOldProgram , configFileParsingDiagnostics , projectReferences ) ;
180
+ return createRedirectedBuilderProgram ( ( ) => ( { program : newProgram , compilerOptions : newProgram . getCompilerOptions ( ) } ) , newConfigFileParsingDiagnostics ) ;
174
181
}
0 commit comments