33use std:: env;
44
55use super :: super :: registry:: {
6- public_registry_index, PackageDetails , PackageIndex , RawPackageMetadata ,
7- NPM_ABBREVIATED_ACCEPT_HEADER ,
6+ fetch_public_index, public_registry_index, PackageDetails , PackageIndex ,
87} ;
98use super :: super :: registry_fetch_error;
109use super :: metadata:: { RawYarnIndex , YarnIndex } ;
@@ -14,7 +13,6 @@ use crate::session::Session;
1413use crate :: style:: progress_spinner;
1514use crate :: tool:: Yarn ;
1615use crate :: version:: { parse_version, VersionSpec , VersionTag } ;
17- use attohttpc:: header:: ACCEPT ;
1816use attohttpc:: Response ;
1917use log:: debug;
2018use semver:: { Version , VersionReq } ;
@@ -73,27 +71,17 @@ fn resolve_semver(matching: VersionReq, hooks: Option<&ToolHooks<Yarn>>) -> Fall
7371
7472fn fetch_yarn_index ( package : & str ) -> Fallible < ( String , PackageIndex ) > {
7573 let url = public_registry_index ( package) ;
76- let spinner = progress_spinner ( format ! ( "Fetching public registry: {}" , url) ) ;
77- let metadata: RawPackageMetadata = attohttpc:: get ( & url)
78- . header ( ACCEPT , NPM_ABBREVIATED_ACCEPT_HEADER )
79- . send ( )
80- . and_then ( Response :: error_for_status)
81- . and_then ( Response :: json)
82- . with_context ( registry_fetch_error ( "Yarn" , & url) ) ?;
83-
84- spinner. finish_and_clear ( ) ;
85- Ok ( ( url, metadata. into ( ) ) )
74+ fetch_public_index ( url, "Yarn" )
8675}
8776
8877fn resolve_custom_tag ( tag : String ) -> Fallible < Version > {
8978 if env:: var_os ( "VOLTA_FEATURE_YARN_3" ) . is_some ( ) {
9079 // first try yarn2+, which uses "@yarnpkg/cli-dist" instead of "yarn"
9180 let ( url, mut index) = fetch_yarn_index ( "@yarnpkg/cli-dist" ) ?;
9281
93- let matches_yarn_2 = VersionReq :: parse ( "2.*" ) . unwrap ( ) ;
9482 if let Some ( version) = index. tags . remove ( & tag) {
9583 debug ! ( "Found yarn@{} matching tag '{}' from {}" , version, tag, url) ;
96- if matches_yarn_2 . matches ( & version) {
84+ if version. major == 2 {
9785 return Err ( ErrorKind :: Yarn2NotSupported . into ( ) ) ;
9886 }
9987 return Ok ( version) ;
@@ -137,11 +125,10 @@ fn resolve_semver_from_registry(matching: VersionReq) -> Fallible<Version> {
137125 . filter ( |PackageDetails { version, .. } | matching. matches ( version) )
138126 . collect ( ) ;
139127
140- if matching_entries. len ( ) > 0 {
141- let matches_yarn_3 = VersionReq :: parse ( ">=3" ) . unwrap ( ) ;
128+ if !matching_entries. is_empty ( ) {
142129 let details_opt = matching_entries
143130 . iter ( )
144- . find ( |PackageDetails { version, .. } | matches_yarn_3 . matches ( version) ) ;
131+ . find ( |PackageDetails { version, .. } | version. major >= 3 ) ;
145132
146133 match details_opt {
147134 Some ( details) => {
0 commit comments