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

Commit

Permalink
Fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Oct 30, 2023
1 parent a126631 commit abf39a7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
30 changes: 16 additions & 14 deletions crates/node-depman/src/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,31 @@ impl PackageManager {
}
}

pub fn get_package_name(&self, version: impl AsRef<VersionSpec>) -> String {
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()
}
}

pub fn is_yarn_classic(&self, version: &VersionSpec) -> bool {
pub fn is_yarn_classic(&self, version: impl AsRef<UnresolvedVersionSpec>) -> bool {
matches!(self, PackageManager::Yarn)
&& match version {
VersionSpec::Canary => false,
VersionSpec::Alias(alias) => alias == "legacy" || alias == "classic",
VersionSpec::Version(ver) => ver.major == 1,
&& match version.as_ref() {
UnresolvedVersionSpec::Alias(alias) => alias == "legacy" || alias == "classic",
UnresolvedVersionSpec::Version(ver) => ver.major == 1,
UnresolvedVersionSpec::Req(req) => req.comparators.iter().any(|c| c.major == 1),
_ => false,
}
}

pub fn is_yarn_berry(&self, version: &VersionSpec) -> bool {
pub fn is_yarn_berry(&self, version: impl AsRef<UnresolvedVersionSpec>) -> bool {
matches!(self, PackageManager::Yarn)
&& match version {
VersionSpec::Canary => false,
VersionSpec::Alias(alias) => alias == "berry" || alias == "latest",
VersionSpec::Version(ver) => ver.major > 1,
&& match version.as_ref() {
UnresolvedVersionSpec::Alias(alias) => alias == "berry" || alias == "latest",
UnresolvedVersionSpec::Version(ver) => ver.major > 1,
UnresolvedVersionSpec::Req(req) => req.comparators.iter().any(|c| c.major > 1),
_ => false,
}
}
}
Expand Down Expand Up @@ -102,10 +104,10 @@ pub fn download_prebuilt(
.into());
}

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

// Derive values based on package manager
let archive_prefix = if manager.is_yarn_classic(version) {
let archive_prefix = if manager.is_yarn_classic(version.to_unresolved_spec()) {
format!("yarn-v{version}")
} else {
"package".into()
Expand Down Expand Up @@ -205,7 +207,7 @@ fn parse_registry_response(res: HttpResponse, is_yarn: bool) -> Result<RegistryR
pub fn load_versions(Json(input): Json<LoadVersionsInput>) -> FnResult<Json<LoadVersionsOutput>> {
let mut output = LoadVersionsOutput::default();
let manager = PackageManager::detect();
let package_name = manager.get_package_name(input.initial.to_resolved_spec());
let package_name = manager.get_package_name(&input.initial);

let mut map_output = |res: HttpResponse, is_yarn: bool| -> Result<(), Error> {
let res = parse_registry_response(res, is_yarn)?;
Expand Down
2 changes: 1 addition & 1 deletion crates/node-depman/tests/versions_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ mod yarn {
"1" => "1.22.19",
"2" => "2.4.3",
"3" => "3.6.4",
"berry" => "4.0.0",
"berry" => "4.0.1",
});

#[test]
Expand Down

0 comments on commit abf39a7

Please sign in to comment.