From 94c3c25eea62025309577ed553b5cc56cb2f4925 Mon Sep 17 00:00:00 2001 From: Tim Seckinger Date: Thu, 21 Feb 2019 23:47:32 +0100 Subject: [PATCH 1/3] fix jest-haste-map-types --- babel.config.js | 1 + package.json | 1 + packages/jest-haste-map/src/index.ts | 12 +++++++----- .../src/__tests__/dependency_resolver.test.ts | 6 +++--- packages/jest-resolve/src/__tests__/resolve.test.ts | 5 +---- packages/jest-transform/src/ScriptTransformer.ts | 1 - yarn.lock | 5 +++++ 7 files changed, 18 insertions(+), 13 deletions(-) diff --git a/babel.config.js b/babel.config.js index e295ec832457..5b6610d3801e 100644 --- a/babel.config.js +++ b/babel.config.js @@ -9,6 +9,7 @@ module.exports = { }, { plugins: [ + 'babel-plugin-typescript-strip-namespaces', require.resolve( './scripts/babel-plugin-jest-replace-ts-export-assignment.js' ), diff --git a/package.json b/package.json index a1d279fd9e1a..12bab1f44dbf 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "ansi-styles": "^3.2.0", "babel-eslint": "^9.0.0", "babel-loader": "^8.0.5", + "babel-plugin-typescript-strip-namespaces": "^1.1.0", "camelcase": "^5.0.0", "chalk": "^2.0.1", "codecov": "^3.0.0", diff --git a/packages/jest-haste-map/src/index.ts b/packages/jest-haste-map/src/index.ts index 0bf7125abaf8..994c4c1da778 100644 --- a/packages/jest-haste-map/src/index.ts +++ b/packages/jest-haste-map/src/index.ts @@ -98,9 +98,11 @@ type Watcher = { type WorkerInterface = {worker: typeof worker; getSha1: typeof getSha1}; -export type ModuleMap = HasteModuleMap; -export type SerializableModuleMap = HasteSerializableModuleMap; -export type FS = HasteFS; +namespace HasteMap { + export type ModuleMap = HasteModuleMap; + export type SerializableModuleMap = HasteSerializableModuleMap; + export type FS = HasteFS; +} const CHANGE_INTERVAL = 30; const MAX_WAIT_TIME = 240000; @@ -368,7 +370,7 @@ class HasteMap extends EventEmitter { return hasteMap; } - readModuleMap(): ModuleMap { + readModuleMap(): HasteModuleMap { const data = this.read(); return new HasteModuleMap({ duplicates: data.duplicates, @@ -1079,4 +1081,4 @@ function copyMap(input: Map): Map { HasteMap.H = H; HasteMap.ModuleMap = HasteModuleMap; -module.exports = HasteMap; +export = HasteMap; diff --git a/packages/jest-resolve-dependencies/src/__tests__/dependency_resolver.test.ts b/packages/jest-resolve-dependencies/src/__tests__/dependency_resolver.test.ts index c2f50429462e..f6bdea51c0ba 100644 --- a/packages/jest-resolve-dependencies/src/__tests__/dependency_resolver.test.ts +++ b/packages/jest-resolve-dependencies/src/__tests__/dependency_resolver.test.ts @@ -33,10 +33,10 @@ beforeEach(() => { roots: ['./packages/jest-resolve-dependencies'], }); return Runtime.createContext(config, {maxWorkers, watchman: false}).then( - (hasteMap: any) => { + (runtimeContext: any) => { dependencyResolver = new DependencyResolver( - hasteMap.resolver, - hasteMap.hasteFS, + runtimeContext.resolver, + runtimeContext.hasteFS, buildSnapshotResolver(config), ); }, diff --git a/packages/jest-resolve/src/__tests__/resolve.test.ts b/packages/jest-resolve/src/__tests__/resolve.test.ts index 014407bc47c7..021ba08aeeac 100644 --- a/packages/jest-resolve/src/__tests__/resolve.test.ts +++ b/packages/jest-resolve/src/__tests__/resolve.test.ts @@ -8,7 +8,7 @@ import fs from 'fs'; import path from 'path'; -import HasteMap from 'jest-haste-map'; +import {ModuleMap} from 'jest-haste-map'; import Resolver from '../'; // @ts-ignore: js file import userResolver from '../__mocks__/userResolver'; @@ -16,9 +16,6 @@ import nodeModulesPaths from '../nodeModulesPaths'; import defaultResolver from '../defaultResolver'; import {ResolverConfig} from '../types'; -// @ts-ignore: types are wrong. not sure how... -const {ModuleMap} = HasteMap; - jest.mock('../__mocks__/userResolver'); beforeEach(() => { diff --git a/packages/jest-transform/src/ScriptTransformer.ts b/packages/jest-transform/src/ScriptTransformer.ts index 690a97c7da33..3d92b9f94cee 100644 --- a/packages/jest-transform/src/ScriptTransformer.ts +++ b/packages/jest-transform/src/ScriptTransformer.ts @@ -110,7 +110,6 @@ export default class ScriptTransformer { content: string, instrument: boolean, ): Config.Path { - // @ts-ignore: not properly exported (needs ESM) const baseCacheDir = HasteMap.getCacheFilePath( this._config.cacheDirectory, 'jest-transform-cache-' + this._config.name, diff --git a/yarn.lock b/yarn.lock index 02da8691c7e2..a16c547fc344 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2610,6 +2610,11 @@ babel-plugin-syntax-trailing-function-commas@^7.0.0-beta.0: resolved "https://registry.yarnpkg.com/babel-plugin-syntax-trailing-function-commas/-/babel-plugin-syntax-trailing-function-commas-7.0.0-beta.0.tgz#aa213c1435e2bffeb6fca842287ef534ad05d5cf" integrity sha512-Xj9XuRuz3nTSbaTXWv3itLOcxyF4oPD8douBBmj7U9BBC6nEBYfyOJYQMf/8PJAFotC62UY5dFfIGEPr7WswzQ== +babel-plugin-typescript-strip-namespaces@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/babel-plugin-typescript-strip-namespaces/-/babel-plugin-typescript-strip-namespaces-1.1.0.tgz#7f8b022505bc742905801f9c41dd93f08f34ffc4" + integrity sha512-69kdF5HJoSIdgTVtHDor6XGJzVcxF5Hh92Rnh+rcitBZpj0pVU3Go0CrNJdPog6uoTcB90Ifk9O55FPZg0XN4w== + babel-polyfill@6.23.0: version "6.23.0" resolved "https://registry.yarnpkg.com/babel-polyfill/-/babel-polyfill-6.23.0.tgz#8364ca62df8eafb830499f699177466c3b03499d" From 9c8f2176c3b7b0e53e5dcb2a68787225c904d44d Mon Sep 17 00:00:00 2001 From: Tim Seckinger Date: Fri, 22 Feb 2019 00:22:13 +0100 Subject: [PATCH 2/3] Update CHANGELOG.md --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b95746b8ceb7..69706c1b3943 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,7 +21,7 @@ ### Chore & Maintenance -- `[*]`: Setup building, linting and testing of TypeScript ([#7808](https://github.com/facebook/jest/pull/7808), [#7855](https://github.com/facebook/jest/pull/7855)) +- `[*]`: 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)) - `[pretty-format]`: Migrate to TypeScript ([#7809](https://github.com/facebook/jest/pull/7809)) - `[diff-sequences]`: Migrate to Typescript ([#7820](https://github.com/facebook/jest/pull/7820)) - `[jest-get-type]`: Migrate to TypeScript ([#7818](https://github.com/facebook/jest/pull/7818)) @@ -38,7 +38,7 @@ - `[jest-watcher]`: Migrate to TypeScript ([#7843](https://github.com/facebook/jest/pull/7843)) - `[jest-mock]`: Migrate to TypeScript ([#7847](https://github.com/facebook/jest/pull/7847), [#7850](https://github.com/facebook/jest/pull/7850)) - `[jest-worker]`: Migrate to TypeScript ([#7853](https://github.com/facebook/jest/pull/7853)) -- `[jest-haste-map]`: Migrate to TypeScript ([#7854](https://github.com/facebook/jest/pull/7854)) +- `[jest-haste-map]`: Migrate to TypeScript ([#7854](https://github.com/facebook/jest/pull/7854), [#7951](https://github.com/facebook/jest/pull/7951)) - `[docs]`: Fix image paths in SnapshotTesting.md for current and version 24 ([#7872](https://github.com/facebook/jest/pull/7872)) - `[babel-jest]`: Migrate to TypeScript ([#7862](https://github.com/facebook/jest/pull/7862)) - `[jest-resolve]`: Migrate to TypeScript ([#7871](https://github.com/facebook/jest/pull/7871)) From 6636a67adb5c0697609838d87945e58478747d1a Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Fri, 22 Feb 2019 01:16:11 +0100 Subject: [PATCH 3/3] Update index.ts --- packages/jest-haste-map/src/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/jest-haste-map/src/index.ts b/packages/jest-haste-map/src/index.ts index 994c4c1da778..f809a46df037 100644 --- a/packages/jest-haste-map/src/index.ts +++ b/packages/jest-haste-map/src/index.ts @@ -98,6 +98,7 @@ type Watcher = { type WorkerInterface = {worker: typeof worker; getSha1: typeof getSha1}; +// TODO: Ditch namespace when this module exports ESM namespace HasteMap { export type ModuleMap = HasteModuleMap; export type SerializableModuleMap = HasteSerializableModuleMap;