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

Compartment Mapper should gracefully include peerDependencies only if present #2636

Open
kriskowal opened this issue Nov 18, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@kriskowal
Copy link
Member

Describe the bug

The Compartment Mapper reaches for peerDependencies during mapNodeModules, and if the package manager did not arrange for them, the routine fails with an exception for a missing transitive package. We should instead include each peer dependency in the packages map only if it’s physically present.

Steps to reproduce

Contrive a package graph that contains peerDependencies that are alternately present or absent and observe that the compartment mapper can link the peerDependencies only if they are present, regardless of whether they’re imported by the entry module.

Expected behavior

mapNodeModules should tolerate the absence of a peer dependency, allowing a module graph to link as long as it doesn’t attempt to import the peer dependency.

Platform environment

All at time of writing (2024-11-18)

@kriskowal kriskowal added the bug Something isn't working label Nov 18, 2024
@kriskowal kriskowal self-assigned this Nov 18, 2024
@kriskowal
Copy link
Member Author

Reviewing our code for this case, it seems that peerDependencies are not in fact optional, unless specified as optional in optionalDependencies or peerDependenciesMeta with optional: true. So, the implementation is consistent and provides a useful diagnostic for invalid node_modules trees. We could instead ignore peerDependenciesMeta and treat all peerDependencies or even all dependencies as optional if there is no corresponding physical package, which would defer linkage errors to load. Those errors might be less informative.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant