@@ -90,7 +90,7 @@ use crate::{
9090 cache:: { Cache , CachedPath } ,
9191 context:: ResolveContext as Ctx ,
9292 package_json:: JSONMap ,
93- path:: { PathUtil , SLASH_START } ,
93+ path:: { path_to_str , PathUtil , SLASH_START } ,
9494 specifier:: Specifier ,
9595 tsconfig:: { ExtendsField , ProjectReference , TsConfig } ,
9696} ;
@@ -239,7 +239,7 @@ impl<Fs: FileSystem + Send + Sync> ResolverGeneric<Fs> {
239239 }
240240
241241 /// Wrap `resolve_impl` with `tracing` information
242- #[ cfg_attr( feature="enable_instrument" , tracing:: instrument( level=tracing:: Level :: DEBUG , skip_all, fields( path = %directory . to_string_lossy ( ) , specifier = specifier) ) ) ]
242+ #[ cfg_attr( feature="enable_instrument" , tracing:: instrument( level=tracing:: Level :: DEBUG , skip_all, fields( path = path_to_str ( directory ) , specifier = specifier) ) ) ]
243243 async fn resolve_tracing (
244244 & self ,
245245 directory : & Path ,
@@ -436,7 +436,7 @@ impl<Fs: FileSystem + Send + Sync> ResolverGeneric<Fs> {
436436 }
437437
438438 // 3. If X begins with './' or '/' or '../'
439- #[ cfg_attr( feature="enable_instrument" , tracing:: instrument( level=tracing:: Level :: DEBUG , skip_all, fields( specifier = specifier, path = % cached_path. path( ) . to_string_lossy ( ) ) ) ) ]
439+ #[ cfg_attr( feature="enable_instrument" , tracing:: instrument( level=tracing:: Level :: DEBUG , skip_all, fields( specifier = specifier, path = path_to_str ( cached_path. path( ) ) ) ) ) ]
440440 async fn require_relative (
441441 & self ,
442442 cached_path : & CachedPath ,
@@ -536,7 +536,7 @@ impl<Fs: FileSystem + Send + Sync> ResolverGeneric<Fs> {
536536 Ok ( ( parsed, None ) )
537537 }
538538
539- #[ cfg_attr( feature="enable_instrument" , tracing:: instrument( level=tracing:: Level :: DEBUG , skip_all, fields( specifier = specifier, path = % cached_path. path( ) . to_string_lossy ( ) ) ) ) ]
539+ #[ cfg_attr( feature="enable_instrument" , tracing:: instrument( level=tracing:: Level :: DEBUG , skip_all, fields( specifier = specifier, path = path_to_str ( cached_path. path( ) ) ) ) ) ]
540540 async fn load_package_self_or_node_modules (
541541 & self ,
542542 cached_path : & CachedPath ,
@@ -590,7 +590,7 @@ impl<Fs: FileSystem + Send + Sync> ResolverGeneric<Fs> {
590590 Ok ( None )
591591 }
592592
593- #[ cfg_attr( feature="enable_instrument" , tracing:: instrument( level=tracing:: Level :: DEBUG , skip_all, fields( path = % cached_path. path( ) . to_string_lossy ( ) ) ) ) ]
593+ #[ cfg_attr( feature="enable_instrument" , tracing:: instrument( level=tracing:: Level :: DEBUG , skip_all, fields( path = path_to_str ( cached_path. path( ) ) ) ) ) ]
594594 async fn load_as_file ( & self , cached_path : & CachedPath , ctx : & mut Ctx ) -> ResolveResult {
595595 // enhanced-resolve feature: extension_alias
596596 if let Some ( path) = self . load_extension_alias ( cached_path, ctx) . await ? {
@@ -653,7 +653,7 @@ impl<Fs: FileSystem + Send + Sync> ResolverGeneric<Fs> {
653653 self . load_index ( cached_path, ctx) . await
654654 }
655655
656- #[ cfg_attr( feature="enable_instrument" , tracing:: instrument( level=tracing:: Level :: DEBUG , skip_all, fields( specifier = specifier, path = % cached_path. path( ) . to_string_lossy ( ) ) ) ) ]
656+ #[ cfg_attr( feature="enable_instrument" , tracing:: instrument( level=tracing:: Level :: DEBUG , skip_all, fields( specifier = specifier, path = path_to_str ( cached_path. path( ) ) ) ) ) ]
657657 async fn load_as_file_or_directory (
658658 & self ,
659659 cached_path : & CachedPath ,
@@ -681,7 +681,7 @@ impl<Fs: FileSystem + Send + Sync> ResolverGeneric<Fs> {
681681 Ok ( None )
682682 }
683683
684- #[ cfg_attr( feature="enable_instrument" , tracing:: instrument( level=tracing:: Level :: DEBUG , skip_all, fields( path = % path. path( ) . to_string_lossy ( ) ) ) ) ]
684+ #[ cfg_attr( feature="enable_instrument" , tracing:: instrument( level=tracing:: Level :: DEBUG , skip_all, fields( path = path_to_str ( path. path( ) ) ) ) ) ]
685685 async fn load_extensions (
686686 & self ,
687687 path : & CachedPath ,
@@ -691,10 +691,10 @@ impl<Fs: FileSystem + Send + Sync> ResolverGeneric<Fs> {
691691 if ctx. fully_specified {
692692 return Ok ( None ) ;
693693 }
694- let path = path. path ( ) . as_os_str ( ) ;
694+ let path = path_to_str ( path. path ( ) ) ;
695695 // 8 is wild guess for max extension length
696696 let mut path_with_extension_buffer = String :: with_capacity ( path. len ( ) + 8 ) ;
697- path_with_extension_buffer. push_str ( & path. to_string_lossy ( ) ) ;
697+ path_with_extension_buffer. push_str ( path) ;
698698 let base_len = path_with_extension_buffer. len ( ) ;
699699
700700 for extension in extensions {
@@ -708,7 +708,7 @@ impl<Fs: FileSystem + Send + Sync> ResolverGeneric<Fs> {
708708 Ok ( None )
709709 }
710710
711- #[ cfg_attr( feature="enable_instrument" , tracing:: instrument( level=tracing:: Level :: DEBUG , skip_all, fields( path = % cached_path. path( ) . to_string_lossy ( ) ) ) ) ]
711+ #[ cfg_attr( feature="enable_instrument" , tracing:: instrument( level=tracing:: Level :: DEBUG , skip_all, fields( path = path_to_str ( cached_path. path( ) ) ) ) ) ]
712712 async fn load_realpath (
713713 & self ,
714714 cached_path : & CachedPath ,
@@ -758,7 +758,7 @@ impl<Fs: FileSystem + Send + Sync> ResolverGeneric<Fs> {
758758 true
759759 }
760760
761- #[ cfg_attr( feature="enable_instrument" , tracing:: instrument( level=tracing:: Level :: DEBUG , skip_all, fields( path = % cached_path. path( ) . to_string_lossy ( ) ) ) ) ]
761+ #[ cfg_attr( feature="enable_instrument" , tracing:: instrument( level=tracing:: Level :: DEBUG , skip_all, fields( path = path_to_str ( cached_path. path( ) ) ) ) ) ]
762762 async fn load_index ( & self , cached_path : & CachedPath , ctx : & mut Ctx ) -> ResolveResult {
763763 for main_file in & self . options . main_files {
764764 let main_path = cached_path. path ( ) . normalize_with ( main_file) ;
@@ -798,7 +798,7 @@ impl<Fs: FileSystem + Send + Sync> ResolverGeneric<Fs> {
798798 }
799799 }
800800 // enhanced-resolve: try file as alias
801- let alias_specifier = cached_path. path ( ) . to_string_lossy ( ) ;
801+ let alias_specifier = path_to_str ( cached_path. path ( ) ) ;
802802 if let Some ( path) = self
803803 . load_alias ( cached_path, & alias_specifier, & self . options . alias , ctx)
804804 . await ?
@@ -812,7 +812,7 @@ impl<Fs: FileSystem + Send + Sync> ResolverGeneric<Fs> {
812812 Ok ( None )
813813 }
814814
815- #[ cfg_attr( feature="enable_instrument" , tracing:: instrument( level=tracing:: Level :: DEBUG , skip_all, fields( specifier = specifier, path = % cached_path. path( ) . to_string_lossy ( ) ) ) ) ]
815+ #[ cfg_attr( feature="enable_instrument" , tracing:: instrument( level=tracing:: Level :: DEBUG , skip_all, fields( specifier = specifier, path = path_to_str ( cached_path. path( ) ) ) ) ) ]
816816 async fn load_node_modules (
817817 & self ,
818818 cached_path : & CachedPath ,
@@ -956,7 +956,7 @@ impl<Fs: FileSystem + Send + Sync> ResolverGeneric<Fs> {
956956 }
957957
958958 #[ cfg( feature = "yarn_pnp" ) ]
959- #[ cfg_attr( feature = "enable_instrument" , tracing:: instrument( level=tracing:: Level :: DEBUG , skip_all, fields( path = % cached_path. path( ) . to_string_lossy ( ) ) ) ) ]
959+ #[ cfg_attr( feature = "enable_instrument" , tracing:: instrument( level=tracing:: Level :: DEBUG , skip_all, fields( path = path_to_str ( cached_path. path( ) ) ) ) ) ]
960960 fn find_pnp_manifest ( & self , cached_path : & CachedPath ) -> Option < Arc < ( PathBuf , pnp:: Manifest ) > > {
961961 // 1. Already have a manifest → return it (covers global cache paths too)
962962 if let Some ( manifest) = self . pnp_manifest . load_full ( ) {
@@ -1000,7 +1000,7 @@ impl<Fs: FileSystem + Send + Sync> ResolverGeneric<Fs> {
10001000 }
10011001
10021002 #[ cfg( feature = "yarn_pnp" ) ]
1003- #[ cfg_attr( feature="enable_instrument" , tracing:: instrument( level=tracing:: Level :: DEBUG , skip_all, fields( specifier = specifier, path = % cached_path. path( ) . to_string_lossy ( ) ) ) ) ]
1003+ #[ cfg_attr( feature="enable_instrument" , tracing:: instrument( level=tracing:: Level :: DEBUG , skip_all, fields( specifier = specifier, path = path_to_str ( cached_path. path( ) ) ) ) ) ]
10041004 async fn load_pnp (
10051005 & self ,
10061006 cached_path : & CachedPath ,
@@ -1108,7 +1108,7 @@ impl<Fs: FileSystem + Send + Sync> ResolverGeneric<Fs> {
11081108 Ok ( None )
11091109 }
11101110
1111- #[ cfg_attr( feature="enable_instrument" , tracing:: instrument( level=tracing:: Level :: DEBUG , skip_all, fields( specifier = specifier, path = % cached_path. path( ) . to_string_lossy ( ) ) ) ) ]
1111+ #[ cfg_attr( feature="enable_instrument" , tracing:: instrument( level=tracing:: Level :: DEBUG , skip_all, fields( specifier = specifier, path = path_to_str ( cached_path. path( ) ) ) ) ) ]
11121112 async fn load_package_self (
11131113 & self ,
11141114 cached_path : & CachedPath ,
@@ -1152,7 +1152,7 @@ impl<Fs: FileSystem + Send + Sync> ResolverGeneric<Fs> {
11521152 }
11531153
11541154 /// RESOLVE_ESM_MATCH(MATCH)
1155- #[ cfg_attr( feature="enable_instrument" , tracing:: instrument( level=tracing:: Level :: DEBUG , skip_all, fields( specifier = specifier, path = % cached_path. path( ) . to_string_lossy ( ) ) ) ) ]
1155+ #[ cfg_attr( feature="enable_instrument" , tracing:: instrument( level=tracing:: Level :: DEBUG , skip_all, fields( specifier = specifier, path = path_to_str ( cached_path. path( ) ) ) ) ) ]
11561156 async fn resolve_esm_match (
11571157 & self ,
11581158 specifier : & str ,
@@ -1192,7 +1192,7 @@ impl<Fs: FileSystem + Send + Sync> ResolverGeneric<Fs> {
11921192 }
11931193
11941194 /// enhanced-resolve: AliasFieldPlugin for [ResolveOptions::alias_fields]
1195- #[ cfg_attr( feature="enable_instrument" , tracing:: instrument( level=tracing:: Level :: DEBUG , skip_all, fields( specifier = module_specifier, path = % cached_path. path( ) . to_string_lossy ( ) ) ) ) ]
1195+ #[ cfg_attr( feature="enable_instrument" , tracing:: instrument( level=tracing:: Level :: DEBUG , skip_all, fields( specifier = module_specifier, path = path_to_str ( cached_path. path( ) ) ) ) ) ]
11961196 async fn load_browser_field (
11971197 & self ,
11981198 cached_path : & CachedPath ,
@@ -1332,7 +1332,7 @@ impl<Fs: FileSystem + Send + Sync> ResolverGeneric<Fs> {
13321332 Cow :: Borrowed ( alias_value)
13331333 } else {
13341334 let normalized = alias_path. normalize_with ( tail) ;
1335- Cow :: Owned ( normalized . to_string_lossy ( ) . to_string ( ) )
1335+ Cow :: Owned ( path_to_str ( & normalized ) . to_string ( ) )
13361336 }
13371337 } ;
13381338
@@ -1397,14 +1397,14 @@ impl<Fs: FileSystem + Send + Sync> ResolverGeneric<Fs> {
13971397 // Create a meaningful error message.
13981398 let dir = path. parent ( ) . unwrap ( ) . to_path_buf ( ) ;
13991399 let filename_without_extension = Path :: new ( filename) . with_extension ( "" ) ;
1400- let filename_without_extension = filename_without_extension . to_string_lossy ( ) ;
1400+ let filename_without_extension = path_to_str ( & filename_without_extension ) ;
14011401 let files = extensions
14021402 . iter ( )
14031403 . map ( |ext| format ! ( "{filename_without_extension}{ext}" ) )
14041404 . collect :: < Vec < _ > > ( )
14051405 . join ( "," ) ;
14061406 Err ( ResolveError :: ExtensionAlias (
1407- filename. to_string_lossy ( ) . to_string ( ) ,
1407+ filename. to_str ( ) . expect ( "path should be UTF-8" ) . to_string ( ) ,
14081408 files,
14091409 dir,
14101410 ) )
0 commit comments