Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
DiZy committed May 18, 2021
1 parent c7a7fd8 commit 41287a3
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 48 deletions.
14 changes: 2 additions & 12 deletions packages/jest-haste-map/src/ModuleMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,15 @@ import * as fastPath from './lib/fast_path';
import type {
DuplicatesSet,
HTypeValue,
MockData,
ModuleMapData,
IModuleMap,
ModuleMetaData,
RawModuleMap,
SerializableModuleMap,
} from './types';
import type {IModuleMap} from '.';

const EMPTY_OBJ: Record<string, ModuleMetaData> = {};
const EMPTY_MAP = new Map();

type ValueType<T> = T extends Map<string, infer V> ? V : never;

export type SerializableModuleMap = {
duplicates: ReadonlyArray<[string, [string, [string, [string, number]]]]>;
map: ReadonlyArray<[string, ValueType<ModuleMapData>]>;
mocks: ReadonlyArray<[string, ValueType<MockData>]>;
rootDir: Config.Path;
};

export default class ModuleMap implements IModuleMap<SerializableModuleMap> {
static DuplicateHasteCandidatesError: typeof DuplicateHasteCandidatesError;
private readonly _raw: RawModuleMap;
Expand Down
41 changes: 6 additions & 35 deletions packages/jest-haste-map/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {escapePathForRegex} from 'jest-regex-util';
import serializer from 'jest-serializer';
import {Worker} from 'jest-worker';
import HasteFS from './HasteFS';
import HasteModuleMap, {SerializableModuleMap} from './ModuleMap';
import HasteModuleMap from './ModuleMap';
import H from './constants';
import nodeCrawl = require('./crawlers/node');
import watchmanCrawl = require('./crawlers/watchman');
Expand All @@ -32,14 +32,14 @@ import type {
EventsQueue,
FileData,
FileMetaData,
HTypeValue,
HasteMapStatic,
HasteRegExp,
InternalHasteMap,
HasteMap as InternalHasteMapObject,
MockData,
ModuleMapData,
ModuleMetaData,
RawModuleMap,
SerializableModuleMap,
WorkerMetadata,
} from './types';
import FSEventsWatcher = require('./watchers/FSEventsWatcher');
Expand Down Expand Up @@ -109,7 +109,8 @@ type Watcher = {
type WorkerInterface = {worker: typeof worker; getSha1: typeof getSha1};

export {default as ModuleMap} from './ModuleMap';
export type {SerializableModuleMap} from './ModuleMap';
export type {SerializableModuleMap} from './types';
export type {IModuleMap} from './types';
export type {default as FS} from './HasteFS';
export type {ChangeEvent, HasteMap as HasteMapObject} from './types';

Expand All @@ -135,36 +136,6 @@ function invariant(condition: unknown, message?: string): asserts condition {
}
}

export interface IModuleMap<S = SerializableModuleMap> {
getModule(
name: string,
platform?: string | null,
supportsNativePlatform?: boolean | null,
type?: HTypeValue | null,
): Config.Path | null;

getPackage(
name: string,
platform: string | null | undefined,
_supportsNativePlatform: boolean | null,
): Config.Path | null;

getMockModule(name: string): Config.Path | undefined;

getRawModuleMap(): RawModuleMap;

toJSON(): S;
}

export type HasteMapStatic<S = SerializableModuleMap> = {
getCacheFilePath(
tmpdir: Config.Path,
name: string,
...extra: Array<string>
): string;
getModuleMapFromJSON(json: S): IModuleMap<S>;
};

/**
* HasteMap is a JavaScript implementation of Facebook's haste module system.
*
Expand Down Expand Up @@ -256,7 +227,7 @@ export default class HasteMap extends EventEmitter {
if (config.haste.hasteMapModulePath) {
return require(config.haste.hasteMapModulePath);
}
return this;
return HasteMap;
}

static create(options: Options): HasteMap {
Expand Down
40 changes: 39 additions & 1 deletion packages/jest-haste-map/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,45 @@ import type {Stats} from 'graceful-fs';
import type {Config} from '@jest/types';
import type HasteFS from './HasteFS';
import type ModuleMap from './ModuleMap';
import type {IModuleMap} from '.';

type ValueType<T> = T extends Map<string, infer V> ? V : never;

export type SerializableModuleMap = {
duplicates: ReadonlyArray<[string, [string, [string, [string, number]]]]>;
map: ReadonlyArray<[string, ValueType<ModuleMapData>]>;
mocks: ReadonlyArray<[string, ValueType<MockData>]>;
rootDir: Config.Path;
};

export interface IModuleMap<S = SerializableModuleMap> {
getModule(
name: string,
platform?: string | null,
supportsNativePlatform?: boolean | null,
type?: HTypeValue | null,
): Config.Path | null;

getPackage(
name: string,
platform: string | null | undefined,
_supportsNativePlatform: boolean | null,
): Config.Path | null;

getMockModule(name: string): Config.Path | undefined;

getRawModuleMap(): RawModuleMap;

toJSON(): S;
}

export type HasteMapStatic<S = SerializableModuleMap> = {
getCacheFilePath(
tmpdir: Config.Path,
name: string,
...extra: Array<string>
): string;
getModuleMapFromJSON(json: S): IModuleMap<S>;
};

export type IgnoreMatcher = (item: string) => boolean;

Expand Down

0 comments on commit 41287a3

Please sign in to comment.