Skip to content

Commit

Permalink
fix: root package has peer dependency on itself (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
littledivy authored Oct 3, 2024
1 parent e0c7024 commit a48a867
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/resolution/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1356,6 +1356,12 @@ impl<'a, TNpmRegistryApi: NpmRegistryApi>
} else {
(None, path)
};

if path.is_empty() {
// the peer dep is the same as the parent, so we don't need to do anything
return;
}

self.add_peer_deps_to_path(path, &[(&peer_dep, peer_dep_nv.clone())]);

// now set the peer dependency
Expand Down Expand Up @@ -3904,6 +3910,24 @@ mod test {
}
}

#[tokio::test]
async fn peer_dep_on_self() {
let api = TestNpmRegistryApi::default();
api.ensure_package_version("package-a", "1.0.0");
api.add_peer_dependency(("package-a", "1.0.0"), ("package-a", "1"));

let snapshot =
run_resolver_and_get_snapshot(api, vec!["package-a@1.0.0"]).await;
let packages = package_names_with_info(
&snapshot,
&NpmSystemInfo {
os: "darwin".to_string(),
cpu: "x86_64".to_string(),
},
);
assert_eq!(packages, vec!["package-a@1.0.0".to_string()]);
}

#[tokio::test]
async fn non_existent_optional_peer_dep() {
let api = TestNpmRegistryApi::default();
Expand Down

0 comments on commit a48a867

Please sign in to comment.