1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | import type {IModuleMap} from 'jest-haste-map';
|
8 |
|
9 | export declare type AsyncResolver = (
|
10 | path: string,
|
11 | options: ResolverOptions,
|
12 | ) => Promise<string>;
|
13 |
|
14 | declare function cachedShouldLoadAsEsm(
|
15 | path: string,
|
16 | extensionsToTreatAsEsm: Array<string>,
|
17 | ): boolean;
|
18 |
|
19 | declare const defaultResolver: SyncResolver;
|
20 |
|
21 | export declare type FindNodeModuleConfig = {
|
22 | basedir: string;
|
23 | conditions?: Array<string>;
|
24 | extensions?: Array<string>;
|
25 | moduleDirectory?: Array<string>;
|
26 | paths?: Array<string>;
|
27 | resolver?: string | null;
|
28 | rootDir?: string;
|
29 | throwIfNotFound?: boolean;
|
30 | };
|
31 |
|
32 | export declare type JestResolver = ResolverSyncObject | ResolverAsyncObject;
|
33 |
|
34 | declare interface JSONObject {
|
35 | [key: string]: JSONValue;
|
36 | }
|
37 |
|
38 | declare type JSONValue =
|
39 | | string
|
40 | | number
|
41 | | boolean
|
42 | | JSONObject
|
43 | | Array<JSONValue>;
|
44 |
|
45 | declare type ModuleNameMapperConfig = {
|
46 | regex: RegExp;
|
47 | moduleName: string | Array<string>;
|
48 | };
|
49 |
|
50 | declare class ModuleNotFoundError extends Error {
|
51 | code: string;
|
52 | hint?: string;
|
53 | requireStack?: Array<string>;
|
54 | siblingWithSimilarExtensionFound?: boolean;
|
55 | moduleName?: string;
|
56 | private _originalMessage?;
|
57 | constructor(message: string, moduleName?: string);
|
58 | buildMessage(rootDir: string): void;
|
59 | static duckType(error: ModuleNotFoundError): ModuleNotFoundError;
|
60 | }
|
61 |
|
62 | /**
|
63 | * Allows transforming parsed `package.json` contents.
|
64 | *
|
65 | * @param pkg - Parsed `package.json` contents.
|
66 | * @param file - Path to `package.json` file.
|
67 | * @param dir - Directory that contains the `package.json`.
|
68 | *
|
69 | * @returns Transformed `package.json` contents.
|
70 | */
|
71 | export declare type PackageFilter = (
|
72 | pkg: PackageJSON,
|
73 | file: string,
|
74 | dir: string,
|
75 | ) => PackageJSON;
|
76 |
|
77 | export declare type PackageJSON = JSONObject;
|
78 |
|
79 | /**
|
80 | * Allows transforming a path within a package.
|
81 | *
|
82 | * @param pkg - Parsed `package.json` contents.
|
83 | * @param path - Path being resolved.
|
84 | * @param relativePath - Path relative from the `package.json` location.
|
85 | *
|
86 | * @returns Relative path that will be joined from the `package.json` location.
|
87 | */
|
88 | export declare type PathFilter = (
|
89 | pkg: PackageJSON,
|
90 | path: string,
|
91 | relativePath: string,
|
92 | ) => string;
|
93 |
|
94 | export declare type ResolveModuleConfig = {
|
95 | conditions?: Array<string>;
|
96 | skipNodeResolution?: boolean;
|
97 | paths?: Array<string>;
|
98 | };
|
99 |
|
100 | declare class Resolver {
|
101 | private readonly _options;
|
102 | private readonly _moduleMap;
|
103 | private readonly _moduleIDCache;
|
104 | private readonly _moduleNameCache;
|
105 | private readonly _modulePathCache;
|
106 | private readonly _supportsNativePlatform;
|
107 | constructor(moduleMap: IModuleMap, options: ResolverConfig);
|
108 | static ModuleNotFoundError: typeof ModuleNotFoundError;
|
109 | static tryCastModuleNotFoundError(error: unknown): ModuleNotFoundError | null;
|
110 | static clearDefaultResolverCache(): void;
|
111 | static findNodeModule(
|
112 | path: string,
|
113 | options: FindNodeModuleConfig,
|
114 | ): string | null;
|
115 | static findNodeModuleAsync(
|
116 | path: string,
|
117 | options: FindNodeModuleConfig,
|
118 | ): Promise<string | null>;
|
119 | static unstable_shouldLoadAsEsm: typeof cachedShouldLoadAsEsm;
|
120 | resolveModuleFromDirIfExists(
|
121 | dirname: string,
|
122 | moduleName: string,
|
123 | options?: ResolveModuleConfig,
|
124 | ): string | null;
|
125 | resolveModuleFromDirIfExistsAsync(
|
126 | dirname: string,
|
127 | moduleName: string,
|
128 | options?: ResolveModuleConfig,
|
129 | ): Promise<string | null>;
|
130 | resolveModule(
|
131 | from: string,
|
132 | moduleName: string,
|
133 | options?: ResolveModuleConfig,
|
134 | ): string;
|
135 | resolveModuleAsync(
|
136 | from: string,
|
137 | moduleName: string,
|
138 | options?: ResolveModuleConfig,
|
139 | ): Promise<string>;
|
140 | /**
|
141 | * _prepareForResolution is shared between the sync and async module resolution
|
142 | * methods, to try to keep them as DRY as possible.
|
143 | */
|
144 | private _prepareForResolution;
|
145 | /**
|
146 | * _getHasteModulePath attempts to return the path to a haste module.
|
147 | */
|
148 | private _getHasteModulePath;
|
149 | private _throwModNotFoundError;
|
150 | private _getMapModuleName;
|
151 | private _isAliasModule;
|
152 | isCoreModule(moduleName: string): boolean;
|
153 | getModule(name: string): string | null;
|
154 | getModulePath(from: string, moduleName: string): string;
|
155 | getPackage(name: string): string | null;
|
156 | getMockModule(from: string, name: string): string | null;
|
157 | getMockModuleAsync(from: string, name: string): Promise<string | null>;
|
158 | getModulePaths(from: string): Array<string>;
|
159 | getGlobalPaths(moduleName?: string): Array<string>;
|
160 | getModuleID(
|
161 | virtualMocks: Map<string, boolean>,
|
162 | from: string,
|
163 | moduleName?: string,
|
164 | options?: ResolveModuleConfig,
|
165 | ): string;
|
166 | getModuleIDAsync(
|
167 | virtualMocks: Map<string, boolean>,
|
168 | from: string,
|
169 | moduleName?: string,
|
170 | options?: ResolveModuleConfig,
|
171 | ): Promise<string>;
|
172 | private _getModuleType;
|
173 | private _getAbsolutePath;
|
174 | private _getAbsolutePathAsync;
|
175 | private _getMockPath;
|
176 | private _getMockPathAsync;
|
177 | private _getVirtualMockPath;
|
178 | private _getVirtualMockPathAsync;
|
179 | private _isModuleResolved;
|
180 | private _isModuleResolvedAsync;
|
181 | resolveStubModuleName(from: string, moduleName: string): string | null;
|
182 | resolveStubModuleNameAsync(
|
183 | from: string,
|
184 | moduleName: string,
|
185 | ): Promise<string | null>;
|
186 | }
|
187 | export default Resolver;
|
188 |
|
189 | declare type ResolverAsyncObject = {
|
190 | sync?: SyncResolver;
|
191 | async: AsyncResolver;
|
192 | };
|
193 |
|
194 | declare type ResolverConfig = {
|
195 | defaultPlatform?: string | null;
|
196 | extensions: Array<string>;
|
197 | hasCoreModules: boolean;
|
198 | moduleDirectories: Array<string>;
|
199 | moduleNameMapper?: Array<ModuleNameMapperConfig> | null;
|
200 | modulePaths?: Array<string>;
|
201 | platforms?: Array<string>;
|
202 | resolver?: string | null;
|
203 | rootDir: string;
|
204 | };
|
205 |
|
206 | export declare type ResolverOptions = {
|
207 |
|
208 | basedir: string;
|
209 |
|
210 | conditions?: Array<string>;
|
211 |
|
212 | defaultResolver: typeof defaultResolver;
|
213 |
|
214 | extensions?: Array<string>;
|
215 | |
216 |
|
217 |
|
218 |
|
219 |
|
220 |
|
221 | moduleDirectory?: Array<string>;
|
222 | |
223 |
|
224 |
|
225 |
|
226 |
|
227 |
|
228 | paths?: Array<string>;
|
229 |
|
230 | packageFilter?: PackageFilter;
|
231 |
|
232 | pathFilter?: PathFilter;
|
233 |
|
234 | rootDir?: string;
|
235 | };
|
236 |
|
237 | declare type ResolverSyncObject = {
|
238 | sync: SyncResolver;
|
239 | async?: AsyncResolver;
|
240 | };
|
241 |
|
242 |
|
243 |
|
244 |
|
245 |
|
246 |
|
247 |
|
248 |
|
249 |
|
250 | export declare const resolveRunner: (
|
251 | resolver: string | undefined | null,
|
252 | {
|
253 | filePath,
|
254 | rootDir,
|
255 | requireResolveFunction,
|
256 | }: {
|
257 | filePath: string;
|
258 | rootDir: string;
|
259 | requireResolveFunction: (moduleName: string) => string;
|
260 | },
|
261 | ) => string;
|
262 |
|
263 | export declare const resolveSequencer: (
|
264 | resolver: string | undefined | null,
|
265 | {
|
266 | filePath,
|
267 | rootDir,
|
268 | requireResolveFunction,
|
269 | }: {
|
270 | filePath: string;
|
271 | rootDir: string;
|
272 | requireResolveFunction: (moduleName: string) => string;
|
273 | },
|
274 | ) => string;
|
275 |
|
276 |
|
277 |
|
278 |
|
279 |
|
280 |
|
281 |
|
282 |
|
283 |
|
284 | export declare const resolveTestEnvironment: ({
|
285 | rootDir,
|
286 | testEnvironment: filePath,
|
287 | requireResolveFunction,
|
288 | }: {
|
289 | rootDir: string;
|
290 | testEnvironment: string;
|
291 | requireResolveFunction: (moduleName: string) => string;
|
292 | }) => string;
|
293 |
|
294 |
|
295 |
|
296 |
|
297 |
|
298 |
|
299 |
|
300 |
|
301 |
|
302 | export declare const resolveWatchPlugin: (
|
303 | resolver: string | undefined | null,
|
304 | {
|
305 | filePath,
|
306 | rootDir,
|
307 | requireResolveFunction,
|
308 | }: {
|
309 | filePath: string;
|
310 | rootDir: string;
|
311 | requireResolveFunction: (moduleName: string) => string;
|
312 | },
|
313 | ) => string;
|
314 |
|
315 | export declare type SyncResolver = (
|
316 | path: string,
|
317 | options: ResolverOptions,
|
318 | ) => string;
|
319 |
|
320 | export {};
|