UNPKG

2.32 kBTypeScriptView Raw
1/**
2 * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7import type { Config } from '@jest/types';
8import type { DuplicatesSet, HTypeValue, MockData, ModuleMapData, RawModuleMap } from './types';
9declare type ValueType<T> = T extends Map<string, infer V> ? V : never;
10export declare type SerializableModuleMap = {
11 duplicates: ReadonlyArray<[string, [string, [string, [string, number]]]]>;
12 map: ReadonlyArray<[string, ValueType<ModuleMapData>]>;
13 mocks: ReadonlyArray<[string, ValueType<MockData>]>;
14 rootDir: Config.Path;
15};
16export default class ModuleMap {
17 static DuplicateHasteCandidatesError: typeof DuplicateHasteCandidatesError;
18 private readonly _raw;
19 private json;
20 private static mapToArrayRecursive;
21 private static mapFromArrayRecursive;
22 constructor(raw: RawModuleMap);
23 getModule(name: string, platform?: string | null, supportsNativePlatform?: boolean | null, type?: HTypeValue | null): Config.Path | null;
24 getPackage(name: string, platform: string | null | undefined, _supportsNativePlatform: boolean | null): Config.Path | null;
25 getMockModule(name: string): Config.Path | undefined;
26 getRawModuleMap(): RawModuleMap;
27 toJSON(): SerializableModuleMap;
28 static fromJSON(serializableModuleMap: SerializableModuleMap): ModuleMap;
29 /**
30 * When looking up a module's data, we walk through each eligible platform for
31 * the query. For each platform, we want to check if there are known
32 * duplicates for that name+platform pair. The duplication logic normally
33 * removes elements from the `map` object, but we want to check upfront to be
34 * extra sure. If metadata exists both in the `duplicates` object and the
35 * `map`, this would be a bug.
36 */
37 private _getModuleMetadata;
38 private _assertNoDuplicates;
39 static create(rootDir: Config.Path): ModuleMap;
40}
41declare class DuplicateHasteCandidatesError extends Error {
42 hasteName: string;
43 platform: string | null;
44 supportsNativePlatform: boolean;
45 duplicatesSet: DuplicatesSet;
46 constructor(name: string, platform: string, supportsNativePlatform: boolean, duplicatesSet: DuplicatesSet);
47}
48export {};