@@ -21,12 +21,12 @@ pub struct CachedPath(pub Arc<CachedPathImpl>);
2121pub struct CachedPathImpl {
2222 pub hash : u64 ,
2323 pub path : Box < Path > ,
24- pub parent : Option < ( Weak < CachedPathImpl > , PathBuf ) > ,
24+ pub parent : Option < Weak < CachedPathImpl > > ,
2525 pub is_node_modules : bool ,
2626 pub inside_node_modules : bool ,
2727 pub meta : OnceLock < Option < ( /* is_file */ bool , /* is_dir */ bool ) > > , // None means not found.
2828 pub canonicalized : OnceLock < ( Weak < CachedPathImpl > , PathBuf ) > ,
29- pub node_modules : OnceLock < Option < ( Weak < CachedPathImpl > , PathBuf ) > > ,
29+ pub node_modules : OnceLock < Option < Weak < CachedPathImpl > > > ,
3030 pub package_json : OnceLock < Option < PackageJsonIndex > > ,
3131 /// `tsconfig.json` found at path.
3232 pub tsconfig : OnceLock < Option < Arc < TsConfig > > > ,
@@ -40,7 +40,7 @@ impl CachedPathImpl {
4040 path : Box < Path > ,
4141 is_node_modules : bool ,
4242 inside_node_modules : bool ,
43- parent : Option < ( Weak < Self > , PathBuf ) > ,
43+ parent : Option < Weak < Self > > ,
4444 ) -> Self {
4545 Self {
4646 hash,
@@ -76,11 +76,11 @@ impl CachedPath {
7676 }
7777
7878 pub ( crate ) fn parent < Fs : FileSystem > ( & self , cache : & Cache < Fs > ) -> Option < Self > {
79- self . 0 . parent . as_ref ( ) . and_then ( |( weak, path_buf ) | {
79+ self . 0 . parent . as_ref ( ) . and_then ( |weak| {
8080 weak. upgrade ( ) . map ( CachedPath ) . or_else ( || {
8181 // Weak pointer upgrade failed - parent was cleared from cache
82- // Recreate it from the stored PathBuf
83- Some ( cache. value ( path_buf ) )
82+ // Recreate it by deriving the parent path
83+ self . path ( ) . parent ( ) . map ( |parent_path| cache. value ( parent_path ) )
8484 } )
8585 } )
8686 }
@@ -110,14 +110,13 @@ impl CachedPath {
110110 ) -> Option < Self > {
111111 self . node_modules
112112 . get_or_init ( || {
113- self . module_directory ( "node_modules" , cache, ctx)
114- . map ( |cp| ( Arc :: downgrade ( & cp. 0 ) , cp. to_path_buf ( ) ) )
113+ self . module_directory ( "node_modules" , cache, ctx) . map ( |cp| Arc :: downgrade ( & cp. 0 ) )
115114 } )
116115 . as_ref ( )
117- . and_then ( |( weak, path_buf ) | {
116+ . and_then ( |weak| {
118117 weak. upgrade ( ) . map ( CachedPath ) . or_else ( || {
119- // Weak pointer upgrade failed - recreate from stored PathBuf
120- Some ( cache . value ( path_buf ) )
118+ // Weak pointer upgrade failed - recreate by deriving the node_modules path
119+ Some ( self . push ( "node_modules" , cache ) )
121120 } )
122121 } )
123122 }
0 commit comments