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/snapshot.rs | |
parent | 69c0b05f7ab72f957ce7685998d3f424fb7e812c (diff) |
fix(npm): filter out duplicate packages names in resolution (#17857)
Diffstat (limited to 'cli/npm/resolution/snapshot.rs')
-rw-r--r-- | cli/npm/resolution/snapshot.rs | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/cli/npm/resolution/snapshot.rs b/cli/npm/resolution/snapshot.rs index bdc204ce8..3fc82cbb8 100644 --- a/cli/npm/resolution/snapshot.rs +++ b/cli/npm/resolution/snapshot.rs @@ -1,5 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +use std::collections::BTreeMap; use std::collections::HashMap; use std::collections::HashSet; use std::sync::Arc; @@ -42,7 +43,7 @@ impl NpmPackagesPartitioned { } } -#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Clone, Default, Serialize, Deserialize, PartialEq, Eq)] pub struct NpmResolutionSnapshot { /// The unique package requirements map to a single npm package name and version. #[serde(with = "map_to_vec")] @@ -55,6 +56,30 @@ pub struct NpmResolutionSnapshot { pub(super) packages: HashMap<NpmPackageId, NpmResolutionPackage>, } +impl std::fmt::Debug for NpmResolutionSnapshot { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + // do a custom debug implementation that creates deterministic output for the tests + f.debug_struct("NpmResolutionSnapshot") + .field( + "package_reqs", + &self.package_reqs.iter().collect::<BTreeMap<_, _>>(), + ) + .field( + "root_packages", + &self.root_packages.iter().collect::<BTreeMap<_, _>>(), + ) + .field( + "packages_by_name", + &self.packages_by_name.iter().collect::<BTreeMap<_, _>>(), + ) + .field( + "packages", + &self.packages.iter().collect::<BTreeMap<_, _>>(), + ) + .finish() + } +} + // This is done so the maps with non-string keys get serialized and deserialized as vectors. // Adapted from: https://github.com/serde-rs/serde/issues/936#issuecomment-302281792 mod map_to_vec { |