From 590612932ac3772003b2757d7734dcc1aec2f5e3 Mon Sep 17 00:00:00 2001 From: StackOverflowExcept1on <109800286+StackOverflowExcept1on@users.noreply.github.com> Date: Thu, 15 Aug 2024 01:04:03 +0300 Subject: [PATCH 1/2] fix: handle renamed dependencies correctly --- .gitignore | 1 + src/publish.rs | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/src/publish.rs b/src/publish.rs index b88a46c..0702faf 100644 --- a/src/publish.rs +++ b/src/publish.rs @@ -83,8 +83,12 @@ struct Dep { impl From for crate::index::Dep { fn from(source: Dep) -> Self { + let (name, package) = match &source.explicit_name_in_toml { + Some(explicit) => (explicit.to_string(), Some(source.name.to_string())), + None => (source.name.to_string(), None), + }; Self { - name: source.name, + name, req: source.version_req, features: source.features, optional: source.optional, @@ -92,7 +96,7 @@ impl From for crate::index::Dep { target: source.target, kind: source.kind.to_string(), registry: source.registry, - package: source.explicit_name_in_toml, + package, } } } From 6569561d885ba112f1803c9f8028ebb4fd726c56 Mon Sep 17 00:00:00 2001 From: StackOverflowExcept1on <109800286+StackOverflowExcept1on@users.noreply.github.com> Date: Thu, 15 Aug 2024 02:32:46 +0300 Subject: [PATCH 2/2] add 2 test cases --- src/publish.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/publish.rs b/src/publish.rs index 0702faf..7345bd9 100644 --- a/src/publish.rs +++ b/src/publish.rs @@ -357,4 +357,44 @@ mod tests { assert_eq!(&crate_path("abcd"), Path::new("ab/cd")); assert_eq!(&crate_path("ydasdayusiy"), Path::new("yd/as")); } + + #[test] + fn convert_simple_dependency() { + // rand = { version = "0.8.5" } + let dep = Dep { + name: "rand".into(), + version_req: "0.8.5".into(), + features: vec![], + optional: false, + default_features: true, + target: None, + kind: Kind::Normal, + registry: None, + explicit_name_in_toml: None, + }; + + let index_dep = crate::index::Dep::from(dep); + assert_eq!(index_dep.name.as_str(), "rand"); // name of dependency + assert_eq!(index_dep.package, None); // null if dependency is not renamed + } + + #[test] + fn convert_renamed_dependency() { + // renamed-rand = { version = "0.8.5", package = "rand" } + let dep = Dep { + name: "rand".into(), + version_req: "0.8.5".into(), + features: vec![], + optional: false, + default_features: true, + target: None, + kind: Kind::Normal, + registry: None, + explicit_name_in_toml: Some("renamed-rand".into()), + }; + + let index_dep = crate::index::Dep::from(dep); + assert_eq!(index_dep.name.as_str(), "renamed-rand"); // new name dependency was renamed to + assert_eq!(index_dep.package, Some("rand".into())); // name of dependency package + } }