Skip to content

Commit

Permalink
feat(jest-haste-map): add DependencyExtractor type
Browse files Browse the repository at this point in the history
  • Loading branch information
chentsulin committed Feb 23, 2022
1 parent 4e7f6ec commit e9abd9f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/jest-haste-map/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import normalizePathSep from './lib/normalizePathSep';
import type {
ChangeEvent,
CrawlerOptions,
DependencyExtractor,
EventsQueue,
FileData,
FileMetaData,
Expand Down Expand Up @@ -316,7 +317,7 @@ export default class HasteMap extends EventEmitter {
}

if (options.dependencyExtractor) {
const dependencyExtractor = await requireOrImportModule<any>(
const dependencyExtractor = await requireOrImportModule<DependencyExtractor>(
options.dependencyExtractor,
false,
);
Expand Down
5 changes: 5 additions & 0 deletions packages/jest-haste-map/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,8 @@ export type ChangeEvent = {
hasteFS: HasteFS;
moduleMap: ModuleMap;
};

export type DependencyExtractor = {
extract: (code: string, filePath: string, defaultExtract: DependencyExtractor['extract']) => Set<string>;
getCacheKey?: () => string;
};
4 changes: 2 additions & 2 deletions packages/jest-haste-map/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {requireOrImportModule} from 'jest-util';
import blacklist from './blacklist';
import H from './constants';
import * as dependencyExtractor from './lib/dependencyExtractor';
import type {HasteImpl, WorkerMessage, WorkerMetadata} from './types';
import type {DependencyExtractor, HasteImpl, WorkerMessage, WorkerMetadata} from './types';

const PACKAGE_JSON = path.sep + 'package.json';

Expand Down Expand Up @@ -75,7 +75,7 @@ export async function worker(data: WorkerMessage): Promise<WorkerMetadata> {
dependencies = Array.from(
data.dependencyExtractor
? (
await requireOrImportModule<any>(data.dependencyExtractor, false)
await requireOrImportModule<DependencyExtractor>(data.dependencyExtractor, false)
).extract(content, filePath, dependencyExtractor.extract)
: dependencyExtractor.extract(content),
);
Expand Down

0 comments on commit e9abd9f

Please sign in to comment.