-
Notifications
You must be signed in to change notification settings - Fork 459
/
Copy pathtypes.ts
244 lines (222 loc) · 7.09 KB
/
types.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
import type { TransformedSource, Transformer, TransformOptions } from '@jest/transform'
import type { Config } from '@jest/types'
import type * as babelJest from 'babel-jest'
import type * as _babel from 'babel__core'
import type * as _ts from 'typescript'
import type { ConfigSet } from './legacy/config/config-set'
import type { RawCompilerOptions } from './raw-compiler-options'
declare module '@jest/types' {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace Config {
interface ConfigGlobals {
/**
* strangely `@ts-expect-error` doesn't work in this case when running
* `npm run build` vs `npm run pretest`
*/
// eslint-disable-next-line
// @ts-ignore
'ts-jest': TsJestGlobalOptions
}
}
}
/**
* @internal
*/
export type TBabelCore = typeof _babel
/**
* @internal
*/
export type TBabelJest = typeof babelJest
export type TTypeScript = typeof _ts
// Stimulate `esbuild` type to avoid import `esbuild` while building the assets which are shipped to npm
/**
* @internal
*/
export interface TEsBuild {
transformSync(
input: string,
options?: { loader: 'ts' | 'js'; format: 'cjs' | 'esm'; target: string },
): { code: string; map: string }
}
/**
* @internal
*/
export type BabelJestTransformer = {
[K in Exclude<keyof Transformer, 'createTransformer'>]: Exclude<Transformer[K], undefined>
}
/**
* Don't mark as internal because it is used in TsJestGlobalOptions which is an exposed type
*/
export type BabelConfig = _babel.TransformOptions
export type TsJestPresets = Pick<
Config.InitialOptions,
'extensionsToTreatAsEsm' | 'moduleFileExtensions' | 'transform' | 'testMatch'
>
export interface AstTransformer<T = Record<string, unknown>> {
path: string
options?: T
}
export interface ConfigCustomTransformer {
before?: Array<string | AstTransformer>
after?: Array<string | AstTransformer>
afterDeclarations?: Array<string | AstTransformer>
}
/**
* @deprecated use `TsJestTransformerOptions` instead
*/
export interface TsJestGlobalOptions {
/**
* Compiler options. It can be:
* - `true` (or `undefined`, it's the default): use default tsconfig file
* - `false`: do NOT use default config file
* - `path/to/tsconfig.json`: path to a specific tsconfig file (<rootDir> can be used)
* - `{...}`: an object with inline compiler options
*
* @default undefined uses the default tsconfig file
*/
tsconfig?: boolean | string | RawCompilerOptions
/**
* Compiles files as isolated modules (disables some features and type-checking)
*
* @default undefined (disabled)
*/
isolatedModules?: boolean
/**
* Compiler to use
*
* @default 'typescript'
*/
compiler?: 'typescript' | 'ttypescript' | string
/**
* Custom transformers (mostly used by jest presets)
*/
astTransformers?: ConfigCustomTransformer
/**
* TS diagnostics - less to be reported if `isolatedModules` is `true`. It can be:
* - `true` (or `undefined`, it's the default): show all diagnostics
* - `false`: hide diagnostics of all files (kind of useless)
* - `{...}`: an inline object with fine grained settings
*
* @default undefined shows all diagnostics
*/
diagnostics?:
| boolean
| {
/**
* Enables colorful and pretty output of errors
*
* @default undefined (enabled)
*/
pretty?: boolean
/**
* List of TypeScript diagnostic error codes to ignore
* [here](https://github.com/Microsoft/TypeScript/blob/master/src/compiler/diagnosticMessages.json).
*
* @see https://github.com/Microsoft/TypeScript/blob/master/src/compiler/diagnosticMessages.json
* @default [6059,18002,18003]
*/
ignoreCodes?: number | string | Array<number | string>
/**
* If specified, diagnostics of source files which path **matches** will be ignored
*/
exclude?: string[]
/**
* Logs TypeScript errors to stderr instead of throwing exceptions
*
* @default undefined (disabled)
*/
warnOnly?: boolean
}
/**
* Babel config. It can be:
* - `false` (or `undefined`, it's the default): do NOT use babel
* - `true`: use babel using default babelrc file
* - `path/to/.babelrc`: path to a babelrc file (<rootDir> can be used)
* - `{...}`: an object with inline babel options
*
* @default undefined does NOT use babel
*/
babelConfig?: boolean | string | BabelConfig
// should this be kept in here? it has nothing to do with TS after all...
/**
* Kept for backward compatibility to handle __TRANSFORM_HTML__
* Any file which will match this regex will be transpiled as a module
* exporting the content of the file as a string
*/
stringifyContentPathRegex?: string | RegExp
/**
* Tell `ts-jest` to transform codes to ESM format. This only works in combination with `jest-runtime` ESM option
* `supportsStaticESM` true which is passed into Jest transformer
*/
useESM?: boolean
}
/**
* For transformers which extends `ts-jest`
* @deprecated use `JestConfigWithTsJest` instead
*/
export interface ProjectConfigTsJest extends Config.ProjectConfig {
globals: GlobalConfigTsJest
}
/**
* @deprecated use `JestConfigWithTsJest` instead
*/
export interface TransformOptionsTsJest extends TransformOptions {
config: ProjectConfigTsJest
}
/**
* For typings in `jest.config.ts`
* @deprecated use `JestConfigWithTsJest` instead
*/
export interface GlobalConfigTsJest extends Config.ConfigGlobals {
'ts-jest': TsJestGlobalOptions
}
/**
* @deprecated use `JestConfigWithTsJest` instead
*/
export interface InitialOptionsTsJest extends Config.InitialOptions {
globals?: GlobalConfigTsJest
}
type TsJestTransformerOptions = TsJestGlobalOptions
export interface JestConfigWithTsJest extends Partial<Omit<Config.ProjectConfig, 'transform'>> {
transform: {
[regex: string]: 'ts-jest' | ['ts-jest', TsJestTransformerOptions] | string | [string, Record<string, unknown>]
}
}
export type StringMap = Map<string, string>
/**
* @internal
*/
export interface DepGraphInfo {
fileContent: string
resolvedModuleNames: string[]
}
export interface TsJestCompileOptions {
depGraphs: Map<string, DepGraphInfo>
watchMode: boolean
supportsStaticESM: boolean
}
export interface CompiledOutput extends TransformedSource {
diagnostics?: _ts.Diagnostic[]
}
export interface CompilerInstance {
getResolvedModules(fileContent: string, fileName: string, runtimeCacheFS: StringMap): string[]
getCompiledOutput(fileContent: string, fileName: string, options: TsJestCompileOptions): CompiledOutput
}
export interface TsCompilerInstance extends CompilerInstance {
configSet: ConfigSet
program: _ts.Program | undefined
}
export interface AstTransformerDesc<T = Record<string, unknown>> {
name: string
version: number
factory(
tsCompiler: TsCompilerInstance,
opts?: T,
): _ts.TransformerFactory<_ts.SourceFile> | _ts.TransformerFactory<_ts.Bundle | _ts.SourceFile>
options?: T
}
export interface TsJestAstTransformer {
before: AstTransformerDesc[]
after: AstTransformerDesc[]
afterDeclarations: AstTransformerDesc[]
}