diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2023-02-21 15:19:09 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-21 15:19:09 -0500 |
commit | 5becfd6381889287ff16a064128021f87c8dfcb6 (patch) | |
tree | e6931d7794eb195075dd214002e4c1bf69647b2d /cli/npm/resolution/graph.rs | |
parent | 69c0b05f7ab72f957ce7685998d3f424fb7e812c (diff) |
fix(npm): filter out duplicate packages names in resolution (#17857)
Diffstat (limited to 'cli/npm/resolution/graph.rs')
-rw-r--r-- | cli/npm/resolution/graph.rs | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/cli/npm/resolution/graph.rs b/cli/npm/resolution/graph.rs index 76ec2e62c..966e1f010 100644 --- a/cli/npm/resolution/graph.rs +++ b/cli/npm/resolution/graph.rs @@ -584,14 +584,14 @@ impl Graph { .nodes_by_package_name .into_iter() .map(|(name, ids)| { - ( - name, - ids - .into_iter() - .filter(|id| traversed_node_ids.contains(id)) - .map(|id| packages_to_resolved_id.get(&id).unwrap().clone()) - .collect(), - ) + let mut ids = ids + .into_iter() + .filter(|id| traversed_node_ids.contains(id)) + .map(|id| packages_to_resolved_id.get(&id).unwrap().clone()) + .collect::<Vec<_>>(); + ids.sort(); + ids.dedup(); + (name, ids) }) .collect(), packages, @@ -3586,25 +3586,25 @@ mod test { let snapshot = graph.into_snapshot(&api).await.unwrap(); { - // let new_snapshot = Graph::from_snapshot(snapshot.clone()) - // .unwrap() - // .into_snapshot(&api) - // .await - // .unwrap(); - // assert_eq!( - // snapshot, new_snapshot, - // "recreated snapshot should be the same" - // ); - // // create one again from the new snapshot - // let new_snapshot2 = Graph::from_snapshot(new_snapshot.clone()) - // .unwrap() - // .into_snapshot(&api) - // .await - // .unwrap(); - // assert_eq!( - // snapshot, new_snapshot2, - // "second recreated snapshot should be the same" - // ); + let new_snapshot = Graph::from_snapshot(snapshot.clone()) + .unwrap() + .into_snapshot(&api) + .await + .unwrap(); + assert_eq!( + snapshot, new_snapshot, + "recreated snapshot should be the same" + ); + // create one again from the new snapshot + let new_snapshot2 = Graph::from_snapshot(new_snapshot.clone()) + .unwrap() + .into_snapshot(&api) + .await + .unwrap(); + assert_eq!( + snapshot, new_snapshot2, + "second recreated snapshot should be the same" + ); } let mut packages = snapshot.all_packages(); |