@@ -395,8 +395,7 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
395395 c,
396396 Component :: CurDir | Component :: ParentDir | Component :: Normal ( _)
397397 ) ) ) ;
398- let path = cached_path. path ( ) . normalize_with ( specifier) ;
399- let cached_path = self . cache . value ( & path) ;
398+ let cached_path = cached_path. normalize_with ( specifier, & self . cache ) ;
400399 // a. LOAD_AS_FILE(Y + X)
401400 // b. LOAD_AS_DIRECTORY(Y + X)
402401 if let Some ( path) = self . load_as_file_or_directory ( & cached_path, specifier, ctx) ? {
@@ -546,9 +545,8 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
546545 // b. If "main" is a falsy value, GOTO 2.
547546 for main_field in package_json. main_fields ( & self . options . main_fields ) {
548547 // c. let M = X + (json main field)
549- let main_field_path = cached_path. path ( ) . normalize_with ( main_field) ;
548+ let cached_path = cached_path. normalize_with ( main_field, & self . cache ) ;
550549 // d. LOAD_AS_FILE(M)
551- let cached_path = self . cache . value ( & main_field_path) ;
552550 if let Some ( path) = self . load_as_file ( & cached_path, ctx) ? {
553551 return Ok ( Some ( path) ) ;
554552 }
@@ -596,12 +594,8 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
596594 if ctx. fully_specified {
597595 return Ok ( None ) ;
598596 }
599- let path = path. path ( ) . as_os_str ( ) ;
600597 for extension in extensions {
601- let mut path_with_extension = path. to_os_string ( ) ;
602- path_with_extension. reserve_exact ( extension. len ( ) ) ;
603- path_with_extension. push ( extension) ;
604- let cached_path = self . cache . value ( Path :: new ( & path_with_extension) ) ;
598+ let cached_path = path. add_extension ( extension, & self . cache ) ;
605599 if let Some ( path) = self . load_alias_or_file ( & cached_path, ctx) ? {
606600 return Ok ( Some ( path) ) ;
607601 }
@@ -648,8 +642,7 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
648642
649643 fn load_index ( & self , cached_path : & CachedPath , ctx : & mut Ctx ) -> ResolveResult {
650644 for main_file in & self . options . main_files {
651- let main_path = cached_path. path ( ) . normalize_with ( main_file) ;
652- let cached_path = self . cache . value ( & main_path) ;
645+ let cached_path = cached_path. normalize_with ( main_file, & self . cache ) ;
653646 if self . options . enforce_extension . is_disabled ( ) {
654647 if let Some ( path) = self . load_alias_or_file ( & cached_path, ctx) ? {
655648 return Ok ( Some ( path) ) ;
@@ -722,8 +715,7 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
722715 // 1. Try to interpret X as a combination of NAME and SUBPATH where the name
723716 // may have a @scope/ prefix and the subpath begins with a slash (`/`).
724717 if !package_name. is_empty ( ) {
725- let package_path = cached_path. path ( ) . normalize_with ( package_name) ;
726- let cached_path = self . cache . value ( & package_path) ;
718+ let cached_path = cached_path. normalize_with ( package_name, & self . cache ) ;
727719 // Try foo/node_modules/package_name
728720 if cached_path. is_dir ( & self . cache . fs , ctx) {
729721 // a. LOAD_PACKAGE_EXPORTS(X, DIR)
@@ -752,8 +744,7 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
752744 // Try as file or directory for all other cases
753745 // b. LOAD_AS_FILE(DIR/X)
754746 // c. LOAD_AS_DIRECTORY(DIR/X)
755- let node_module_file = cached_path. path ( ) . normalize_with ( specifier) ;
756- let cached_path = self . cache . value ( & node_module_file) ;
747+ let cached_path = cached_path. normalize_with ( specifier, & self . cache ) ;
757748 if let Some ( path) = self . load_as_file_or_directory ( & cached_path, specifier, ctx) ? {
758749 return Ok ( Some ( path) ) ;
759750 }
@@ -984,8 +975,8 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
984975 }
985976 }
986977 AliasValue :: Ignore => {
987- let path = cached_path. path ( ) . normalize_with ( alias_key) ;
988- return Err ( ResolveError :: Ignored ( path ) ) ;
978+ let cached_path = cached_path. normalize_with ( alias_key, & self . cache ) ;
979+ return Err ( ResolveError :: Ignored ( cached_path . to_path_buf ( ) ) ) ;
989980 }
990981 }
991982 }
@@ -1025,8 +1016,8 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
10251016
10261017 // Remove the leading slash so the final path is concatenated.
10271018 let tail = tail. trim_start_matches ( SLASH_START ) ;
1028- let normalized = alias_value . normalize_with ( tail) ;
1029- Cow :: Owned ( normalized. to_string_lossy ( ) . to_string ( ) )
1019+ let normalized = alias_value_cached_path . normalize_with ( tail, & self . cache ) ;
1020+ Cow :: Owned ( normalized. path ( ) . to_string_lossy ( ) . to_string ( ) )
10301021 } ;
10311022
10321023 * should_stop = true ;
@@ -1067,13 +1058,9 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
10671058 } ;
10681059 let path = cached_path. path ( ) ;
10691060 let Some ( filename) = path. file_name ( ) else { return Ok ( None ) } ;
1070- let path_without_extension = path. with_extension ( "" ) ;
10711061 ctx. with_fully_specified ( true ) ;
10721062 for extension in extensions {
1073- let mut path_with_extension = path_without_extension. clone ( ) . into_os_string ( ) ;
1074- path_with_extension. reserve_exact ( extension. len ( ) ) ;
1075- path_with_extension. push ( extension) ;
1076- let cached_path = self . cache . value ( Path :: new ( & path_with_extension) ) ;
1063+ let cached_path = cached_path. replace_extension ( extension, & self . cache ) ;
10771064 if let Some ( path) = self . load_alias_or_file ( & cached_path, ctx) ? {
10781065 ctx. with_fully_specified ( false ) ;
10791066 return Ok ( Some ( path) ) ;
@@ -1271,8 +1258,7 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
12711258 continue ;
12721259 } ;
12731260 // 2. Set parentURL to the parent folder URL of parentURL.
1274- let package_path = cached_path. path ( ) . normalize_with ( package_name) ;
1275- let cached_path = self . cache . value ( & package_path) ;
1261+ let cached_path = cached_path. normalize_with ( package_name, & self . cache ) ;
12761262 // 3. If the folder at packageURL does not exist, then
12771263 // 1. Continue the next loop iteration.
12781264 if cached_path. is_dir ( & self . cache . fs , ctx) {
@@ -1297,8 +1283,8 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
12971283 // 1. If pjson.main is a string, then
12981284 for main_field in package_json. main_fields ( & self . options . main_fields ) {
12991285 // 1. Return the URL resolution of main in packageURL.
1300- let path = cached_path . path ( ) . normalize_with ( main_field ) ;
1301- let cached_path = self . cache . value ( & path ) ;
1286+ let cached_path =
1287+ cached_path . normalize_with ( main_field , & self . cache ) ;
13021288 if cached_path. is_file ( & self . cache . fs , ctx) {
13031289 return Ok ( Some ( cached_path) ) ;
13041290 }
0 commit comments