@@ -309,7 +309,7 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
309309 break ;
310310 }
311311 if self . cache . is_dir ( cp, ctx) {
312- if let Some ( ( _ , package_json) ) =
312+ if let Some ( package_json) =
313313 self . cache . get_package_json ( cp, & self . options , ctx) ?
314314 {
315315 last = Some ( package_json) ;
@@ -318,9 +318,7 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
318318 }
319319 Ok ( last)
320320 } else {
321- cached_path
322- . find_package_json ( & self . options , self . cache . as_ref ( ) , ctx)
323- . map ( |result| result. map ( |( _, p) | p) )
321+ cached_path. find_package_json ( & self . options , self . cache . as_ref ( ) , ctx)
324322 }
325323 }
326324
@@ -619,7 +617,7 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
619617 ) -> ResolveResult {
620618 // 1. Find the closest package scope SCOPE to DIR.
621619 // 2. If no scope was found, return.
622- let Some ( ( _ , package_json) ) =
620+ let Some ( package_json) =
623621 cached_path. find_package_json ( & self . options , self . cache . as_ref ( ) , ctx) ?
624622 else {
625623 return Ok ( None ) ;
@@ -656,9 +654,7 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
656654 fn load_as_directory ( & self , cached_path : & CachedPath , ctx : & mut Ctx ) -> ResolveResult {
657655 // 1. If X/package.json is a file,
658656 // a. Parse X/package.json, and look for "main" field.
659- if let Some ( ( _, package_json) ) =
660- self . cache . get_package_json ( cached_path, & self . options , ctx) ?
661- {
657+ if let Some ( package_json) = self . cache . get_package_json ( cached_path, & self . options , ctx) ? {
662658 // b. If "main" is a falsy value, GOTO 2.
663659 for main_field in package_json. main_fields ( & self . options . main_fields ) {
664660 // ref https://github.com/webpack/enhanced-resolve/blob/main/lib/MainFieldPlugin.js#L66-L67
@@ -805,11 +801,11 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
805801 ctx : & mut Ctx ,
806802 ) -> ResolveResult {
807803 if !self . options . alias_fields . is_empty ( ) {
808- if let Some ( ( package_url , package_json) ) =
804+ if let Some ( package_json) =
809805 cached_path. find_package_json ( & self . options , self . cache . as_ref ( ) , ctx) ?
810806 {
811807 if let Some ( path) =
812- self . load_browser_field ( cached_path, None , & package_url , & package_json, ctx) ?
808+ self . load_browser_field ( cached_path, None , & package_json, ctx) ?
813809 {
814810 return Ok ( Some ( path) ) ;
815811 }
@@ -1044,8 +1040,7 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
10441040 ) -> ResolveResult {
10451041 // 2. If X does not match this pattern or DIR/NAME/package.json is not a file,
10461042 // return.
1047- let Some ( ( _, package_json) ) =
1048- self . cache . get_package_json ( cached_path, & self . options , ctx) ?
1043+ let Some ( package_json) = self . cache . get_package_json ( cached_path, & self . options , ctx) ?
10491044 else {
10501045 return Ok ( None ) ;
10511046 } ;
@@ -1073,7 +1068,7 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
10731068 ) -> ResolveResult {
10741069 // 1. Find the closest package scope SCOPE to DIR.
10751070 // 2. If no scope was found, return.
1076- let Some ( ( package_url , package_json) ) =
1071+ let Some ( package_json) =
10771072 cached_path. find_package_json ( & self . options , self . cache . as_ref ( ) , ctx) ?
10781073 else {
10791074 return Ok ( None ) ;
@@ -1089,6 +1084,7 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
10891084 // defined in the ESM resolver.
10901085 // Note: The subpath is not prepended with a dot on purpose
10911086 // because `package_exports_resolve` matches subpath without the leading dot.
1087+ let package_url = self . cache . value ( package_json. path . parent ( ) . unwrap ( ) ) ;
10921088 for exports in package_json. exports_fields ( & self . options . exports_fields ) {
10931089 if let Some ( cached_path) = self . package_exports_resolve (
10941090 & package_url,
@@ -1101,7 +1097,7 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
11011097 }
11021098 }
11031099 }
1104- self . load_browser_field ( cached_path, Some ( specifier) , & package_url , & package_json, ctx)
1100+ self . load_browser_field ( cached_path, Some ( specifier) , & package_json, ctx)
11051101 }
11061102
11071103 /// RESOLVE_ESM_MATCH(MATCH)
@@ -1128,7 +1124,6 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
11281124 & self ,
11291125 cached_path : & CachedPath ,
11301126 module_specifier : Option < & str > ,
1131- package_url : & CachedPath ,
11321127 package_json : & PackageJson ,
11331128 ctx : & mut Ctx ,
11341129 ) -> ResolveResult {
@@ -1162,7 +1157,8 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
11621157 }
11631158 ctx. with_resolving_alias ( new_specifier. to_string ( ) ) ;
11641159 ctx. with_fully_specified ( false ) ;
1165- self . require ( package_url, new_specifier, ctx) . map ( Some )
1160+ let package_url = self . cache . value ( package_json. path ( ) . parent ( ) . unwrap ( ) ) ;
1161+ self . require ( & package_url, new_specifier, ctx) . map ( Some )
11661162 }
11671163
11681164 /// enhanced-resolve: AliasPlugin for [ResolveOptions::alias] and [ResolveOptions::fallback].
@@ -1546,7 +1542,7 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
15461542 // 1. Continue the next loop iteration.
15471543 if self . cache . is_dir ( & cached_path, ctx) {
15481544 // 4. Let pjson be the result of READ_PACKAGE_JSON(packageURL).
1549- if let Some ( ( _ , package_json) ) =
1545+ if let Some ( package_json) =
15501546 self . cache . get_package_json ( & cached_path, & self . options , ctx) ?
15511547 {
15521548 // 5. If pjson is not null and pjson.exports is not null or undefined, then
@@ -2088,7 +2084,7 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
20882084 let package_json =
20892085 cached_path. find_package_json ( & self . options , self . cache . as_ref ( ) , ctx) ?;
20902086 // 9. Let packageType be null.
2091- if let Some ( ( _ , package_json) ) = package_json {
2087+ if let Some ( package_json) = package_json {
20922088 // 10. If pjson?.type is "module" or "commonjs", then
20932089 // 1. Set packageType to pjson.type.
20942090 if let Some ( ty) = package_json. r#type ( ) {
0 commit comments