From d00f6b021e9e7efb5a33a8c491d0c6f1f311303e Mon Sep 17 00:00:00 2001 From: Tom Mrazauskas Date: Mon, 25 Apr 2022 16:22:48 +0300 Subject: [PATCH 1/3] feat(jest-resolve): expose ResolverOptions type --- .../jest-resolve/__typetests__/resolver.test.ts | 16 ++++++++++++++++ packages/jest-resolve/src/defaultResolver.ts | 2 +- packages/jest-resolve/src/index.ts | 1 + 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/jest-resolve/__typetests__/resolver.test.ts b/packages/jest-resolve/__typetests__/resolver.test.ts index b3ee2403e5f3..a6ef5cfe00a9 100644 --- a/packages/jest-resolve/__typetests__/resolver.test.ts +++ b/packages/jest-resolve/__typetests__/resolver.test.ts @@ -12,6 +12,7 @@ import type { PackageFilter, PackageJSON, PathFilter, + ResolverOptions, SyncResolver, } from 'jest-resolve'; @@ -42,6 +43,21 @@ const pathFilter = (pkg: PackageJSON, path: string, relativePath: string) => expectAssignable(pathFilter); +// ResolverOptions + +function customSyncResolver(path: string, options: ResolverOptions): string { + return path; +} +expectAssignable(customSyncResolver); + +async function customAsyncResolver( + path: string, + options: ResolverOptions, +): Promise { + return path; +} +expectAssignable(customAsyncResolver); + // AsyncResolver const asyncResolver: AsyncResolver = async (path, options) => { diff --git a/packages/jest-resolve/src/defaultResolver.ts b/packages/jest-resolve/src/defaultResolver.ts index 16694ad990ed..ae9ac7c8ca99 100644 --- a/packages/jest-resolve/src/defaultResolver.ts +++ b/packages/jest-resolve/src/defaultResolver.ts @@ -51,7 +51,7 @@ export type PathFilter = ( relativePath: string, ) => string; -type ResolverOptions = { +export type ResolverOptions = { /** Directory to begin resolving from. */ basedir: string; /** List of export conditions. */ diff --git a/packages/jest-resolve/src/index.ts b/packages/jest-resolve/src/index.ts index e32263a3a488..40b1a73bf5b3 100644 --- a/packages/jest-resolve/src/index.ts +++ b/packages/jest-resolve/src/index.ts @@ -12,6 +12,7 @@ export type { SyncResolver, PackageFilter, PathFilter, + ResolverOptions, } from './defaultResolver'; export type { FindNodeModuleConfig, From 229773967fccc7522fd4d9b95f67ffe3cbfcf064 Mon Sep 17 00:00:00 2001 From: Tom Mrazauskas Date: Mon, 25 Apr 2022 16:26:08 +0300 Subject: [PATCH 2/3] fix typo --- packages/jest-resolve/src/defaultResolver.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/jest-resolve/src/defaultResolver.ts b/packages/jest-resolve/src/defaultResolver.ts index ae9ac7c8ca99..5f121278a95b 100644 --- a/packages/jest-resolve/src/defaultResolver.ts +++ b/packages/jest-resolve/src/defaultResolver.ts @@ -37,7 +37,7 @@ export type PackageFilter = ( ) => PackageJSON; /** - * Allows transforms a path within a package. + * Allows transforming a path within a package. * * @param pkg - Parsed `package.json` contents. * @param path - Path being resolved. From 0d14737b042dcf914d65fca533aa8af7b3e6712d Mon Sep 17 00:00:00 2001 From: Tom Mrazauskas Date: Mon, 25 Apr 2022 16:32:11 +0300 Subject: [PATCH 3/3] add changelog entry --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6fe38aa4aac3..24751c2dc3db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ### Features +- `[jest-resolve]` Expose `ResolverOptions` type ([#12736](https://github.com/facebook/jest/pull/12736)) + ### Fixes ### Chore & Maintenance