/
types.ts
197 lines (176 loc) · 6.02 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
import { TransformedSource, Transformer } from '@jest/transform/build/types'
import * as _babel from 'babel__core'
import { CompilerOptions, SourceFile, TransformerFactory } from 'typescript'
// tslint:disable-next-line:no-duplicate-imports
import * as _ts from 'typescript'
import { ConfigSet } from './config/config-set'
export type TBabelCore = typeof _babel
export type TTypeScript = typeof _ts
export type TBabelJest = Required<Transformer>
export type BabelJestTransformer = {
[K in Exclude<keyof Transformer, 'createTransformer'>]: Exclude<Transformer[K], undefined>
}
export type BabelConfig = _babel.TransformOptions
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
*/
tsConfig?: boolean | string | CompilerOptions
/**
* packageJson. It can be:
* - `true` (or `undefined`, it's the default): use default package.json file
* - `path/to/package.json`: path to a specific package.json file (<rootDir> can be used)
* - `{...}`: contents of a package.json
*/
packageJson?: boolean | string | object
/**
* Whether to compile files as isolated modules (disables some features and type-checking, default to `false`):
*/
isolatedModules?: boolean
/**
* Compiler to use (default to 'typescript'):
*/
compiler?: string
/**
* Custom transformers (mostly used by jest presets)
*/
astTransformers?: string[]
/**
* 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
*/
diagnostics?:
| boolean
| {
pretty?: boolean
ignoreCodes?: number | string | (number | string)[]
pathRegex?: RegExp | string
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
*/
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
}
interface TsJestConfig$tsConfig$file {
kind: 'file'
value: string | undefined
}
interface TsJestConfig$tsConfig$inline {
kind: 'inline'
value: CompilerOptions
}
type TsJestConfig$tsConfig = TsJestConfig$tsConfig$file | TsJestConfig$tsConfig$inline | undefined
interface TsJestConfig$diagnostics {
pretty: boolean
ignoreCodes: number[]
pathRegex?: string | undefined
throws: boolean
}
interface TsJestConfig$babelConfig$file {
kind: 'file'
value: string | undefined
}
interface TsJestConfig$babelConfig$inline {
kind: 'inline'
value: BabelConfig
}
type TsJestConfig$babelConfig = TsJestConfig$babelConfig$file | TsJestConfig$babelConfig$inline | undefined
interface TsJestConfig$packageJson$file {
kind: 'file'
value: string | undefined
}
interface TsJestConfig$packageJson$inline {
kind: 'inline'
value: any
}
type TsJestConfig$packageJson = TsJestConfig$packageJson$file | TsJestConfig$packageJson$inline | undefined
type TsJestConfig$stringifyContentPathRegex = string | undefined
export interface TsJestConfig {
tsConfig: TsJestConfig$tsConfig
packageJson: TsJestConfig$packageJson
isolatedModules: boolean
compiler: string
diagnostics: TsJestConfig$diagnostics
babelConfig: TsJestConfig$babelConfig
transformers: string[]
// to deprecate / deprecated === === ===
stringifyContentPathRegex: TsJestConfig$stringifyContentPathRegex
}
export interface TsJestHooksMap {
afterProcess?(args: any[], result: string | TransformedSource): string | TransformedSource | void
}
/**
* @internal
*/
export type ModulePatcher<T = any> = (module: T) => T
/**
* Common TypeScript interfaces between versions.
*/
export interface TSCommon {
version: typeof _ts.version
sys: typeof _ts.sys
ScriptSnapshot: typeof _ts.ScriptSnapshot
displayPartsToString: typeof _ts.displayPartsToString
createLanguageService: typeof _ts.createLanguageService
getDefaultLibFilePath: typeof _ts.getDefaultLibFilePath
getPreEmitDiagnostics: typeof _ts.getPreEmitDiagnostics
flattenDiagnosticMessageText: typeof _ts.flattenDiagnosticMessageText
transpileModule: typeof _ts.transpileModule
ModuleKind: typeof _ts.ModuleKind
ScriptTarget: typeof _ts.ScriptTarget
findConfigFile: typeof _ts.findConfigFile
readConfigFile: typeof _ts.readConfigFile
parseJsonConfigFileContent: typeof _ts.parseJsonConfigFileContent
formatDiagnostics: typeof _ts.formatDiagnostics
formatDiagnosticsWithColorAndContext: typeof _ts.formatDiagnosticsWithColorAndContext
}
/**
* Track the project information.
* @internal
*/
export interface MemoryCache {
contents: { [path: string]: string | undefined }
versions: { [path: string]: number | undefined }
outputs: { [path: string]: string }
}
/**
* Information retrieved from type info check.
*/
export interface TypeInfo {
name: string
comment: string
}
export interface TsCompiler {
cwd: string
extensions: string[]
cachedir: string | undefined
ts: TSCommon
compile(code: string, fileName: string, lineOffset?: number): string
getTypeInfo(code: string, fileName: string, position: number): TypeInfo
}
export interface AstTransformerDesc {
name: string
version: number
factory(cs: ConfigSet): TransformerFactory<SourceFile>
}
export interface IPackageJson {
main: string
}