Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: migrate jest-resolve-dependencies to ESM #10876

Merged
merged 1 commit into from Nov 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Expand Up @@ -36,8 +36,9 @@
- `[jest-config]` [**BREAKING**] Remove `enabledTestsMap` config, use `filter` instead ([#10787](https://github.com/facebook/jest/pull/10787))
- `[jest-console]` [**BREAKING**] Move `root` into `config` and take `GlobalConfig` as mandatory parameter for `getConsoleOutput` ([#10126](https://github.com/facebook/jest/pull/10126))
- `[jest-fake-timers]` Clarify global behavior of `jest.useFakeTimers` and `jest.useRealTimers` ([#10867](https://github.com/facebook/jest/pull/10867))
- `[jest-resolve]` [**BREAKING**] Migrate to ESM ([#10688](https://github.com/facebook/jest/pull/10688))
- `[jest-repl, jest-runtime]` [**BREAKING**] Move the `jest-runtime` CLI into `jest-repl` ([#10016](https://github.com/facebook/jest/pull/10016))
- `[jest-resolve]` [**BREAKING**] Migrate to ESM ([#10688](https://github.com/facebook/jest/pull/10688))
- `[jest-resolve-dependencies]` [**BREAKING**] Migrate to ESM ([#10876](https://github.com/facebook/jest/pull/10876))
- `[jest-util]` No longer checking `enumerable` when adding `process.domain` ([#10862](https://github.com/facebook/jest/pull/10862))

### Performance
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-core/src/SearchSource.ts
Expand Up @@ -12,7 +12,7 @@ import type {Config} from '@jest/types';
import type {ChangedFiles} from 'jest-changed-files';
import {replaceRootDirInPath} from 'jest-config';
import {escapePathForRegex} from 'jest-regex-util';
import DependencyResolver = require('jest-resolve-dependencies');
import {DependencyResolver} from 'jest-resolve-dependencies';
import type {Test} from 'jest-runner';
import type {Context} from 'jest-runtime';
import {buildSnapshotResolver} from 'jest-snapshot';
Expand Down
Expand Up @@ -9,9 +9,9 @@ import {tmpdir} from 'os';
import * as path from 'path';
import {makeProjectConfig} from '@jest/test-utils';
import type {Config} from '@jest/types';
import Resolver from 'jest-resolve';
import type Resolver from 'jest-resolve';
import {buildSnapshotResolver} from 'jest-snapshot';
import DependencyResolver from '../index';
import {DependencyResolver} from '../index';

const maxWorkers = 1;
let dependencyResolver: DependencyResolver;
Expand Down
22 changes: 9 additions & 13 deletions packages/jest-resolve-dependencies/src/index.ts
Expand Up @@ -11,18 +11,16 @@ import type {FS as HasteFS} from 'jest-haste-map';
import type {ResolveModuleConfig, default as Resolver} from 'jest-resolve';
import {SnapshotResolver, isSnapshotPath} from 'jest-snapshot';

declare namespace DependencyResolver {
export type ResolvedModule = {
file: Config.Path;
dependencies: Array<Config.Path>;
};
}
export type ResolvedModule = {
file: Config.Path;
dependencies: Array<Config.Path>;
};

/**
* DependencyResolver is used to resolve the direct dependencies of a module or
* to retrieve a list of all transitive inverse dependencies.
*/
class DependencyResolver {
export class DependencyResolver {
private _hasteFS: HasteFS;
private _resolver: Resolver;
private _snapshotResolver: SnapshotResolver;
Expand Down Expand Up @@ -106,18 +104,18 @@ class DependencyResolver {
paths: Set<Config.Path>,
filter: (file: Config.Path) => boolean,
options?: ResolveModuleConfig,
): Array<DependencyResolver.ResolvedModule> {
): Array<ResolvedModule> {
if (!paths.size) {
return [];
}

const collectModules = (
related: Set<Config.Path>,
moduleMap: Array<DependencyResolver.ResolvedModule>,
moduleMap: Array<ResolvedModule>,
changed: Set<Config.Path>,
) => {
const visitedModules = new Set();
const result: Array<DependencyResolver.ResolvedModule> = [];
const result: Array<ResolvedModule> = [];
while (changed.size) {
changed = new Set(
moduleMap.reduce<Array<Config.Path>>((acc, module) => {
Expand Down Expand Up @@ -157,7 +155,7 @@ class DependencyResolver {
}
}
}
const modules: Array<DependencyResolver.ResolvedModule> = [];
const modules: Array<ResolvedModule> = [];
for (const file of this._hasteFS.getAbsoluteFileIterator()) {
modules.push({
dependencies: this.resolve(file, options),
Expand All @@ -177,5 +175,3 @@ class DependencyResolver {
);
}
}

export = DependencyResolver;