Skip to content

Commit e745e57

Browse files
committed
yarn2 is not supported
1 parent 5aebcda commit e745e57

File tree

4 files changed

+42
-20
lines changed

4 files changed

+42
-20
lines changed

crates/volta-core/src/error/kind.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,9 @@ pub enum ErrorKind {
499499
#[cfg(windows)]
500500
WriteUserPathError,
501501

502+
/// Thrown when a user attempts to install a version of Yarn2
503+
Yarn2NotSupported,
504+
502505
/// Thrown when there is an error fetching the latest version of Yarn
503506
YarnLatestFetchError {
504507
from_url: String,
@@ -1373,6 +1376,12 @@ to {}
13731376
"Could not write Path environment variable.
13741377
13751378
Please ensure you have permissions to edit your environment variables."
1379+
),
1380+
ErrorKind::Yarn2NotSupported => write!(
1381+
f,
1382+
"Yarn@2 is not recommended for use, and not supported by Volta.
1383+
1384+
Please use Yarn@3 instead."
13761385
),
13771386
ErrorKind::YarnLatestFetchError { from_url } => write!(
13781387
f,
@@ -1506,6 +1515,7 @@ impl ErrorKind {
15061515
ErrorKind::WritePlatformError { .. } => ExitCode::FileSystemError,
15071516
#[cfg(windows)]
15081517
ErrorKind::WriteUserPathError => ExitCode::EnvironmentError,
1518+
ErrorKind::Yarn2NotSupported => ExitCode::NoVersionMatch,
15091519
ErrorKind::YarnLatestFetchError { .. } => ExitCode::NetworkError,
15101520
ErrorKind::YarnVersionNotFound { .. } => ExitCode::NoVersionMatch,
15111521
}

crates/volta-core/src/tool/yarn/fetch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ fn determine_remote_url(version: &Version, hooks: Option<&ToolHooks<Yarn>>) -> F
127127
hook.resolve(version, &distro_file_name)
128128
}
129129
_ => {
130-
let matches_yarn_berry = VersionReq::parse(">2").unwrap();
130+
let matches_yarn_berry = VersionReq::parse(">=2").unwrap();
131131
if env::var_os("VOLTA_FEATURE_YARN_3").is_some() && matches_yarn_berry.matches(version)
132132
{
133133
Ok(public_registry_package(

crates/volta-core/src/tool/yarn/resolve.rs

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -119,26 +119,35 @@ fn resolve_semver_from_registry(matching: VersionReq) -> Fallible<Version> {
119119
if env::var_os("VOLTA_FEATURE_YARN_3").is_some() {
120120
// first try yarn2+, which uses "@yarnpkg/cli-dist" instead of "yarn"
121121
let (url, index) = fetch_yarn_index("@yarnpkg/cli-dist")?;
122-
let details_opt = index
122+
let matching_entries: Vec<PackageDetails> = index
123123
.entries
124124
.into_iter()
125-
.find(|PackageDetails { version, .. }| matching.matches(version));
126-
127-
match details_opt {
128-
Some(details) => {
129-
debug!(
130-
"Found yarn@{} matching requirement '{}' from {}",
131-
details.version, matching, url
132-
);
133-
return Ok(details.version);
134-
}
135-
None => {
136-
debug!(
137-
"Did not find yarn matching requirement '{}' from {}",
138-
matching, url
139-
);
125+
.filter(|PackageDetails { version, .. }| matching.matches(version))
126+
.collect();
127+
128+
if matching_entries.len() > 0 {
129+
let matches_yarn_3 = VersionReq::parse(">=3").unwrap();
130+
let details_opt = matching_entries
131+
.iter()
132+
.find(|PackageDetails { version, .. }| matches_yarn_3.matches(version));
133+
134+
match details_opt {
135+
Some(details) => {
136+
debug!(
137+
"Found yarn@{} matching requirement '{}' from {}",
138+
details.version, matching, url
139+
);
140+
return Ok(details.version.clone());
141+
}
142+
None => {
143+
return Err(ErrorKind::Yarn2NotSupported.into());
144+
}
140145
}
141146
}
147+
debug!(
148+
"Did not find yarn matching requirement '{}' from {}",
149+
matching, url
150+
);
142151
}
143152

144153
let (url, index) = fetch_yarn_index("yarn")?;

tests/acceptance/volta_pin.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,6 @@ fn pin_yarn_1() {
411411

412412
#[test]
413413
fn pin_yarn_2_is_error() {
414-
// TODO
415414
let s = sandbox()
416415
.package_json(&package_json_with_pinned_node("1.2.3"))
417416
.yarn_1_available_versions(YARN_1_VERSION_INFO)
@@ -423,12 +422,16 @@ fn pin_yarn_2_is_error() {
423422

424423
assert_that!(
425424
s.volta("pin yarn@2"),
426-
execs().with_status(ExitCode::Success as i32)
425+
execs()
426+
.with_status(ExitCode::NoVersionMatch as i32)
427+
.with_stderr_contains(
428+
"[..]Yarn@2 is not recommended for use, and not supported by Volta[..]"
429+
)
427430
);
428431

429432
assert_eq!(
430433
s.read_package_json(),
431-
package_json_with_pinned_node_yarn("1.2.3", "2.4.159"),
434+
package_json_with_pinned_node("1.2.3"),
432435
)
433436
}
434437

0 commit comments

Comments
 (0)