@@ -9,6 +9,12 @@ use pnp::fs::{LruZipCache, VPath, VPathInfo, ZipCache};
9
9
10
10
/// File System abstraction used for `ResolverGeneric`
11
11
pub trait FileSystem : Send + Sync {
12
+ #[ cfg( feature = "yarn_pnp" ) ]
13
+ fn new ( yarn_pnp : bool ) -> Self ;
14
+
15
+ #[ cfg( not( feature = "yarn_pnp" ) ) ]
16
+ fn new ( ) -> Self ;
17
+
12
18
/// See [std::fs::read_to_string]
13
19
///
14
20
/// # Errors
@@ -95,25 +101,13 @@ impl From<fs::Metadata> for FileMetadata {
95
101
}
96
102
}
97
103
98
- /// Operating System
99
- #[ cfg( feature = "yarn_pnp" ) ]
100
- pub struct FileSystemOs {
101
- pnp_lru : LruZipCache < Vec < u8 > > ,
102
- }
103
-
104
104
#[ cfg( not( feature = "yarn_pnp" ) ) ]
105
105
pub struct FileSystemOs ;
106
106
107
- impl Default for FileSystemOs {
108
- fn default ( ) -> Self {
109
- cfg_if ! {
110
- if #[ cfg( feature = "yarn_pnp" ) ] {
111
- Self { pnp_lru: LruZipCache :: new( 50 , pnp:: fs:: open_zip_via_read_p) }
112
- } else {
113
- Self
114
- }
115
- }
116
- }
107
+ #[ cfg( feature = "yarn_pnp" ) ]
108
+ pub struct FileSystemOs {
109
+ pnp_lru : LruZipCache < Vec < u8 > > ,
110
+ yarn_pnp : bool ,
117
111
}
118
112
119
113
impl FileSystemOs {
@@ -171,38 +165,51 @@ impl FileSystemOs {
171
165
}
172
166
173
167
impl FileSystem for FileSystemOs {
168
+ #[ cfg( feature = "yarn_pnp" ) ]
169
+ fn new ( yarn_pnp : bool ) -> Self {
170
+ Self { pnp_lru : LruZipCache :: new ( 50 , pnp:: fs:: open_zip_via_read_p) , yarn_pnp }
171
+ }
172
+
173
+ #[ cfg( not( feature = "yarn_pnp" ) ) ]
174
+ fn new ( ) -> Self {
175
+ Self
176
+ }
177
+
174
178
fn read_to_string ( & self , path : & Path ) -> io:: Result < String > {
175
179
cfg_if ! {
176
180
if #[ cfg( feature = "yarn_pnp" ) ] {
177
- match VPath :: from( path) ? {
178
- VPath :: Zip ( info) => {
179
- self . pnp_lru. read_to_string( info. physical_base_path( ) , info. zip_path)
181
+ if self . yarn_pnp {
182
+ return match VPath :: from( path) ? {
183
+ VPath :: Zip ( info) => {
184
+ self . pnp_lru. read_to_string( info. physical_base_path( ) , info. zip_path)
185
+ }
186
+ VPath :: Virtual ( info) => Self :: read_to_string( & info. physical_base_path( ) ) ,
187
+ VPath :: Native ( path) => Self :: read_to_string( & path) ,
180
188
}
181
- VPath :: Virtual ( info) => Self :: read_to_string( & info. physical_base_path( ) ) ,
182
- VPath :: Native ( path) => Self :: read_to_string( & path) ,
183
189
}
184
- } else {
185
- Self :: read_to_string( path)
186
190
}
187
191
}
192
+ Self :: read_to_string ( path)
188
193
}
189
194
190
195
fn metadata ( & self , path : & Path ) -> io:: Result < FileMetadata > {
191
196
cfg_if ! {
192
197
if #[ cfg( feature = "yarn_pnp" ) ] {
193
- match VPath :: from( path) ? {
194
- VPath :: Zip ( info) => self
195
- . pnp_lru
196
- . file_type( info. physical_base_path( ) , info. zip_path)
197
- . map( FileMetadata :: from) ,
198
- VPath :: Virtual ( info) => {
199
- Self :: metadata( & info. physical_base_path( ) )
198
+ if self . yarn_pnp {
199
+ return match VPath :: from( path) ? {
200
+ VPath :: Zip ( info) => self
201
+ . pnp_lru
202
+ . file_type( info. physical_base_path( ) , info. zip_path)
203
+ . map( FileMetadata :: from) ,
204
+ VPath :: Virtual ( info) => {
205
+ Self :: metadata( & info. physical_base_path( ) )
206
+ }
207
+ VPath :: Native ( path) => Self :: metadata( & path) ,
200
208
}
201
- VPath :: Native ( path) => Self :: metadata( & path) ,
202
209
}
203
- } else {
204
- Self :: metadata( path) }
210
+ }
205
211
}
212
+ Self :: metadata ( path)
206
213
}
207
214
208
215
fn symlink_metadata ( & self , path : & Path ) -> io:: Result < FileMetadata > {
@@ -212,15 +219,16 @@ impl FileSystem for FileSystemOs {
212
219
fn read_link ( & self , path : & Path ) -> io:: Result < PathBuf > {
213
220
cfg_if ! {
214
221
if #[ cfg( feature = "yarn_pnp" ) ] {
215
- match VPath :: from( path) ? {
216
- VPath :: Zip ( info) => Self :: read_link( & info. physical_base_path( ) . join( info. zip_path) ) ,
217
- VPath :: Virtual ( info) => Self :: read_link( & info. physical_base_path( ) ) ,
218
- VPath :: Native ( path) => Self :: read_link( & path) ,
222
+ if self . yarn_pnp {
223
+ return match VPath :: from( path) ? {
224
+ VPath :: Zip ( info) => Self :: read_link( & info. physical_base_path( ) . join( info. zip_path) ) ,
225
+ VPath :: Virtual ( info) => Self :: read_link( & info. physical_base_path( ) ) ,
226
+ VPath :: Native ( path) => Self :: read_link( & path) ,
227
+ }
219
228
}
220
- } else {
221
- Self :: read_link( path)
222
229
}
223
230
}
231
+ Self :: read_link ( path)
224
232
}
225
233
}
226
234
0 commit comments