Skip to content

Commit

Permalink
do not add main if there is index in root
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Oct 17, 2021
1 parent 047c8b9 commit 96ee934
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions packages/jest-resolve/src/defaultResolver.ts
Expand Up @@ -5,6 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import {resolve} from 'path';
import * as fs from 'graceful-fs';
import pnpResolver from 'jest-pnp-resolver';
import {Opts as ResolveOpts, sync as resolveSync} from 'resolve';
Expand Down Expand Up @@ -175,11 +176,24 @@ function createPackageFilter(
}
}

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

if (userFilter) {
filteredPkg = userFilter(filteredPkg, ...rest);
filteredPkg = userFilter(filteredPkg, path);
}

if (filteredPkg.main) {
return filteredPkg;
}

const indexInRoot = resolve(path, './index.js');

// if the module contains an `index.js` file in root, `resolve` will request
// that if there is no `main`. Since we don't wanna break that, add this
// check
if (isFile(indexInRoot)) {
return filteredPkg;
}

return {
Expand Down

0 comments on commit 96ee934

Please sign in to comment.