@@ -116,7 +116,9 @@ pub struct ResolverGeneric<Fs> {
116
116
options : ResolveOptions ,
117
117
cache : Arc < Cache < Fs > > ,
118
118
#[ cfg( feature = "yarn_pnp" ) ]
119
- pnp_cache : Arc < DashMap < CachedPath , Option < pnp:: Manifest > > > ,
119
+ pnp_manifest_content_cache : Arc < DashMap < CachedPath , Option < pnp:: Manifest > > > ,
120
+ #[ cfg( feature = "yarn_pnp" ) ]
121
+ pnp_manifest_path_cache : Arc < DashMap < PathBuf , Option < CachedPath > > > ,
120
122
}
121
123
122
124
impl < Fs > fmt:: Debug for ResolverGeneric < Fs > {
@@ -137,7 +139,9 @@ impl<Fs: Send + Sync + FileSystem + Default> ResolverGeneric<Fs> {
137
139
options : options. sanitize ( ) ,
138
140
cache : Arc :: new ( Cache :: new ( Fs :: default ( ) ) ) ,
139
141
#[ cfg( feature = "yarn_pnp" ) ]
140
- pnp_cache : Arc :: new ( DashMap :: default ( ) ) ,
142
+ pnp_manifest_content_cache : Arc :: new ( DashMap :: default ( ) ) ,
143
+ #[ cfg( feature = "yarn_pnp" ) ]
144
+ pnp_manifest_path_cache : Arc :: new ( DashMap :: default ( ) ) ,
141
145
}
142
146
}
143
147
}
@@ -148,7 +152,9 @@ impl<Fs: FileSystem + Send + Sync> ResolverGeneric<Fs> {
148
152
options : options. sanitize ( ) ,
149
153
cache : Arc :: new ( Cache :: new ( file_system) ) ,
150
154
#[ cfg( feature = "yarn_pnp" ) ]
151
- pnp_cache : Arc :: new ( DashMap :: default ( ) ) ,
155
+ pnp_manifest_content_cache : Arc :: new ( DashMap :: default ( ) ) ,
156
+ #[ cfg( feature = "yarn_pnp" ) ]
157
+ pnp_manifest_path_cache : Arc :: new ( DashMap :: default ( ) ) ,
152
158
}
153
159
}
154
160
@@ -159,7 +165,9 @@ impl<Fs: FileSystem + Send + Sync> ResolverGeneric<Fs> {
159
165
options : options. sanitize ( ) ,
160
166
cache : Arc :: clone ( & self . cache ) ,
161
167
#[ cfg( feature = "yarn_pnp" ) ]
162
- pnp_cache : Arc :: clone ( & self . pnp_cache ) ,
168
+ pnp_manifest_content_cache : Arc :: clone ( & self . pnp_manifest_content_cache ) ,
169
+ #[ cfg( feature = "yarn_pnp" ) ]
170
+ pnp_manifest_path_cache : Arc :: clone ( & self . pnp_manifest_path_cache ) ,
163
171
}
164
172
}
165
173
@@ -172,7 +180,10 @@ impl<Fs: FileSystem + Send + Sync> ResolverGeneric<Fs> {
172
180
pub fn clear_cache ( & self ) {
173
181
self . cache . clear ( ) ;
174
182
#[ cfg( feature = "yarn_pnp" ) ]
175
- self . pnp_cache . clear ( ) ;
183
+ {
184
+ self . pnp_manifest_content_cache . clear ( ) ;
185
+ self . pnp_manifest_path_cache . clear ( ) ;
186
+ }
176
187
}
177
188
178
189
/// Resolve `specifier` at an absolute path to a `directory`.
@@ -801,10 +812,19 @@ impl<Fs: FileSystem + Send + Sync> ResolverGeneric<Fs> {
801
812
& self ,
802
813
cached_path : & CachedPath ,
803
814
) -> Ref < ' _ , CachedPath , Option < pnp:: Manifest > > {
815
+ let base_path = cached_path. to_path_buf ( ) ;
816
+
817
+ let cached_manifest_path =
818
+ self . pnp_manifest_path_cache . entry ( base_path. clone ( ) ) . or_insert_with ( || {
819
+ pnp:: find_closest_pnp_manifest_path ( base_path) . map ( |p| self . cache . value ( & p) )
820
+ } ) ;
821
+
822
+ let cache_key = cached_manifest_path. as_ref ( ) . unwrap_or ( cached_path) ;
823
+
804
824
let entry = self
805
- . pnp_cache
806
- . entry ( cached_path . clone ( ) )
807
- . or_insert_with ( || pnp:: find_pnp_manifest ( cached_path . path ( ) ) . unwrap ( ) ) ;
825
+ . pnp_manifest_content_cache
826
+ . entry ( cache_key . clone ( ) )
827
+ . or_insert_with ( || pnp:: load_pnp_manifest ( cache_key . path ( ) ) . ok ( ) ) ;
808
828
809
829
entry. downgrade ( )
810
830
}
0 commit comments