Skip to content
/ jest Public
forked from jestjs/jest

Commit

Permalink
get rid of package filter
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Feb 17, 2022
1 parent 0f23f26 commit a38e5c6
Showing 1 changed file with 2 additions and 45 deletions.
47 changes: 2 additions & 45 deletions packages/jest-resolve/src/defaultResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function getPathInModule(
path: string,
options: UpstreamResolveOptionsWithConditions,
): string {
if (isAbsolute(path) || path.startsWith('.')) {
if (shouldIgnoreRequestForExports(path)) {
return path;
}

Expand Down Expand Up @@ -122,10 +122,7 @@ export default function defaultResolver(

const result =
pathToResolve === path
? resolveSync(pathToResolve, {
...resolveOptions,
packageFilter: createPackageFilter(pathToResolve, options),
})
? resolveSync(pathToResolve, resolveOptions)
: pathToResolve;

// Dereference symlinks to ensure we don't create a separate
Expand All @@ -141,46 +138,6 @@ function readPackageSync(_: unknown, file: string): PkgJson {
return readPackageCached(file);
}

function createPackageFilter(
originalPath: string,
options: ResolverOptions,
): ResolverOptions['packageFilter'] {
if (shouldIgnoreRequestForExports(originalPath)) {
return options.packageFilter;
}

return function packageFilter(pkg, ...rest) {
let filteredPkg = pkg;

if (options.packageFilter) {
filteredPkg = options.packageFilter(filteredPkg, ...rest);
}

if (filteredPkg.exports == null) {
return filteredPkg;
}

let resolvedMain: string | void = undefined;

try {
resolvedMain = resolveExports(
filteredPkg,
'.',
createResolveOptions(options.conditions),
);
} catch {
// ignore
}

return {
...filteredPkg,
// override `main` so `resolve` resolves it correctly while respecting
// `exports`.
main: resolvedMain,
};
};
}

function createResolveOptions(
conditions: Array<string> | undefined,
): ResolveExportsOptions {
Expand Down

0 comments on commit a38e5c6

Please sign in to comment.