@@ -177,15 +177,17 @@ fn update_dependencies(
177177) -> Result < bool > {
178178 let mut changed = false ;
179179 for ( key, value) in dependencies. iter_mut ( ) {
180- let category = PackageCategory :: from_package_name ( key. get ( ) ) ;
180+ let crate_name = extract_real_crate_name ( & key, value) ;
181+
182+ let category = PackageCategory :: from_package_name ( & crate_name) ;
181183 if !matches ! ( category, PackageCategory :: Unknown ) {
182184 let old_value = match value {
183185 Item :: Table ( table) => table. clone ( ) ,
184186 Item :: Value ( Value :: InlineTable ( inline) ) => inline. clone ( ) . into_table ( ) ,
185187 _ => Table :: new ( ) ,
186188 } ;
187189 * value = Item :: Value ( Value :: InlineTable ( updated_dependency_value (
188- key . get ( ) ,
190+ & crate_name ,
189191 old_value,
190192 dependency_context,
191193 crate_path,
@@ -196,6 +198,21 @@ fn update_dependencies(
196198 Ok ( changed)
197199}
198200
201+ /// Extracts the real name of the underlying crate when the dependency has an alias
202+ fn extract_real_crate_name ( key : & toml_edit:: KeyMut , value : & Item ) -> String {
203+ match value {
204+ Item :: Value ( Value :: InlineTable ( inline_table) ) => {
205+ if let Some ( Value :: String ( real_package) ) = inline_table. get ( "package" ) {
206+ real_package. value ( )
207+ } else {
208+ key. get ( )
209+ }
210+ }
211+ _ => key. get ( ) ,
212+ }
213+ . to_string ( )
214+ }
215+
199216fn crate_path_name ( name : & str ) -> & str {
200217 if matches ! (
201218 PackageCategory :: from_package_name( name) ,
@@ -540,4 +557,46 @@ features = ["foo", "baz"]
540557"#
541558 ) ;
542559 }
560+
561+ #[ test]
562+ fn update_aliased_dependency_with_real_crate_name ( ) {
563+ let temp_dir = tempfile:: tempdir ( ) . unwrap ( ) ;
564+ let crate_path = temp_dir. path ( ) . join ( "test" ) ;
565+ fs:: create_dir_all ( & crate_path) . unwrap ( ) ;
566+
567+ let manifest_path = crate_path. join ( "Cargo.toml" ) ;
568+ std:: fs:: write (
569+ & manifest_path,
570+ br#"
571+ [package]
572+ name = "test"
573+ version = "0.1.0"
574+
575+ [dependencies]
576+ config = { package = "aws-config", path = "not/a/real/path" }
577+ "# ,
578+ )
579+ . unwrap ( ) ;
580+
581+ let context = DependencyContext {
582+ sdk_path : None ,
583+ versions_manifest : Some ( versions_toml_for ( & [
584+ ( "aws-config" , "0.5.0" ) ,
585+ ( "config" , "1.0.0" ) ,
586+ ] ) ) ,
587+ } ;
588+
589+ update_manifest ( & manifest_path, & context) . expect ( "success" ) ;
590+
591+ let actual = std:: fs:: read_to_string ( & manifest_path) . unwrap ( ) ;
592+ let expected = r#"
593+ [package]
594+ name = "test"
595+ version = "0.1.0"
596+
597+ [dependencies]
598+ config = { version = "0.5.0", package = "aws-config" }
599+ "# ;
600+ assert_eq ! ( expected, actual) ;
601+ }
543602}
0 commit comments