Skip to content

Commit

Permalink
update types
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Feb 18, 2021
1 parent bdaae98 commit 902eacd
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 30 deletions.
2 changes: 1 addition & 1 deletion packages/jest-resolve/package.json
Expand Up @@ -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": {
Expand Down
15 changes: 8 additions & 7 deletions packages/jest-resolve/src/defaultResolver.ts
Expand Up @@ -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';

Expand All @@ -19,7 +19,7 @@ type ResolverOptions = {
moduleDirectory?: Array<string>;
paths?: Array<Config.Path>;
rootDir?: Config.Path;
packageFilter?: ResolveOpts['packageFilter'];
packageFilter?: (pkg: any, pkgfile: string) => any;
};

// https://github.com/facebook/jest/pull/10617
Expand Down Expand Up @@ -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,
});
Expand Down Expand Up @@ -121,15 +120,17 @@ function realpathCached(path: Config.Path): Config.Path {
return result;
}

const packageContents = new Map<string, unknown>();
function readPackageCached(path: Config.Path): unknown {
type PkgJson = Record<string, unknown>;

const packageContents = new Map<string, PkgJson>();
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);

Expand All @@ -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);
}
4 changes: 1 addition & 3 deletions packages/jest-resolve/src/index.ts
Expand Up @@ -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<string, string>;
Expand Down Expand Up @@ -495,5 +495,3 @@ Please check your configuration for these entries:

return error;
};

export default Resolver;
21 changes: 9 additions & 12 deletions packages/jest-runtime/src/index.ts
Expand Up @@ -271,7 +271,7 @@ export default class Runtime {

static shouldInstrument = shouldInstrument;

static createContext(
static async createContext(
config: Config.ProjectConfig,
options: {
console?: Console;
Expand All @@ -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(
Expand Down
12 changes: 5 additions & 7 deletions yarn.lock
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 902eacd

Please sign in to comment.