@@ -219,6 +219,7 @@ pub fn consolidate(
219219 let mut all_local: Vec < CollectedEntity > = Vec :: new ( ) ;
220220 let mut all_shared: Vec < CollectedEntity > = Vec :: new ( ) ;
221221 let mut subcrate_folders: Vec < Value > = Vec :: new ( ) ;
222+ let mut processed_subcrate_ids: HashSet < String > = HashSet :: new ( ) ;
222223 let mut root_entity: Option < Value > = None ;
223224 let mut metadata_descriptor: Option < Value > = None ;
224225
@@ -233,6 +234,7 @@ pub fn consolidate(
233234 & mut all_local,
234235 & mut all_shared,
235236 & mut subcrate_folders,
237+ & mut processed_subcrate_ids,
236238 & mut root_entity,
237239 & mut metadata_descriptor,
238240 & mut stats,
@@ -269,6 +271,7 @@ pub fn consolidate(
269271 & mut all_local,
270272 & mut all_shared,
271273 & mut subcrate_folders,
274+ & mut processed_subcrate_ids,
272275 & mut None , // Don't override root
273276 & mut None , // Don't override descriptor
274277 & mut stats,
@@ -297,6 +300,9 @@ pub fn consolidate(
297300 }
298301 }
299302
303+ // Filter out processed subcrates from shared entities (they're replaced by subcrate folders)
304+ all_shared. retain ( |e| !processed_subcrate_ids. contains ( & e. original_id ) ) ;
305+
300306 // Merge shared entities (those with absolute IDs appearing in multiple crates)
301307 let shared_before = all_shared. len ( ) ;
302308 let merged_shared = merge_by_id ( all_shared) ;
@@ -363,6 +369,7 @@ fn collect_hierarchy(
363369 all_local : & mut Vec < CollectedEntity > ,
364370 all_shared : & mut Vec < CollectedEntity > ,
365371 subcrate_folders : & mut Vec < Value > ,
372+ processed_subcrate_ids : & mut HashSet < String > ,
366373 root_entity : & mut Option < Value > ,
367374 metadata_descriptor : & mut Option < Value > ,
368375 stats : & mut ConsolidateStats ,
@@ -395,6 +402,11 @@ fn collect_hierarchy(
395402 if let Some ( collected) = collection. metadata_descriptor {
396403 * metadata_descriptor = Some ( collected. entity ) ;
397404 }
405+ } else {
406+ // This is a subcrate - capture its root for subcrate folder creation
407+ if let Some ( collected) = collection. root_entity {
408+ * root_entity = Some ( collected. entity ) ;
409+ }
398410 }
399411
400412 // Process and rewrite local entities
@@ -456,11 +468,15 @@ fn collect_hierarchy(
456468 all_local,
457469 all_shared,
458470 subcrate_folders,
471+ processed_subcrate_ids,
459472 & mut subcrate_root,
460473 & mut subcrate_desc,
461474 stats,
462475 ) ?;
463476
477+ // Mark this subcrate as processed (so we can exclude it from shared entities)
478+ processed_subcrate_ids. insert ( subcrate_id. clone ( ) ) ;
479+
464480 // Create the subcrate folder entity
465481 if let Some ( sub_root) = subcrate_root {
466482 let folder_id = if namespace. is_empty ( ) {
0 commit comments