@@ -135,8 +135,6 @@ pub type Resolver = ResolverGeneric<FsCache<FileSystemOs>>;
135
135
pub struct ResolverGeneric < C : Cache > {
136
136
options : ResolveOptions ,
137
137
cache : Arc < C > ,
138
- #[ cfg( feature = "yarn_pnp" ) ]
139
- pnp_cache : Arc < papaya:: HashMap < C :: Cp , Option < pnp:: Manifest > > > ,
140
138
}
141
139
142
140
impl < C : Cache > fmt:: Debug for ResolverGeneric < C > {
@@ -154,34 +152,19 @@ impl<C: Cache + Default> Default for ResolverGeneric<C> {
154
152
impl < C : Cache + Default > ResolverGeneric < C > {
155
153
#[ must_use]
156
154
pub fn new ( options : ResolveOptions ) -> Self {
157
- Self {
158
- options : options. sanitize ( ) ,
159
- cache : Arc :: new ( C :: default ( ) ) ,
160
- #[ cfg( feature = "yarn_pnp" ) ]
161
- pnp_cache : Arc :: new ( papaya:: HashMap :: default ( ) ) ,
162
- }
155
+ Self { options : options. sanitize ( ) , cache : Arc :: new ( C :: default ( ) ) }
163
156
}
164
157
}
165
158
166
159
impl < C : Cache > ResolverGeneric < C > {
167
160
pub fn new_with_cache ( cache : Arc < C > , options : ResolveOptions ) -> Self {
168
- Self {
169
- cache,
170
- options : options. sanitize ( ) ,
171
- #[ cfg( feature = "yarn_pnp" ) ]
172
- pnp_cache : Arc :: new ( papaya:: HashMap :: default ( ) ) ,
173
- }
161
+ Self { cache, options : options. sanitize ( ) }
174
162
}
175
163
176
164
/// Clone the resolver using the same underlying cache.
177
165
#[ must_use]
178
166
pub fn clone_with_options ( & self , options : ResolveOptions ) -> Self {
179
- Self {
180
- options : options. sanitize ( ) ,
181
- cache : Arc :: clone ( & self . cache ) ,
182
- #[ cfg( feature = "yarn_pnp" ) ]
183
- pnp_cache : Arc :: clone ( & self . pnp_cache ) ,
184
- }
167
+ Self { options : options. sanitize ( ) , cache : Arc :: clone ( & self . cache ) }
185
168
}
186
169
187
170
/// Returns the options.
@@ -883,92 +866,81 @@ impl<C: Cache> ResolverGeneric<C> {
883
866
specifier : & str ,
884
867
ctx : & mut Ctx ,
885
868
) -> Result < Option < C :: Cp > , ResolveError > {
886
- let pnp_cache = self . pnp_cache . pin ( ) ;
887
- let pnp_manifest = pnp_cache. get_or_insert_with ( cached_path. clone ( ) , || {
888
- if let Some ( path) = pnp:: find_pnp_manifest ( cached_path. path ( ) ) . unwrap ( ) {
889
- return Some ( path) ;
890
- }
891
- self . options . roots . iter ( ) . find_map ( |root| pnp:: find_pnp_manifest ( root) . unwrap ( ) )
892
- } ) ;
869
+ let pnp_manifest = self . cache . get_yarn_pnp_manifest ( self . options . cwd . as_deref ( ) ) ?;
893
870
894
- if let Some ( pnp_manifest) = pnp_manifest. as_ref ( ) {
895
- // "pnpapi" in a P'n'P builtin module
896
- if specifier == "pnpapi" {
897
- return Ok ( Some ( self . cache . value ( pnp_manifest. manifest_path . as_path ( ) ) ) ) ;
898
- }
871
+ // "pnpapi" in a P'n'P builtin module
872
+ if specifier == "pnpapi" {
873
+ return Ok ( Some ( self . cache . value ( pnp_manifest. manifest_path . as_path ( ) ) ) ) ;
874
+ }
899
875
900
- // `resolve_to_unqualified` requires a trailing slash
901
- let mut path = cached_path. to_path_buf ( ) ;
902
- path. push ( "" ) ;
876
+ // `resolve_to_unqualified` requires a trailing slash
877
+ let mut path = cached_path. to_path_buf ( ) ;
878
+ path. push ( "" ) ;
903
879
904
- let resolution =
905
- pnp:: resolve_to_unqualified_via_manifest ( pnp_manifest, specifier, path) ;
880
+ let resolution = pnp:: resolve_to_unqualified_via_manifest ( pnp_manifest, specifier, path) ;
906
881
907
- match resolution {
908
- Ok ( pnp:: Resolution :: Resolved ( path, subpath) ) => {
909
- let cached_path = self . cache . value ( & path) ;
910
- let cached_path_string = cached_path. path ( ) . to_string_lossy ( ) ;
882
+ match resolution {
883
+ Ok ( pnp:: Resolution :: Resolved ( path, subpath) ) => {
884
+ let cached_path = self . cache . value ( & path) ;
885
+ let cached_path_string = cached_path. path ( ) . to_string_lossy ( ) ;
911
886
912
- let export_resolution = self . load_package_self ( & cached_path, specifier, ctx) ?;
913
- // can be found in pnp cached folder
914
- if export_resolution. is_some ( ) {
915
- return Ok ( export_resolution) ;
916
- }
887
+ let export_resolution = self . load_package_self ( & cached_path, specifier, ctx) ?;
888
+ // can be found in pnp cached folder
889
+ if export_resolution. is_some ( ) {
890
+ return Ok ( export_resolution) ;
891
+ }
917
892
918
- // symbol linked package doesn't have node_modules structure
919
- let pkg_name = cached_path_string. rsplit_once ( "node_modules/" ) . map_or (
920
- "" ,
921
- // remove trailing slash
922
- |( _, last) | last. strip_suffix ( '/' ) . unwrap_or ( last) ,
923
- ) ;
893
+ // symbol linked package doesn't have node_modules structure
894
+ let pkg_name = cached_path_string. rsplit_once ( "node_modules/" ) . map_or (
895
+ "" ,
896
+ // remove trailing slash
897
+ |( _, last) | last. strip_suffix ( '/' ) . unwrap_or ( last) ,
898
+ ) ;
924
899
925
- let inner_request = if pkg_name. is_empty ( ) {
926
- subpath. map_or_else (
927
- || "." . to_string ( ) ,
928
- |mut p| {
929
- p. insert_str ( 0 , "./" ) ;
930
- p
931
- } ,
932
- )
900
+ let inner_request = if pkg_name. is_empty ( ) {
901
+ subpath. map_or_else (
902
+ || "." . to_string ( ) ,
903
+ |mut p| {
904
+ p. insert_str ( 0 , "./" ) ;
905
+ p
906
+ } ,
907
+ )
908
+ } else {
909
+ let ( first, rest) = specifier. split_once ( '/' ) . unwrap_or ( ( specifier, "" ) ) ;
910
+ // the original `pkg_name` in cached path could be different with specifier
911
+ // due to alias like `"custom-minimist": "npm:minimist@^1.2.8"`
912
+ // in this case, `specifier` is `pkg_name`'s source of truth
913
+ let pkg_name = if first. starts_with ( '@' ) {
914
+ & format ! ( "{first}/{}" , rest. split_once( '/' ) . unwrap_or( ( rest, "" ) ) . 0 )
933
915
} else {
934
- let ( first, rest) = specifier. split_once ( '/' ) . unwrap_or ( ( specifier, "" ) ) ;
935
- // the original `pkg_name` in cached path could be different with specifier
936
- // due to alias like `"custom-minimist": "npm:minimist@^1.2.8"`
937
- // in this case, `specifier` is `pkg_name`'s source of truth
938
- let pkg_name = if first. starts_with ( '@' ) {
939
- & format ! ( "{first}/{}" , rest. split_once( '/' ) . unwrap_or( ( rest, "" ) ) . 0 )
940
- } else {
941
- first
942
- } ;
943
- let inner_specifier = specifier. strip_prefix ( pkg_name) . unwrap ( ) ;
944
- String :: from ( "./" )
945
- + inner_specifier. strip_prefix ( "/" ) . unwrap_or ( inner_specifier)
916
+ first
946
917
} ;
918
+ let inner_specifier = specifier. strip_prefix ( pkg_name) . unwrap ( ) ;
919
+ String :: from ( "./" )
920
+ + inner_specifier. strip_prefix ( "/" ) . unwrap_or ( inner_specifier)
921
+ } ;
947
922
948
- // it could be a directory with `package.json` that redirects to another file,
949
- // take `@atlaskit/pragmatic-drag-and-drop` for example, as described at import-js/eslint-import-resolver-typescript#409
950
- if let Ok ( Some ( result) ) = self . load_as_directory (
951
- & self . cache . value ( & path. join ( inner_request. clone ( ) ) . normalize ( ) ) ,
952
- ctx,
953
- ) {
954
- return Ok ( Some ( result) ) ;
955
- }
923
+ // it could be a directory with `package.json` that redirects to another file,
924
+ // take `@atlaskit/pragmatic-drag-and-drop` for example, as described at import-js/eslint-import-resolver-typescript#409
925
+ if let Ok ( Some ( result) ) = self . load_as_directory (
926
+ & self . cache . value ( & path. join ( inner_request. clone ( ) ) . normalize ( ) ) ,
927
+ ctx,
928
+ ) {
929
+ return Ok ( Some ( result) ) ;
930
+ }
956
931
957
- let inner_resolver = self . clone_with_options ( self . options ( ) . clone ( ) ) ;
932
+ let inner_resolver = self . clone_with_options ( self . options ( ) . clone ( ) ) ;
958
933
959
- // try as file or directory `path` in the pnp folder
960
- let Ok ( inner_resolution) = inner_resolver. resolve ( & path, & inner_request) else {
961
- return Err ( ResolveError :: NotFound ( specifier. to_string ( ) ) ) ;
962
- } ;
963
-
964
- Ok ( Some ( self . cache . value ( inner_resolution. path ( ) ) ) )
965
- }
934
+ // try as file or directory `path` in the pnp folder
935
+ let Ok ( inner_resolution) = inner_resolver. resolve ( & path, & inner_request) else {
936
+ return Err ( ResolveError :: NotFound ( specifier. to_string ( ) ) ) ;
937
+ } ;
966
938
967
- Ok ( pnp:: Resolution :: Skipped ) => Ok ( None ) ,
968
- Err ( _) => Err ( ResolveError :: NotFound ( specifier. to_string ( ) ) ) ,
939
+ Ok ( Some ( self . cache . value ( inner_resolution. path ( ) ) ) )
969
940
}
970
- } else {
971
- Ok ( None )
941
+
942
+ Ok ( pnp:: Resolution :: Skipped ) => Ok ( None ) ,
943
+ Err ( _) => Err ( ResolveError :: NotFound ( specifier. to_string ( ) ) ) ,
972
944
}
973
945
}
974
946
0 commit comments