@@ -11,7 +11,6 @@ use cfg_if::cfg_if;
1111#[ cfg( feature = "yarn_pnp" ) ]
1212use once_cell:: sync:: OnceCell ;
1313use papaya:: { HashMap , HashSet } ;
14- use parking_lot:: RwLock ;
1514use rustc_hash:: FxHasher ;
1615
1716use super :: borrowed_path:: BorrowedCachedPath ;
@@ -22,14 +21,11 @@ use crate::{
2221 context:: ResolveContext as Ctx , path:: PathUtil ,
2322} ;
2423
25- pub type PackageJsonIndex = usize ;
26-
2724/// Cache implementation used for caching filesystem access.
2825#[ derive( Default ) ]
2926pub struct Cache < Fs > {
3027 pub ( crate ) fs : Fs ,
3128 pub ( crate ) paths : HashSet < CachedPath , BuildHasherDefault < IdentityHasher > > ,
32- pub ( crate ) package_jsons : RwLock < Vec < Arc < PackageJson > > > ,
3329 /// Cache for raw/unbuilt tsconfigs (used when extending).
3430 pub ( crate ) tsconfigs_raw : HashMap < PathBuf , Arc < TsConfig > , BuildHasherDefault < FxHasher > > ,
3531 /// Cache for built/resolved tsconfigs (used for resolution).
@@ -43,7 +39,6 @@ impl<Fs: FileSystem> Cache<Fs> {
4339 self . paths . pin ( ) . clear ( ) ;
4440 self . tsconfigs_raw . pin ( ) . clear ( ) ;
4541 self . tsconfigs_built . pin ( ) . clear ( ) ;
46- self . package_jsons . write ( ) . clear ( ) ;
4742 }
4843
4944 #[ allow( clippy:: cast_possible_truncation) ]
@@ -145,9 +140,7 @@ impl<Fs: FileSystem> Cache<Fs> {
145140 break ;
146141 }
147142 }
148- self . find_package_json_impl ( & path, options, ctx) . map ( |option_index| {
149- option_index. and_then ( |index| self . package_jsons . read ( ) . get ( index) . cloned ( ) )
150- } )
143+ self . find_package_json_impl ( & path, options, ctx)
151144 }
152145
153146 /// Find package.json of a path by traversing parent directories.
@@ -160,7 +153,7 @@ impl<Fs: FileSystem> Cache<Fs> {
160153 path : & CachedPath ,
161154 options : & ResolveOptions ,
162155 ctx : & mut Ctx ,
163- ) -> Result < Option < PackageJsonIndex > , ResolveError > {
156+ ) -> Result < Option < Arc < PackageJson > > , ResolveError > {
164157 // Change to `std::sync::OnceLock::get_or_try_init` when it is stable.
165158 path. package_json
166159 . get_or_try_init ( || {
@@ -184,16 +177,7 @@ impl<Fs: FileSystem> Cache<Fs> {
184177 real_path,
185178 package_json_bytes,
186179 )
187- . map ( |package_json| {
188- let arc = Arc :: new ( package_json) ;
189- let index = {
190- let mut arena = self . package_jsons . write ( ) ;
191- let index = arena. len ( ) ;
192- arena. push ( arc) ;
193- index
194- } ;
195- Some ( index)
196- } )
180+ . map ( |package_json| Some ( Arc :: new ( package_json) ) )
197181 . map_err ( ResolveError :: Json )
198182 // https://github.com/webpack/enhanced-resolve/blob/58464fc7cb56673c9aa849e68e6300239601e615/lib/DescriptionFileUtils.js#L68-L82
199183 . inspect ( |_| {
@@ -306,7 +290,6 @@ impl<Fs: FileSystem> Cache<Fs> {
306290 . hasher ( BuildHasherDefault :: default ( ) )
307291 . resize_mode ( papaya:: ResizeMode :: Blocking )
308292 . build ( ) ,
309- package_jsons : RwLock :: new ( Vec :: with_capacity ( 512 ) ) ,
310293 tsconfigs_raw : HashMap :: builder ( )
311294 . hasher ( BuildHasherDefault :: default ( ) )
312295 . resize_mode ( papaya:: ResizeMode :: Blocking )
0 commit comments