diff --git a/CHANGELOG.md b/CHANGELOG.md index d1b806080ee2..2083f6337a08 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 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..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. @@ -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,