Skip to content
This repository has been archived by the owner on Jul 17, 2024. It is now read-only.

Commit

Permalink
Fix yarn version.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Jun 17, 2024
1 parent d1b8b50 commit 37ee690
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
22 changes: 18 additions & 4 deletions crates/node-depman/src/package_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,25 @@ impl PackageManager {
}

pub fn get_package_name(&self, version: impl AsRef<UnresolvedVersionSpec>) -> String {
if self.is_yarn_berry(version.as_ref()) {
"@yarnpkg/cli-dist".into()
} else {
self.to_string()
let version = version.as_ref();

if matches!(self, PackageManager::Yarn) {
if let UnresolvedVersionSpec::Version(inner) = &version {
// Version 2.4.3 was published to the wrong package. It should
// have been published to `@yarnpkg/cli-dist` but was published
// to `yarn`. So... we need to manually fix it.
// https://www.npmjs.com/package/yarn?activeTab=versions
if inner.major == 2 && inner.minor == 4 && inner.patch == 3 {
return "yarn".into();
}
}

if self.is_yarn_berry(version) {
return "@yarnpkg/cli-dist".into();
}
}

self.to_string()
}

pub fn is_yarn_classic(&self, version: impl AsRef<UnresolvedVersionSpec>) -> bool {
Expand Down
4 changes: 2 additions & 2 deletions crates/node-depman/src/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ pub fn download_prebuilt(

let package_name = manager.get_package_name(version.to_unresolved_spec());

let package_without_scope = if package_name.contains('/') {
package_name.split('/').nth(1).unwrap()
let package_without_scope = if let Some(index) = package_name.find('/') {
&package_name[index + 1..]
} else {
&package_name
};
Expand Down
7 changes: 7 additions & 0 deletions crates/node-depman/tests/download_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,13 @@ mod yarn {
}
}

mod yarn2 {
use super::*;

// Special case
generate_download_install_tests!("yarn-test", "2.4.3");
}

mod yarn_berry {
use super::*;

Expand Down

0 comments on commit 37ee690

Please sign in to comment.