Skip to content

Commit 3f14f80

Browse files
committed
chore: migrate jest-haste-map to ESM
1 parent 59ae078 commit 3f14f80

File tree

13 files changed

+32
-34
lines changed

13 files changed

+32
-34
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
- `[*]` [**BREAKING**] Add `exports` field to all `package.json`s ([#9921](https://github.com/facebook/jest/pull/9921))
3535
- `[*]` Make it easier for Jest's packages to use the VM escape hatch ([#10824](https://github.com/facebook/jest/pull/10824))
3636
- `[jest-config]` [**BREAKING**] Remove `enabledTestsMap` config, use `filter` instead ([#10787](https://github.com/facebook/jest/pull/10787))
37+
- `[jest-haste-map]` [**BREAKING**] Migrate to ESM
3738
- `[jest-resolve]` [**BREAKING**] Migrate to ESM ([#10688](https://github.com/facebook/jest/pull/10688))
3839
- `[jest-repl, jest-runtime]` [**BREAKING**] Move the `jest-runtime` CLI into `jest-repl` ([#10016](https://github.com/facebook/jest/pull/10016))
3940
- `[jest-util]` No longer checking `enumerable` when adding `process.domain` ([#10862](https://github.com/facebook/jest/pull/10862))

e2e/__tests__/hasteMapMockChanged.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import * as path from 'path';
9-
import JestHasteMap = require('jest-haste-map');
9+
import JestHasteMap from 'jest-haste-map';
1010
import {cleanup, writeFiles} from '../Utils';
1111

1212
// Directory must be here for Watchman to be enabled.

e2e/__tests__/hasteMapSha1.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import {tmpdir} from 'os';
99
import * as path from 'path';
10-
import JestHasteMap = require('jest-haste-map');
10+
import JestHasteMap from 'jest-haste-map';
1111
import {cleanup, writeFiles} from '../Utils';
1212

1313
const DIR = path.resolve(tmpdir(), 'haste_map_sha1');

e2e/__tests__/hasteMapSize.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import {tmpdir} from 'os';
99
import * as path from 'path';
1010
import {realpathSync} from 'graceful-fs';
11-
import HasteMap = require('jest-haste-map');
11+
import HasteMap from 'jest-haste-map';
1212
import {cleanup, writeFiles} from '../Utils';
1313

1414
const DIR = path.resolve(realpathSync.native(tmpdir()), 'haste_map_size');

packages/jest-core/src/__tests__/watchFileChanges.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import * as fs from 'graceful-fs';
1212
import rimraf = require('rimraf');
1313
import type {AggregatedResult} from '@jest/test-result';
1414
import {normalize} from 'jest-config';
15-
import HasteMap = require('jest-haste-map');
15+
import type HasteMap from 'jest-haste-map';
1616
import Runtime from 'jest-runtime';
1717
import {JestHook} from 'jest-watcher';
1818

packages/jest-core/src/cli/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type {AggregatedResult} from '@jest/test-result';
1313
import type {Config} from '@jest/types';
1414
import type {ChangedFilesPromise} from 'jest-changed-files';
1515
import {readConfigs} from 'jest-config';
16-
import HasteMap = require('jest-haste-map');
16+
import type HasteMap from 'jest-haste-map';
1717
import Runtime, {Context} from 'jest-runtime';
1818
import {createDirectory, preRunMessage} from 'jest-util';
1919
import TestWatcher from '../TestWatcher';

packages/jest-core/src/watch.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ import chalk = require('chalk');
1111
import exit = require('exit');
1212
import slash = require('slash');
1313
import type {Config} from '@jest/types';
14-
import HasteMap = require('jest-haste-map');
14+
import type {
15+
ChangeEvent as HasteChangeEvent,
16+
default as HasteMap,
17+
} from 'jest-haste-map';
1518
import {formatExecError} from 'jest-message-util';
1619
import Resolver from 'jest-resolve';
1720
import type {Context} from 'jest-runtime';
@@ -234,7 +237,7 @@ export default function watch(
234237
hasteMapInstances.forEach((hasteMapInstance, index) => {
235238
hasteMapInstance.on(
236239
'change',
237-
({eventsQueue, hasteFS, moduleMap}: HasteMap.HasteChangeEvent) => {
240+
({eventsQueue, hasteFS, moduleMap}: HasteChangeEvent) => {
238241
const validPaths = eventsQueue.filter(({filePath}) =>
239242
isValidPath(globalConfig, filePath),
240243
);

packages/jest-haste-map/src/__tests__/index.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ describe('HasteMap', () => {
192192
console.warn = jest.fn();
193193
console.error = jest.fn();
194194

195-
HasteMap = require('../');
195+
HasteMap = require('../').default;
196196
H = HasteMap.H;
197197

198198
getCacheFilePath = HasteMap.getCacheFilePath;
@@ -225,7 +225,7 @@ describe('HasteMap', () => {
225225

226226
it('creates valid cache file paths', () => {
227227
jest.resetModules();
228-
HasteMap = require('../');
228+
HasteMap = require('../').default;
229229

230230
expect(
231231
HasteMap.getCacheFilePath('/', '@scoped/package', 'random-value'),
@@ -238,15 +238,15 @@ describe('HasteMap', () => {
238238

239239
it('creates different cache file paths for different roots', () => {
240240
jest.resetModules();
241-
const HasteMap = require('../');
241+
const HasteMap = require('../').default;
242242
const hasteMap1 = new HasteMap({...defaultConfig, rootDir: '/root1'});
243243
const hasteMap2 = new HasteMap({...defaultConfig, rootDir: '/root2'});
244244
expect(hasteMap1.getCacheFilePath()).not.toBe(hasteMap2.getCacheFilePath());
245245
});
246246

247247
it('creates different cache file paths for different dependency extractor cache keys', () => {
248248
jest.resetModules();
249-
const HasteMap = require('../');
249+
const HasteMap = require('../').default;
250250
const dependencyExtractor = require('./dependencyExtractor');
251251
const config = {
252252
...defaultConfig,
@@ -261,7 +261,7 @@ describe('HasteMap', () => {
261261

262262
it('creates different cache file paths for different hasteImplModulePath cache keys', () => {
263263
jest.resetModules();
264-
const HasteMap = require('../');
264+
const HasteMap = require('../').default;
265265
const hasteImpl = require('./haste_impl');
266266
hasteImpl.setCacheKey('foo');
267267
const hasteMap1 = new HasteMap(defaultConfig);
@@ -272,7 +272,7 @@ describe('HasteMap', () => {
272272

273273
it('creates different cache file paths for different projects', () => {
274274
jest.resetModules();
275-
const HasteMap = require('../');
275+
const HasteMap = require('../').default;
276276
const hasteMap1 = new HasteMap({...defaultConfig, name: '@scoped/package'});
277277
const hasteMap2 = new HasteMap({...defaultConfig, name: '-scoped-package'});
278278
expect(hasteMap1.getCacheFilePath()).not.toBe(hasteMap2.getCacheFilePath());

packages/jest-haste-map/src/index.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ import {escapePathForRegex} from 'jest-regex-util';
1919
import serializer from 'jest-serializer';
2020
import Worker from 'jest-worker';
2121
import HasteFS from './HasteFS';
22-
import HasteModuleMap, {
23-
SerializableModuleMap as HasteSerializableModuleMap,
24-
} from './ModuleMap';
22+
import HasteModuleMap from './ModuleMap';
2523
import H from './constants';
2624
import nodeCrawl = require('./crawlers/node');
2725
import watchmanCrawl = require('./crawlers/watchman');
@@ -106,14 +104,9 @@ type Watcher = {
106104

107105
type WorkerInterface = {worker: typeof worker; getSha1: typeof getSha1};
108106

109-
// TODO: Ditch namespace when this module exports ESM
110-
declare namespace HasteMap {
111-
export type ModuleMap = HasteModuleMap;
112-
export type SerializableModuleMap = HasteSerializableModuleMap;
113-
export type FS = HasteFS;
114-
export type HasteMapObject = InternalHasteMapObject;
115-
export type HasteChangeEvent = ChangeEvent;
116-
}
107+
export type {default as ModuleMap, SerializableModuleMap} from './ModuleMap';
108+
export type {default as FS} from './HasteFS';
109+
export type {ChangeEvent, HasteMap as HasteMapObject} from './types';
117110

118111
const CHANGE_INTERVAL = 30;
119112
const MAX_WAIT_TIME = 240000;
@@ -215,7 +208,7 @@ function invariant(condition: unknown, message?: string): asserts condition {
215208
* Worker processes can directly access the cache through `HasteMap.read()`.
216209
*
217210
*/
218-
class HasteMap extends EventEmitter {
211+
export default class HasteMap extends EventEmitter {
219212
private _buildPromise: Promise<InternalHasteMapObject> | null;
220213
private _cachePath: Config.Path;
221214
private _changeInterval?: NodeJS.Timeout;
@@ -1121,5 +1114,3 @@ function copyMap<K, V>(input: Map<K, V>): Map<K, V> {
11211114
HasteMap.H = H;
11221115
HasteMap.DuplicateError = DuplicateError;
11231116
HasteMap.ModuleMap = HasteModuleMap;
1124-
1125-
export = HasteMap;

packages/jest-runner/src/testWorker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import exit = require('exit');
1010
import type {SerializableError, TestResult} from '@jest/test-result';
1111
import type {Config} from '@jest/types';
12-
import HasteMap = require('jest-haste-map');
12+
import HasteMap, {SerializableModuleMap} from 'jest-haste-map';
1313
import {separateMessageFromStack} from 'jest-message-util';
1414
import type Resolver from 'jest-resolve';
1515
import Runtime from 'jest-runtime';
@@ -23,7 +23,7 @@ import type {
2323

2424
export type SerializableResolver = {
2525
config: Config.ProjectConfig;
26-
serializableModuleMap: HasteMap.SerializableModuleMap;
26+
serializableModuleMap: SerializableModuleMap;
2727
};
2828

2929
type WorkerData = {

0 commit comments

Comments
 (0)