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
[Feature] PnP resolveToUnqualified() should return an array #1927
Comments
There is a single resolution for a single module and bare identifier, so |
That's true of resolveRequest(), but PnP has chosen to have a resolveToUnqualified() function with a permitted varying extension. What you call "single resolution" is in reality a patterned file path with many possible values. I argue that resolveToUnqualified() under-captures the amount of runtime variability in path that Node.js algorithm requires. |
So, In the case of Node it's a bit problematic because Node doesn't have any concrete idea what a package is. If you import
We don't use it to represent the Node resolution, though 😉 That said, it can represent a "good enough" subset of the Node resolution, if you keep the requirement I mention (which is easy enough - I'm not aware of a single case where keeping the problematic behavior matters in practice). |
Yes, that is how it works now. No argument there. I argue that Node.js, TypeScript*, and my Bazel code gen situation wind up with "split packages," so PnP should support that. My package manager/build system has modules in I could of course merge split packages, but by the same reasoning I also could run a node_modules linker. This is something that I'd hope the location-flexible PnP API would support. * I should have added TypeScript to the list of tools whose module resolution cannot be described with PnP. The entire purpose of TypeScript's |
I guess I should ask one question first: why does it matter whether the PnP API can perfectly represent a loose resolution like the Node one? We don't use it for the Node resolution. Do you have a reproducible example? |
I thought PnP might be a good commonly supported abstraction for resolving JS, CSS, etc. modules for Bazel (which kinda runs the show with where files go). Sometimes the split package case comes up, similar to TypeScripts's If PnP keeps one unqualified path per module identifier (and it sounds like that is the conclusion), I will instead write require.resolve shims, Webpack resolver, etc. to accomplish my intention. |
Hi! 👋 It seems like this issue as been marked as probably resolved, or missing important information blocking its progression. As a result, it'll be closed in a few days unless a maintainer explicitly vouches for it. |
Closing since |
Describe the user story
Node.js
PnP is incapable of describing the Node.js resolution algorithm. Namely, the primary function resolveToUnqualified() cannot support a list of directories.
Resolving module
'exam/ple'
:Currently, to accommodate Node.js resolution, PnP allows the package manager to be agnostic about extension, delegating to the module resolver to use file system info to determine that. However, to match Node.js, it also needs to let the package manager be flexible about directory.
Admittedly, it's unconventional Node.js to have a file in both:
Bazel
Also, when working to create a PnP API for the build tool/dependency manager Bazel, I run into this same issue.
BUILD.bazel
foo.js
bazel-out/blah/blah/blah/gen/bar.js (generated)
The package manager Bazel doesn't know which directory the
'./bar'
module is in. It needs to tell the runtime to check in both.Describe the solution you'd like
I'd like resolveToUnqualified() (or new function resolveToUnqualifiedList()) to return a list.
Describe the drawbacks of your solution
Backwards compatibility.
Describe alternatives you've considered
Have the package manager be aware of the complete resolution, that is, use qualified paths.
Additional context
The text was updated successfully, but these errors were encountered: