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

fix: Fix Yarn archive prefix change. #20

Merged
merged 3 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 0.5.1

#### 🐞 Fixes

- Fixed Yarn >= v1.22.20 not unpacking correctly.

## 0.5.0

#### 💥 Breaking
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/node-depman/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "node_depman_plugin"
version = "0.5.0"
version = "0.5.1"
edition = "2021"
license = "MIT"
publish = false
Expand Down
23 changes: 15 additions & 8 deletions crates/node-depman/src/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,20 @@ pub fn resolve_version(
Ok(Json(output))
}

fn get_archive_prefix(manager: &PackageManager, spec: &VersionSpec) -> String {
if manager.is_yarn_classic(spec.to_unresolved_spec()) {
if let VersionSpec::Version(version) = spec {
// Prefix changed to "package" in v1.22.20
// https://github.com/yarnpkg/yarn/releases/tag/v1.22.20
if version.minor <= 22 && version.patch <= 19 {
return format!("yarn-v{version}");
}
}
}

"package".into()
}

#[plugin_fn]
pub fn download_prebuilt(
Json(input): Json<DownloadPrebuiltInput>,
Expand All @@ -225,21 +239,14 @@ pub fn download_prebuilt(

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.to_unresolved_spec()) {
format!("yarn-v{version}")
} else {
"package".into()
};

let package_without_scope = if package_name.contains('/') {
package_name.split('/').nth(1).unwrap()
} else {
&package_name
};

Ok(Json(DownloadPrebuiltOutput {
archive_prefix: Some(archive_prefix),
archive_prefix: Some(get_archive_prefix(&manager, &version)),
download_url: format!(
"https://registry.npmjs.org/{package_name}/-/{package_without_scope}-{version}.tgz",
),
Expand Down
6 changes: 3 additions & 3 deletions crates/node-depman/tests/versions_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ mod yarn {
use super::*;

generate_resolve_versions_tests!("yarn-test", {
"1" => "1.22.19",
"1" => "1.22.21",
"2" => "2.4.3",
"3" => "3.6.4",
"berry" => "4.0.1",
"3" => "3.7.0",
"berry" => "4.0.2",
});

#[test]
Expand Down
2 changes: 1 addition & 1 deletion crates/node/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "node_plugin"
version = "0.5.0"
version = "0.5.1"
edition = "2021"
license = "MIT"
publish = false
Expand Down