Skip to content
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 #17835

Merged
merged 12 commits into from
Feb 21, 2023

Conversation

dsherret
Copy link
Member

@dsherret dsherret commented Feb 20, 2023

This PR fixes peer dependency resolution to only resolve peers based on the current graph traversal path. Previously, it would resolve a peers by looking at a graph node's ancestors, which is not correct because graph nodes are shared by different resolutions.

It also stores more information about peer dependency resolution in the lockfile.

&id.name,
&id.version,
&id.nv.name,
&id.nv.version,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some changes that could be done (like only providing &id.nv here), will be in the next deno_graph refactor PR.


use super::NpmPackageId;
use crate::npm::registry::NpmPackageInfo;
use crate::npm::registry::NpmPackageVersionInfo;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file doesn't make much sense now, but it will be reused elsewhere in the deno_graph refactor.

@@ -1629,40 +1753,55 @@ mod test {
packages,
vec![
NpmResolutionPackage {
id: NpmPackageNodeId::from_serialized("[email protected]").unwrap(),
pkg_id: NpmPackageId::from_serialized(
"[email protected][email protected]"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These package identifiers always include the descendant peer dep resolutions now. This means lockfiles will have more information in them, but that's necessary in order to differentiate resolutions.

self.graph.borrow_node(parent_id).parents.clone()
{
let path = path.with_specifier(specifier);
for grand_parent in grand_parents {
Copy link
Member Author

@dsherret dsherret Feb 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was previously so wrong it's embarrassing, but it seems like it's worked out ok. The issue here is that we can't look at all of a node's parents... we have to just look at the current graph path's ancestors (now fixed).

@dsherret dsherret marked this pull request as ready for review February 20, 2023 21:11
/// A pointer to a specific node in a graph path. The underlying node id
/// may change as peer dependencies are created.
#[derive(Clone, Debug)]
struct NodeIdRef(Arc<Mutex<NodeId>>);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, I tried to use an Rc<RefCell<NodeId>> here, but the lsp code keeps complaining about the future not being send even when I wrap the code that calls this in a tokio::task::spawn_local(async move { ... }).await.unwrap(). I don't understand why it doesn't work.

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really complex PR. I tested it locally on both debug and release builds and it feels much snappier to install npm dependencies than before.

@dsherret dsherret marked this pull request as draft February 21, 2023 03:41
@dsherret dsherret marked this pull request as ready for review February 21, 2023 15:42
Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dsherret
Copy link
Member Author

Code is much simpler now by nodes not storing parents.

@dsherret dsherret merged commit 3479bc7 into denoland:main Feb 21, 2023
@dsherret dsherret deleted the fix_peer_deps branch February 21, 2023 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants