From 60fb68fcf302b074f71e132dc72cf277e13f784a Mon Sep 17 00:00:00 2001 From: daimond113 <72147841+daimond113@users.noreply.github.com> Date: Tue, 17 Dec 2024 14:58:21 +0100 Subject: [PATCH] fix: change dependency types for removed peers --- CHANGELOG.md | 3 +++ src/lockfile.rs | 3 +++ src/resolver.rs | 21 ++++++++++++++++----- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 237ff64..dc92aec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Fixed +- Change dependency types for removed peer dependencies by @daimond113 + ### Changed - Switch from `log` to `tracing` for logging by @daimond113 diff --git a/src/lockfile.rs b/src/lockfile.rs index 87d0d20..ca1af8c 100644 --- a/src/lockfile.rs +++ b/src/lockfile.rs @@ -32,6 +32,9 @@ pub struct DependencyGraphNode { pub dependencies: BTreeMap, /// The resolved (transformed, for example Peer -> Standard) type of the dependency pub resolved_ty: DependencyType, + /// Whether the resolved type should be Peer if this isn't depended on + #[serde(default, skip_serializing_if = "std::ops::Not::not")] + pub is_peer: bool, /// The package reference pub pkg_ref: PackageRefs, } diff --git a/src/resolver.rs b/src/resolver.rs index 5d29315..3f352eb 100644 --- a/src/resolver.rs +++ b/src/resolver.rs @@ -179,7 +179,7 @@ impl Project { let depth = path.len() - 1; tracing::debug!( - "{}resolving {specifier} from {}", + "{}resolving {specifier} ({ty:?}) from {}", "\t".repeat(depth), path.join(">") ); @@ -304,12 +304,14 @@ impl Project { ); } - if already_resolved.resolved_ty == DependencyType::Peer - && resolved_ty == DependencyType::Standard - { + if already_resolved.resolved_ty == DependencyType::Peer { already_resolved.resolved_ty = resolved_ty; } + if ty == DependencyType::Peer && depth == 0 { + already_resolved.is_peer = true; + } + if already_resolved.direct.is_none() && depth == 0 { already_resolved.direct = Some((alias.clone(), specifier.clone(), ty)); } @@ -326,6 +328,11 @@ impl Project { pkg_ref: pkg_ref.clone(), dependencies: Default::default(), resolved_ty, + is_peer: if depth == 0 { + false + } else { + ty == DependencyType::Peer + }, }; insert_node( &mut graph, @@ -388,8 +395,12 @@ impl Project { } } - for (name, versions) in &graph { + for (name, versions) in &mut graph { for (version_id, node) in versions { + if node.is_peer && node.direct.is_none() { + node.resolved_ty = DependencyType::Peer; + } + if node.resolved_ty == DependencyType::Peer { tracing::warn!("peer dependency {name}@{version_id} was not resolved"); }