diff --git a/packages/jest-resolve/package.json b/packages/jest-resolve/package.json index 72b8e84c1d5c..4328ae3cc25c 100644 --- a/packages/jest-resolve/package.json +++ b/packages/jest-resolve/package.json @@ -25,7 +25,7 @@ }, "devDependencies": { "@types/graceful-fs": "^4.1.3", - "@types/resolve": "^1.17.0", + "@types/resolve": "^1.20.0", "jest-haste-map": "^27.0.0-next.2" }, "engines": { diff --git a/packages/jest-resolve/src/defaultResolver.ts b/packages/jest-resolve/src/defaultResolver.ts index 172376bda70c..7b3dfe17a3bd 100644 --- a/packages/jest-resolve/src/defaultResolver.ts +++ b/packages/jest-resolve/src/defaultResolver.ts @@ -7,7 +7,7 @@ import * as fs from 'graceful-fs'; import pnpResolver from 'jest-pnp-resolver'; -import {Opts as ResolveOpts, sync as resolveSync} from 'resolve'; +import {sync as resolveSync} from 'resolve'; import type {Config} from '@jest/types'; import {tryRealpath} from 'jest-util'; @@ -19,7 +19,7 @@ type ResolverOptions = { moduleDirectory?: Array; paths?: Array; rootDir?: Config.Path; - packageFilter?: ResolveOpts['packageFilter']; + packageFilter?: (pkg: any, pkgfile: string) => any; }; // https://github.com/facebook/jest/pull/10617 @@ -50,7 +50,6 @@ export default function defaultResolver( packageFilter: options.packageFilter, paths: options.paths, preserveSymlinks: false, - // @ts-expect-error: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/51182 readPackageSync, realpathSync, }); @@ -121,15 +120,17 @@ function realpathCached(path: Config.Path): Config.Path { return result; } -const packageContents = new Map(); -function readPackageCached(path: Config.Path): unknown { +type PkgJson = Record; + +const packageContents = new Map(); +function readPackageCached(path: Config.Path): PkgJson { let result = packageContents.get(path); if (result !== undefined) { return result; } - result = JSON.parse(fs.readFileSync(path, 'utf8')); + result = JSON.parse(fs.readFileSync(path, 'utf8')) as PkgJson; packageContents.set(path, result); @@ -151,6 +152,6 @@ function realpathSync(file: Config.Path): Config.Path { return realpathCached(file); } -function readPackageSync(_: unknown, file: Config.Path): unknown { +function readPackageSync(_: unknown, file: Config.Path): PkgJson { return readPackageCached(file); } diff --git a/packages/jest-resolve/src/index.ts b/packages/jest-resolve/src/index.ts index 76a28c9e4902..2a76b92238b7 100644 --- a/packages/jest-resolve/src/index.ts +++ b/packages/jest-resolve/src/index.ts @@ -48,7 +48,7 @@ const nodePaths = NODE_PATH .map(p => path.resolve(resolvedCwd, p)) : undefined; -class Resolver { +export default class Resolver { private readonly _options: ResolverConfig; private readonly _moduleMap: ModuleMap; private readonly _moduleIDCache: Map; @@ -495,5 +495,3 @@ Please check your configuration for these entries: return error; }; - -export default Resolver; diff --git a/packages/jest-runtime/src/index.ts b/packages/jest-runtime/src/index.ts index 2aa3f6739ec6..fb8689c382d4 100644 --- a/packages/jest-runtime/src/index.ts +++ b/packages/jest-runtime/src/index.ts @@ -271,7 +271,7 @@ export default class Runtime { static shouldInstrument = shouldInstrument; - static createContext( + static async createContext( config: Config.ProjectConfig, options: { console?: Console; @@ -288,17 +288,14 @@ export default class Runtime { watch: options.watch, watchman: options.watchman, }); - return instance.build().then( - hasteMap => ({ - config, - hasteFS: hasteMap.hasteFS, - moduleMap: hasteMap.moduleMap, - resolver: Runtime.createResolver(config, hasteMap.moduleMap), - }), - error => { - throw error; - }, - ); + const hasteMap = await instance.build(); + + return { + config, + hasteFS: hasteMap.hasteFS, + moduleMap: hasteMap.moduleMap, + resolver: Runtime.createResolver(config, hasteMap.moduleMap), + }; } static createHasteMap( diff --git a/yarn.lock b/yarn.lock index 2e646f48ffc9..f9a17510e06e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3830,12 +3830,10 @@ __metadata: languageName: node linkType: hard -"@types/resolve@npm:^1.17.0": - version: 1.19.0 - resolution: "@types/resolve@npm:1.19.0" - dependencies: - "@types/node": "*" - checksum: 6dab5d4bf568d4fe7ed2207f839736d3558e04f994cdad122ce3c0a3d75f56080f4f63a297d5dcf61a1d3f450ebb99a8ca3719e3b7147c863d80436f1a9890e2 +"@types/resolve@npm:^1.20.0": + version: 1.20.0 + resolution: "@types/resolve@npm:1.20.0" + checksum: 3c75135d5cf3652453ef8f099b109f7fec5e82fe67bf38048226614dbcd11a943affee383e5d28c12c5f03b049281a3e486395326b9810297f9649c7b00f41fd languageName: node linkType: hard @@ -12067,7 +12065,7 @@ fsevents@^1.2.7: dependencies: "@jest/types": ^27.0.0-next.1 "@types/graceful-fs": ^4.1.3 - "@types/resolve": ^1.17.0 + "@types/resolve": ^1.20.0 chalk: ^4.0.0 escalade: ^3.1.1 graceful-fs: ^4.2.4