Skip to content

Commit 4ea66e2

Browse files
jeysalSimenB
authored andcommitted
fix jest-haste-map-types (#7951)
1 parent cfd60a8 commit 4ea66e2

File tree

8 files changed

+21
-15
lines changed

8 files changed

+21
-15
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
### Chore & Maintenance
2424

25-
- `[*]`: Setup building, linting and testing of TypeScript ([#7808](https://github.com/facebook/jest/pull/7808), [#7855](https://github.com/facebook/jest/pull/7855))
25+
- `[*]`: Setup building, linting and testing of TypeScript ([#7808](https://github.com/facebook/jest/pull/7808), [#7855](https://github.com/facebook/jest/pull/7855), [#7951](https://github.com/facebook/jest/pull/7951))
2626
- `[pretty-format]`: Migrate to TypeScript ([#7809](https://github.com/facebook/jest/pull/7809))
2727
- `[diff-sequences]`: Migrate to Typescript ([#7820](https://github.com/facebook/jest/pull/7820))
2828
- `[jest-get-type]`: Migrate to TypeScript ([#7818](https://github.com/facebook/jest/pull/7818))
@@ -39,7 +39,7 @@
3939
- `[jest-watcher]`: Migrate to TypeScript ([#7843](https://github.com/facebook/jest/pull/7843))
4040
- `[jest-mock]`: Migrate to TypeScript ([#7847](https://github.com/facebook/jest/pull/7847), [#7850](https://github.com/facebook/jest/pull/7850))
4141
- `[jest-worker]`: Migrate to TypeScript ([#7853](https://github.com/facebook/jest/pull/7853))
42-
- `[jest-haste-map]`: Migrate to TypeScript ([#7854](https://github.com/facebook/jest/pull/7854))
42+
- `[jest-haste-map]`: Migrate to TypeScript ([#7854](https://github.com/facebook/jest/pull/7854), [#7951](https://github.com/facebook/jest/pull/7951))
4343
- `[docs]`: Fix image paths in SnapshotTesting.md for current and version 24 ([#7872](https://github.com/facebook/jest/pull/7872))
4444
- `[babel-jest]`: Migrate to TypeScript ([#7862](https://github.com/facebook/jest/pull/7862))
4545
- `[jest-resolve]`: Migrate to TypeScript ([#7871](https://github.com/facebook/jest/pull/7871))

babel.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module.exports = {
99
},
1010
{
1111
plugins: [
12+
'babel-plugin-typescript-strip-namespaces',
1213
require.resolve(
1314
'./scripts/babel-plugin-jest-replace-ts-export-assignment.js'
1415
),

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"ansi-styles": "^3.2.0",
2020
"babel-eslint": "^9.0.0",
2121
"babel-loader": "^8.0.5",
22+
"babel-plugin-typescript-strip-namespaces": "^1.1.0",
2223
"camelcase": "^5.0.0",
2324
"chalk": "^2.0.1",
2425
"codecov": "^3.0.0",

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,12 @@ type Watcher = {
9898

9999
type WorkerInterface = {worker: typeof worker; getSha1: typeof getSha1};
100100

101-
export type ModuleMap = HasteModuleMap;
102-
export type SerializableModuleMap = HasteSerializableModuleMap;
103-
export type FS = HasteFS;
101+
// TODO: Ditch namespace when this module exports ESM
102+
namespace HasteMap {
103+
export type ModuleMap = HasteModuleMap;
104+
export type SerializableModuleMap = HasteSerializableModuleMap;
105+
export type FS = HasteFS;
106+
}
104107

105108
const CHANGE_INTERVAL = 30;
106109
const MAX_WAIT_TIME = 240000;
@@ -368,7 +371,7 @@ class HasteMap extends EventEmitter {
368371
return hasteMap;
369372
}
370373

371-
readModuleMap(): ModuleMap {
374+
readModuleMap(): HasteModuleMap {
372375
const data = this.read();
373376
return new HasteModuleMap({
374377
duplicates: data.duplicates,
@@ -1079,4 +1082,4 @@ function copyMap<K, V>(input: Map<K, V>): Map<K, V> {
10791082
HasteMap.H = H;
10801083
HasteMap.ModuleMap = HasteModuleMap;
10811084

1082-
module.exports = HasteMap;
1085+
export = HasteMap;

packages/jest-resolve-dependencies/src/__tests__/dependency_resolver.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ beforeEach(() => {
3333
roots: ['./packages/jest-resolve-dependencies'],
3434
});
3535
return Runtime.createContext(config, {maxWorkers, watchman: false}).then(
36-
(hasteMap: any) => {
36+
(runtimeContext: any) => {
3737
dependencyResolver = new DependencyResolver(
38-
hasteMap.resolver,
39-
hasteMap.hasteFS,
38+
runtimeContext.resolver,
39+
runtimeContext.hasteFS,
4040
buildSnapshotResolver(config),
4141
);
4242
},

packages/jest-resolve/src/__tests__/resolve.test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,14 @@
88

99
import fs from 'fs';
1010
import path from 'path';
11-
import HasteMap from 'jest-haste-map';
11+
import {ModuleMap} from 'jest-haste-map';
1212
import Resolver from '../';
1313
// @ts-ignore: js file
1414
import userResolver from '../__mocks__/userResolver';
1515
import nodeModulesPaths from '../nodeModulesPaths';
1616
import defaultResolver from '../defaultResolver';
1717
import {ResolverConfig} from '../types';
1818

19-
// @ts-ignore: types are wrong. not sure how...
20-
const {ModuleMap} = HasteMap;
21-
2219
jest.mock('../__mocks__/userResolver');
2320

2421
beforeEach(() => {

packages/jest-transform/src/ScriptTransformer.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ export default class ScriptTransformer {
110110
content: string,
111111
instrument: boolean,
112112
): Config.Path {
113-
// @ts-ignore: not properly exported (needs ESM)
114113
const baseCacheDir = HasteMap.getCacheFilePath(
115114
this._config.cacheDirectory,
116115
'jest-transform-cache-' + this._config.name,

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2610,6 +2610,11 @@ babel-plugin-syntax-trailing-function-commas@^7.0.0-beta.0:
26102610
resolved "https://registry.yarnpkg.com/babel-plugin-syntax-trailing-function-commas/-/babel-plugin-syntax-trailing-function-commas-7.0.0-beta.0.tgz#aa213c1435e2bffeb6fca842287ef534ad05d5cf"
26112611
integrity sha512-Xj9XuRuz3nTSbaTXWv3itLOcxyF4oPD8douBBmj7U9BBC6nEBYfyOJYQMf/8PJAFotC62UY5dFfIGEPr7WswzQ==
26122612

2613+
babel-plugin-typescript-strip-namespaces@^1.1.0:
2614+
version "1.1.0"
2615+
resolved "https://registry.yarnpkg.com/babel-plugin-typescript-strip-namespaces/-/babel-plugin-typescript-strip-namespaces-1.1.0.tgz#7f8b022505bc742905801f9c41dd93f08f34ffc4"
2616+
integrity sha512-69kdF5HJoSIdgTVtHDor6XGJzVcxF5Hh92Rnh+rcitBZpj0pVU3Go0CrNJdPog6uoTcB90Ifk9O55FPZg0XN4w==
2617+
26132618
26142619
version "6.23.0"
26152620
resolved "https://registry.yarnpkg.com/babel-polyfill/-/babel-polyfill-6.23.0.tgz#8364ca62df8eafb830499f699177466c3b03499d"

0 commit comments

Comments
 (0)