@@ -47,8 +47,10 @@ export default function defaultResolver(
4747 ...options ,
4848 isDirectory,
4949 isFile,
50- packageFilter :
51- options . packageFilter ?? createPackageFilter ( options . conditions ) ,
50+ packageFilter : createPackageFilter (
51+ options . conditions ,
52+ options . packageFilter ,
53+ ) ,
5254 preserveSymlinks : false ,
5355 readPackageSync,
5456 realpathSync,
@@ -156,7 +158,10 @@ function readPackageSync(_: unknown, file: Config.Path): PkgJson {
156158 return readPackageCached ( file ) ;
157159}
158160
159- function createPackageFilter ( conditions ?: Array < string > ) {
161+ function createPackageFilter (
162+ conditions ?: Array < string > ,
163+ userFilter ?: ResolverOptions [ 'packageFilter' ] ,
164+ ) : ResolverOptions [ 'packageFilter' ] {
160165 function attemptExportsFallback ( pkg : PkgJson ) {
161166 const options : ResolveExportsOptions = conditions
162167 ? { conditions, unsafe : true }
@@ -170,10 +175,16 @@ function createPackageFilter(conditions?: Array<string>) {
170175 }
171176 }
172177
173- return function packageFilter ( pkg : PkgJson ) {
178+ return function packageFilter ( pkg : PkgJson , ...rest ) {
179+ let filteredPkg = pkg ;
180+
181+ if ( userFilter ) {
182+ filteredPkg = userFilter ( filteredPkg , ...rest ) ;
183+ }
184+
174185 return {
175- ...pkg ,
176- main : pkg . main ?? attemptExportsFallback ( pkg ) ,
186+ ...filteredPkg ,
187+ main : filteredPkg . main ?? attemptExportsFallback ( filteredPkg ) ,
177188 } ;
178189 } ;
179190}
0 commit comments