@@ -250,15 +250,15 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
250250 // enhanced-resolve: restrictions
251251 self . check_restrictions ( & path) ?;
252252 let package_json = cached_path. find_package_json ( & self . options , & self . cache , ctx) ?;
253- if let Some ( package_json) = & package_json {
253+ if let Some ( ( _ , package_json) ) = & package_json {
254254 // path must be inside the package.
255255 debug_assert ! ( path. starts_with( package_json. directory( ) ) ) ;
256256 }
257257 Ok ( Resolution {
258258 path,
259259 query : ctx. query . take ( ) ,
260260 fragment : ctx. fragment . take ( ) ,
261- package_json,
261+ package_json : package_json . map ( | ( _ , p ) | p ) ,
262262 } )
263263 }
264264
@@ -499,7 +499,8 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
499499 ) -> ResolveResult {
500500 // 1. Find the closest package scope SCOPE to DIR.
501501 // 2. If no scope was found, return.
502- let Some ( package_json) = cached_path. find_package_json ( & self . options , & self . cache , ctx) ?
502+ let Some ( ( _, package_json) ) =
503+ cached_path. find_package_json ( & self . options , & self . cache , ctx) ?
503504 else {
504505 return Ok ( None ) ;
505506 } ;
@@ -538,7 +539,9 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
538539 // 1. If X/package.json is a file,
539540 if !self . options . description_files . is_empty ( ) {
540541 // a. Parse X/package.json, and look for "main" field.
541- if let Some ( package_json) = cached_path. package_json ( & self . options , & self . cache , ctx) ? {
542+ if let Some ( ( _, package_json) ) =
543+ cached_path. package_json ( & self . options , & self . cache , ctx) ?
544+ {
542545 // b. If "main" is a falsy value, GOTO 2.
543546 for main_field in package_json. main_fields ( & self . options . main_fields ) {
544547 // c. let M = X + (json main field)
@@ -657,11 +660,11 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
657660
658661 fn load_alias_or_file ( & self , cached_path : & CachedPath , ctx : & mut Ctx ) -> ResolveResult {
659662 if !self . options . alias_fields . is_empty ( ) {
660- if let Some ( package_json) =
663+ if let Some ( ( package_url , package_json) ) =
661664 cached_path. find_package_json ( & self . options , & self . cache , ctx) ?
662665 {
663666 if let Some ( path) =
664- self . load_browser_field ( cached_path, None , & package_json, ctx) ?
667+ self . load_browser_field ( cached_path, None , & package_url , & package_json, ctx) ?
665668 {
666669 return Ok ( Some ( path) ) ;
667670 }
@@ -815,7 +818,8 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
815818 ) -> ResolveResult {
816819 // 2. If X does not match this pattern or DIR/NAME/package.json is not a file,
817820 // return.
818- let Some ( package_json) = cached_path. package_json ( & self . options , & self . cache , ctx) ? else {
821+ let Some ( ( _, package_json) ) = cached_path. package_json ( & self . options , & self . cache , ctx) ?
822+ else {
819823 return Ok ( None ) ;
820824 } ;
821825 // 3. Parse DIR/NAME/package.json, and look for "exports" field.
@@ -842,7 +846,8 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
842846 ) -> ResolveResult {
843847 // 1. Find the closest package scope SCOPE to DIR.
844848 // 2. If no scope was found, return.
845- let Some ( package_json) = cached_path. find_package_json ( & self . options , & self . cache , ctx) ?
849+ let Some ( ( package_url, package_json) ) =
850+ cached_path. find_package_json ( & self . options , & self . cache , ctx) ?
846851 else {
847852 return Ok ( None ) ;
848853 } ;
@@ -856,7 +861,6 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
856861 // 5. let MATCH = PACKAGE_EXPORTS_RESOLVE(pathToFileURL(SCOPE),
857862 // "." + X.slice("name".length), `package.json` "exports", ["node", "require"])
858863 // defined in the ESM resolver.
859- let package_url = self . cache . value ( package_json. directory ( ) ) ;
860864 // Note: The subpath is not prepended with a dot on purpose
861865 // because `package_exports_resolve` matches subpath without the leading dot.
862866 for exports in package_json. exports_fields ( & self . options . exports_fields ) {
@@ -871,7 +875,7 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
871875 }
872876 }
873877 }
874- self . load_browser_field ( cached_path, Some ( specifier) , & package_json, ctx)
878+ self . load_browser_field ( cached_path, Some ( specifier) , & package_url , & package_json, ctx)
875879 }
876880
877881 /// RESOLVE_ESM_MATCH(MATCH)
@@ -897,6 +901,7 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
897901 & self ,
898902 cached_path : & CachedPath ,
899903 module_specifier : Option < & str > ,
904+ package_url : & CachedPath ,
900905 package_json : & PackageJson ,
901906 ctx : & mut Ctx ,
902907 ) -> ResolveResult {
@@ -926,8 +931,7 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
926931 }
927932 ctx. with_resolving_alias ( new_specifier. to_string ( ) ) ;
928933 ctx. with_fully_specified ( false ) ;
929- let cached_path = self . cache . value ( package_json. directory ( ) ) ;
930- self . require ( & cached_path, new_specifier, ctx) . map ( Some )
934+ self . require ( package_url, new_specifier, ctx) . map ( Some )
931935 }
932936
933937 /// enhanced-resolve: AliasPlugin for [ResolveOptions::alias] and [ResolveOptions::fallback].
@@ -1258,7 +1262,7 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
12581262 // 1. Continue the next loop iteration.
12591263 if cached_path. is_dir ( & self . cache . fs , ctx) {
12601264 // 4. Let pjson be the result of READ_PACKAGE_JSON(packageURL).
1261- if let Some ( package_json) =
1265+ if let Some ( ( _ , package_json) ) =
12621266 cached_path. package_json ( & self . options , & self . cache , ctx) ?
12631267 {
12641268 // 5. If pjson is not null and pjson.exports is not null or undefined, then
0 commit comments