mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 07:14:47 -05:00
fix(npm): ancestor that resolves peer dependency should not include self in id (#16693)
Closes #16683
This commit is contained in:
parent
221d1916c1
commit
1e512d10b3
1 changed files with 13 additions and 25 deletions
|
@ -836,13 +836,15 @@ impl<'a, TNpmRegistryApi: NpmRegistryApi>
|
||||||
path: &Arc<GraphSpecifierPath>,
|
path: &Arc<GraphSpecifierPath>,
|
||||||
visited_ancestor_versions: &Arc<VisitedVersionsPath>,
|
visited_ancestor_versions: &Arc<VisitedVersionsPath>,
|
||||||
) -> NpmPackageId {
|
) -> NpmPackageId {
|
||||||
let mut peer_dep_id = Cow::Borrowed(peer_dep_id);
|
let peer_dep_id = Cow::Borrowed(peer_dep_id);
|
||||||
let old_id = node_id;
|
let old_id = node_id;
|
||||||
let (new_id, mut old_node_children) =
|
let (new_id, mut old_node_children) =
|
||||||
if old_id.peer_dependencies.contains(&peer_dep_id) {
|
if old_id.peer_dependencies.contains(&peer_dep_id)
|
||||||
|
|| *old_id == *peer_dep_id
|
||||||
|
{
|
||||||
// the parent has already resolved to using this peer dependency
|
// the parent has already resolved to using this peer dependency
|
||||||
// via some other path, so we don't need to update its ids,
|
// via some other path or the parent is the peer dependency,
|
||||||
// but instead only make a link to it
|
// so we don't need to update its ids, but instead only make a link to it
|
||||||
(
|
(
|
||||||
old_id.clone(),
|
old_id.clone(),
|
||||||
self.graph.borrow_node(old_id).children.clone(),
|
self.graph.borrow_node(old_id).children.clone(),
|
||||||
|
@ -851,11 +853,6 @@ impl<'a, TNpmRegistryApi: NpmRegistryApi>
|
||||||
let mut new_id = old_id.clone();
|
let mut new_id = old_id.clone();
|
||||||
new_id.peer_dependencies.push(peer_dep_id.as_ref().clone());
|
new_id.peer_dependencies.push(peer_dep_id.as_ref().clone());
|
||||||
|
|
||||||
// this will happen for circular dependencies
|
|
||||||
if *old_id == *peer_dep_id {
|
|
||||||
peer_dep_id = Cow::Owned(new_id.clone());
|
|
||||||
}
|
|
||||||
|
|
||||||
// remove the previous parents from the old node
|
// remove the previous parents from the old node
|
||||||
let old_node_children = {
|
let old_node_children = {
|
||||||
for (specifier, parents) in &previous_parents {
|
for (specifier, parents) in &previous_parents {
|
||||||
|
@ -1949,28 +1946,22 @@ mod test {
|
||||||
packages,
|
packages,
|
||||||
vec![
|
vec![
|
||||||
NpmResolutionPackage {
|
NpmResolutionPackage {
|
||||||
id: NpmPackageId::from_serialized("package-a@1.0.0_package-a@1.0.0")
|
id: NpmPackageId::from_serialized("package-a@1.0.0").unwrap(),
|
||||||
.unwrap(),
|
|
||||||
copy_index: 0,
|
copy_index: 0,
|
||||||
dependencies: HashMap::from([(
|
dependencies: HashMap::from([(
|
||||||
"package-b".to_string(),
|
"package-b".to_string(),
|
||||||
NpmPackageId::from_serialized(
|
NpmPackageId::from_serialized("package-b@2.0.0_package-a@1.0.0")
|
||||||
"package-b@2.0.0_package-a@1.0.0__package-a@1.0.0"
|
.unwrap(),
|
||||||
)
|
|
||||||
.unwrap(),
|
|
||||||
)]),
|
)]),
|
||||||
dist: Default::default(),
|
dist: Default::default(),
|
||||||
},
|
},
|
||||||
NpmResolutionPackage {
|
NpmResolutionPackage {
|
||||||
id: NpmPackageId::from_serialized(
|
id: NpmPackageId::from_serialized("package-b@2.0.0_package-a@1.0.0")
|
||||||
"package-b@2.0.0_package-a@1.0.0__package-a@1.0.0"
|
.unwrap(),
|
||||||
)
|
|
||||||
.unwrap(),
|
|
||||||
copy_index: 0,
|
copy_index: 0,
|
||||||
dependencies: HashMap::from([(
|
dependencies: HashMap::from([(
|
||||||
"package-a".to_string(),
|
"package-a".to_string(),
|
||||||
NpmPackageId::from_serialized("package-a@1.0.0_package-a@1.0.0")
|
NpmPackageId::from_serialized("package-a@1.0.0").unwrap(),
|
||||||
.unwrap(),
|
|
||||||
)]),
|
)]),
|
||||||
dist: Default::default(),
|
dist: Default::default(),
|
||||||
},
|
},
|
||||||
|
@ -1978,10 +1969,7 @@ mod test {
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
package_reqs,
|
package_reqs,
|
||||||
vec![(
|
vec![("package-a@1.0".to_string(), "package-a@1.0.0".to_string())]
|
||||||
"package-a@1.0".to_string(),
|
|
||||||
"package-a@1.0.0_package-a@1.0.0".to_string()
|
|
||||||
)]
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue