Skip to content

Commit 6a802f4

Browse files
committed
fix: Fixed consolidation with removed subjectOf logic
1 parent 0a74c16 commit 6a802f4

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

src/consolidate.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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() {

src/transform.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ pub fn create_subcrate_folder(
4343
if let Some(Value::Object(parent)) = parent_folder {
4444
for (key, value) in parent {
4545
if key != "@id" && key != "@type" {
46+
// Skip properties we want to strip
47+
if should_strip_property(key, value) {
48+
continue;
49+
}
4650
result.insert(key.clone(), value.clone());
4751
}
4852
}

0 commit comments

Comments
 (0)