Skip to content

Commit 96ee934

Browse files
committed
do not add main if there is index in root
1 parent 047c8b9 commit 96ee934

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

packages/jest-resolve/src/defaultResolver.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8+
import {resolve} from 'path';
89
import * as fs from 'graceful-fs';
910
import pnpResolver from 'jest-pnp-resolver';
1011
import {Opts as ResolveOpts, sync as resolveSync} from 'resolve';
@@ -175,11 +176,24 @@ function createPackageFilter(
175176
}
176177
}
177178

178-
return function packageFilter(pkg: PkgJson, ...rest) {
179+
return function packageFilter(pkg: PkgJson, path) {
179180
let filteredPkg = pkg;
180181

181182
if (userFilter) {
182-
filteredPkg = userFilter(filteredPkg, ...rest);
183+
filteredPkg = userFilter(filteredPkg, path);
184+
}
185+
186+
if (filteredPkg.main) {
187+
return filteredPkg;
188+
}
189+
190+
const indexInRoot = resolve(path, './index.js');
191+
192+
// if the module contains an `index.js` file in root, `resolve` will request
193+
// that if there is no `main`. Since we don't wanna break that, add this
194+
// check
195+
if (isFile(indexInRoot)) {
196+
return filteredPkg;
183197
}
184198

185199
return {

0 commit comments

Comments
 (0)