-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(npm): improve peer dependency resolution with circular dependencies #18069
Conversation
nv: Arc<NpmPackageNv>, | ||
/// Descendants in the path that circularly link to an ancestor in a child.These | ||
/// descendants should be kept up to date and always point to this node. | ||
linked_circular_descendants: Mutex<Vec<Arc<GraphPath>>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the new concept here. We keep track of descendants that have this ancestor as a child.
@@ -1329,40 +1465,30 @@ mod test { | |||
assert_eq!( | |||
packages, | |||
vec![ | |||
NpmResolutionPackage { | |||
pkg_id: NpmPackageId::from_serialized("package-a@1.0.0").unwrap(), | |||
TestNpmResolutionPackage { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Below this point is mostly updates to use a new less verbose struct for testing. At the bottom of this file and line 3124 there are some new tests. I have commented where those are.
@@ -3377,6 +3120,100 @@ mod test { | |||
); | |||
} | |||
|
|||
#[tokio::test] | |||
async fn resolve_peer_deps_in_ancestor_root() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New tests here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, these indeed look tricky
@@ -3614,10 +3411,254 @@ mod test { | |||
); | |||
} | |||
|
|||
#[tokio::test] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New tests here and below.
std::env::var("DENO_UNSTABLE_NPM_SYNC_DOWNLOAD").is_ok() | ||
// this gets called a lot when doing npm resolution and was taking | ||
// a significant amount of time, so cache it in a lazy | ||
*SHOULD_SYNC_DOWNLOAD |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before: 8.6% of execution -- After: 0%
|
||
if !found_peer { | ||
found_peer = !self.graph.borrow_node_mut(child_id).no_peers; | ||
// cache all the dependencies' registry infos in parallel if should |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment makes no sense :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how to reword this because it's saying what the next line does
// a -> b -> c -> d -> c where c has a peer dependency on b | ||
// -> e -> f -> d -> c where f has a peer dep on a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🫠
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, see comment about Arc
…es (#18069) This improves peer dependency resolution yet again. We did not handle scenarios like the following: ``` // a -> b -> c -> d -> c -> b (peer) ``` ...which would maybe work ok the first time its run in some cases, but then lead to a lockfile that would error on load. This now keeps track of circular dependencies and updates nodes accordingly. That said, there is still a lurking bug in this code somewhere that I've added a comment for (there is a mitigation on the tail end that seems to work well). The current state is much better than before and I can look into it later. I think it's something small that's incorrect.
This improves peer dependency resolution yet again. We did not handle scenarios like the following:
...which would maybe work ok the first time its run in some cases, but then lead to a lockfile that would error on load.
This now keeps track of circular dependencies and updates nodes accordingly. That said, there is still a lurking bug in this code somewhere that I've added a comment for (there is a mitigation on the tail end that seems to work well). The current state is much better than before and I can look into it later. I think it's something small that's incorrect.