1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | import type {Config} from '@jest/types';
|
8 | import type {EncodedSourceMap} from '@jridgewell/trace-mapping';
|
9 | import type {TransformTypes} from '@jest/types';
|
10 |
|
11 | export declare interface AsyncTransformer<TransformerConfig = unknown> {
|
12 | |
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | canInstrument?: boolean;
|
19 | getCacheKey?: (
|
20 | sourceText: string,
|
21 | sourcePath: string,
|
22 | options: TransformOptions<TransformerConfig>,
|
23 | ) => string;
|
24 | getCacheKeyAsync?: (
|
25 | sourceText: string,
|
26 | sourcePath: string,
|
27 | options: TransformOptions<TransformerConfig>,
|
28 | ) => Promise<string>;
|
29 | process?: (
|
30 | sourceText: string,
|
31 | sourcePath: string,
|
32 | options: TransformOptions<TransformerConfig>,
|
33 | ) => TransformedSource;
|
34 | processAsync: (
|
35 | sourceText: string,
|
36 | sourcePath: string,
|
37 | options: TransformOptions<TransformerConfig>,
|
38 | ) => Promise<TransformedSource>;
|
39 | }
|
40 |
|
41 | export declare interface CallerTransformOptions {
|
42 | supportsDynamicImport: boolean;
|
43 | supportsExportNamespaceFrom: boolean;
|
44 | supportsStaticESM: boolean;
|
45 | supportsTopLevelAwait: boolean;
|
46 | }
|
47 |
|
48 | export declare function createScriptTransformer(
|
49 | config: Config.ProjectConfig,
|
50 | cacheFS?: StringMap,
|
51 | ): Promise<ScriptTransformer>;
|
52 |
|
53 | export declare function createTranspilingRequire(
|
54 | config: Config.ProjectConfig,
|
55 | ): Promise<
|
56 | <TModuleType = unknown>(
|
57 | resolverPath: string,
|
58 | applyInteropRequireDefault?: boolean,
|
59 | ) => Promise<TModuleType>
|
60 | >;
|
61 |
|
62 | declare interface ErrorWithCodeFrame extends Error {
|
63 | codeFrame?: string;
|
64 | }
|
65 |
|
66 | declare interface FixedRawSourceMap extends Omit<EncodedSourceMap, 'version'> {
|
67 | version: number;
|
68 | }
|
69 |
|
70 | export declare function handlePotentialSyntaxError(
|
71 | e: ErrorWithCodeFrame,
|
72 | ): ErrorWithCodeFrame;
|
73 |
|
74 | declare interface ReducedTransformOptions extends CallerTransformOptions {
|
75 | instrument: boolean;
|
76 | }
|
77 |
|
78 | declare interface RequireAndTranspileModuleOptions
|
79 | extends ReducedTransformOptions {
|
80 | applyInteropRequireDefault: boolean;
|
81 | }
|
82 |
|
83 | export declare type ScriptTransformer = ScriptTransformer_2;
|
84 |
|
85 | declare class ScriptTransformer_2 {
|
86 | private readonly _config;
|
87 | private readonly _cacheFS;
|
88 | private readonly _cache;
|
89 | private readonly _transformCache;
|
90 | private _transformsAreLoaded;
|
91 | constructor(_config: Config.ProjectConfig, _cacheFS: StringMap);
|
92 | private _buildCacheKeyFromFileInfo;
|
93 | private _buildTransformCacheKey;
|
94 | private _getCacheKey;
|
95 | private _getCacheKeyAsync;
|
96 | private _createCachedFilename;
|
97 | private _getFileCachePath;
|
98 | private _getFileCachePathAsync;
|
99 | private _getTransformPatternAndPath;
|
100 | private _getTransformPath;
|
101 | loadTransformers(): Promise<void>;
|
102 | private _getTransformer;
|
103 | private _instrumentFile;
|
104 | private _buildTransformResult;
|
105 | transformSource(
|
106 | filepath: string,
|
107 | content: string,
|
108 | options: ReducedTransformOptions,
|
109 | ): TransformResult;
|
110 | transformSourceAsync(
|
111 | filepath: string,
|
112 | content: string,
|
113 | options: ReducedTransformOptions,
|
114 | ): Promise<TransformResult>;
|
115 | private _transformAndBuildScriptAsync;
|
116 | private _transformAndBuildScript;
|
117 | transformAsync(
|
118 | filename: string,
|
119 | options: TransformationOptions,
|
120 | fileSource?: string,
|
121 | ): Promise<TransformResult>;
|
122 | transform(
|
123 | filename: string,
|
124 | options: TransformationOptions,
|
125 | fileSource?: string,
|
126 | ): TransformResult;
|
127 | transformJson(
|
128 | filename: string,
|
129 | options: TransformationOptions,
|
130 | fileSource: string,
|
131 | ): string;
|
132 | requireAndTranspileModule<ModuleType = unknown>(
|
133 | moduleName: string,
|
134 | callback?: (module: ModuleType) => void | Promise<void>,
|
135 | options?: RequireAndTranspileModuleOptions,
|
136 | ): Promise<ModuleType>;
|
137 | shouldTransform(filename: string): boolean;
|
138 | }
|
139 |
|
140 | export declare function shouldInstrument(
|
141 | filename: string,
|
142 | options: ShouldInstrumentOptions,
|
143 | config: Config.ProjectConfig,
|
144 | loadedFilenames?: Array<string>,
|
145 | ): boolean;
|
146 |
|
147 | export declare interface ShouldInstrumentOptions
|
148 | extends Pick<
|
149 | Config.GlobalConfig,
|
150 | 'collectCoverage' | 'collectCoverageFrom' | 'coverageProvider'
|
151 | > {
|
152 | changedFiles?: Set<string>;
|
153 | sourcesRelatedToTestsInChangedFiles?: Set<string>;
|
154 | }
|
155 |
|
156 | declare type StringMap = Map<string, string>;
|
157 |
|
158 | export declare interface SyncTransformer<TransformerConfig = unknown> {
|
159 | |
160 |
|
161 |
|
162 |
|
163 |
|
164 |
|
165 | canInstrument?: boolean;
|
166 | getCacheKey?: (
|
167 | sourceText: string,
|
168 | sourcePath: string,
|
169 | options: TransformOptions<TransformerConfig>,
|
170 | ) => string;
|
171 | getCacheKeyAsync?: (
|
172 | sourceText: string,
|
173 | sourcePath: string,
|
174 | options: TransformOptions<TransformerConfig>,
|
175 | ) => Promise<string>;
|
176 | process: (
|
177 | sourceText: string,
|
178 | sourcePath: string,
|
179 | options: TransformOptions<TransformerConfig>,
|
180 | ) => TransformedSource;
|
181 | processAsync?: (
|
182 | sourceText: string,
|
183 | sourcePath: string,
|
184 | options: TransformOptions<TransformerConfig>,
|
185 | ) => Promise<TransformedSource>;
|
186 | }
|
187 |
|
188 | export declare interface TransformationOptions
|
189 | extends ShouldInstrumentOptions,
|
190 | CallerTransformOptions {
|
191 | isInternalModule?: boolean;
|
192 | }
|
193 |
|
194 | export declare type TransformedSource = {
|
195 | code: string;
|
196 | map?: FixedRawSourceMap | string | null;
|
197 | };
|
198 |
|
199 |
|
200 |
|
201 |
|
202 |
|
203 |
|
204 |
|
205 |
|
206 |
|
207 | declare type Transformer_2<TransformerConfig = unknown> =
|
208 | | SyncTransformer<TransformerConfig>
|
209 | | AsyncTransformer<TransformerConfig>;
|
210 | export {Transformer_2 as Transformer};
|
211 |
|
212 | export declare type TransformerCreator<
|
213 | X extends Transformer_2<TransformerConfig>,
|
214 | TransformerConfig = unknown,
|
215 | > = (transformerConfig?: TransformerConfig) => X | Promise<X>;
|
216 |
|
217 |
|
218 |
|
219 |
|
220 |
|
221 |
|
222 | export declare type TransformerFactory<X extends Transformer_2> = {
|
223 | createTransformer: TransformerCreator<X>;
|
224 | };
|
225 |
|
226 | export declare interface TransformOptions<TransformerConfig = unknown>
|
227 | extends ReducedTransformOptions {
|
228 |
|
229 | cacheFS: StringMap;
|
230 |
|
231 | config: Config.ProjectConfig;
|
232 |
|
233 | configString: string;
|
234 |
|
235 | transformerConfig: TransformerConfig;
|
236 | }
|
237 |
|
238 | export declare type TransformResult = TransformTypes.TransformResult;
|
239 |
|
240 | export {};
|