forked from dominikg/tsconfck
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
262 lines (243 loc) · 7.46 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
declare module 'tsconfck' {
export interface TSConfckFindOptions {
/**
* A cache to improve performance for multiple calls in the same project
*
* Warning: You must clear this cache in case tsconfig files are added/removed during it's lifetime
*/
cache?: TSConfckCache<TSConfckParseResult | TSConfckParseNativeResult>;
/**
* project root dir, does not continue scanning outside of this directory.
*
* Improves performance but may lead to different results from native typescript when no tsconfig is found inside root
*/
root?: string;
/**
* set to true if you don't want to find tsconfig for files inside node_modules
*
* This is useful if you want to use the output with esbuild.transform as esbuild itself also ignores node_modules
*
* @default false
*/
ignoreNodeModules?: boolean;
/**
* Override the default name of the config file to find.
*
* Use `jsconfig.json` in projects that have typechecking for js files with jsconfig.json
*
* @default tsconfig.json
*/
configName?: string;
}
export interface TSConfckParseOptions extends TSConfckFindOptions {
// same as find options
}
export interface TSConfckFindAllOptions {
/**
* helper to skip subdirectories when scanning for tsconfig.json
*
* eg ` dir => dir === 'node_modules' || dir === '.git'`
*/
skip?: (dir: string) => boolean;
/**
* list of config filenames to include, use ["tsconfig.json","jsconfig.json"] if you need both
*
* @default ["tsconfig.json"]
*/
configNames?: string[];
}
export interface TSConfckParseResult {
/**
* absolute path to parsed tsconfig.json
*/
tsconfigFile: string;
/**
* parsed result, including merged values from extended
*/
tsconfig: any;
/**
* ParseResult for parent solution
*/
solution?: TSConfckParseResult;
/**
* ParseResults for all tsconfig files referenced in a solution
*/
referenced?: TSConfckParseResult[];
/**
* ParseResult for all tsconfig files
*
* [a,b,c] where a extends b and b extends c
*/
extended?: TSConfckParseResult[];
}
export interface TSConfckParseNativeOptions extends TSConfckParseOptions {
/**
* Set this option to true to force typescript to ignore all source files.
*
* This is faster - especially for large projects - but comes with 2 caveats
*
* 1) output tsconfig always has `files: [],include: []` instead of any real values configured.
* 2) as a result of 1), it won't be able to resolve solution-style references and always return the closest tsconfig
*/
ignoreSourceFiles?: boolean;
}
export interface TSConfckParseNativeResult {
/**
* absolute path to parsed tsconfig.json
*/
tsconfigFile: string;
/**
* parsed result, including merged values from extended and normalized
*/
tsconfig: any;
/**
* ParseResult for parent solution
*/
solution?: TSConfckParseNativeResult;
/**
* ParseNativeResults for all tsconfig files referenced in a solution
*/
referenced?: TSConfckParseNativeResult[];
/**
* full output of ts.parseJsonConfigFileContent
*/
result: any;
}
export class TSConfckCache<T> {
/**
* clear cache, use this if you have a long running process and tsconfig files have been added,changed or deleted
*/
clear(): void;
/**
* has cached closest config for files in dir
* */
hasConfigPath(dir: string, configName?: string | undefined): boolean;
/**
* get cached closest tsconfig for files in dir
* @throws {unknown} if cached value is an error
*/
getConfigPath(dir: string, configName?: string | undefined): Promise<string | null> | string | null;
/**
* has parsed tsconfig for file
* */
hasParseResult(file: string): boolean;
/**
* get parsed tsconfig for file
* @throws {unknown} if cached value is an error
*/
getParseResult(file: string): Promise<T> | T;
/**
* @param isRootFile a flag to check if current file which involking the parse() api, used to distinguish the normal cache which only parsed by parseFile()
* */
private setParseResult;
private setConfigPath;
#private;
}
/**
* find the closest tsconfig.json file
*
* @param filename - path to file to find tsconfig for (absolute or relative to cwd)
* @param options - options
* @returns absolute path to closest tsconfig.json or null if not found
*/
export function find(filename: string, options?: TSConfckFindOptions | undefined): Promise<string | null>;
/**
* find all tsconfig.json files in dir
*
* @param dir - path to dir (absolute or relative to cwd)
* @param options - options
* @returns list of absolute paths to all found tsconfig.json files
*/
export function findAll(dir: string, options?: TSConfckFindAllOptions | undefined): Promise<string[]>;
/**
* convert content of tsconfig.json to regular json
*
* @param tsconfigJson - content of tsconfig.json
* @returns content as regular json, comments and dangling commas have been replaced with whitespace
*/
export function toJson(tsconfigJson: string): string;
/**
* find the closest tsconfig.json file using native ts.findConfigFile
*
* You must have `typescript` installed to use this
*
* @param filename - path to file to find tsconfig for (absolute or relative to cwd)
* @param options - options
* @returns absolute path to closest tsconfig.json
*/
export function findNative(filename: string, options?: TSConfckFindOptions | undefined): Promise<string>;
/**
* parse the closest tsconfig.json file
*
* @param filename - path to a tsconfig .json or a source file or directory (absolute or relative to cwd)
* @param options - options
* */
export function parse(filename: string, options?: TSConfckParseOptions | undefined): Promise<TSConfckParseResult>;
export class TSConfckParseError extends Error {
/**
*
* @param message - error message
* @param code - error code
* @param tsconfigFile - path to tsconfig file
* @param cause - cause of this error
*/
constructor(message: string, code: string, tsconfigFile: string, cause: Error | null);
/**
* error code
* */
code: string;
/**
* error cause
* */
cause: Error | undefined;
/**
* absolute path of tsconfig file where the error happened
* */
tsconfigFile: string;
}
/**
* parse the closest tsconfig.json file with typescript native functions
*
* You need to have `typescript` installed to use this
*
* @param filename - path to a tsconfig .json or a source file (absolute or relative to cwd)
* @param options - options
* */
export function parseNative(filename: string, options?: TSConfckParseNativeOptions | undefined): Promise<TSConfckParseNativeResult>;
export class TSConfckParseNativeError extends Error {
/**
*
* @param diagnostic - diagnostics of ts
* @param tsconfigFile - file that errored
* @param result - parsed result, if any
*/
constructor(diagnostic: TSDiagnosticError, tsconfigFile: string, result: any | null);
/**
* code of typescript diagnostic, prefixed with "TS "
* */
code: string;
/**
* full ts diagnostic that caused this error
* */
diagnostic: TSDiagnosticError;
/**
* native result if present, contains all errors in result.errors
* */
result: any | undefined;
/**
* absolute path of tsconfig file where the error happened
* */
tsconfigFile: string;
}
/**
* {
* code: number;
* category: number;
* messageText: string;
* start?: number;
* } TSDiagnosticError
*/
type TSDiagnosticError = any;
export {};
}
//# sourceMappingURL=index.d.ts.map