-
Notifications
You must be signed in to change notification settings - Fork 626
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
Add support for resolving import subpaths #1302
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1302 +/- ##
==========================================
- Coverage 83.81% 83.70% -0.11%
==========================================
Files 207 209 +2
Lines 10887 10943 +56
Branches 2733 2752 +19
==========================================
+ Hits 9125 9160 +35
- Misses 1762 1783 +21 ☔ View full report in Codecov by Sentry. |
Thanks for picking this up! |
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.
Huge thanks for working on this @jameslawson and sorry for the lack of response from us.
There have been a lot of moving parts in the resolver recently and this would've been a breaking change we couldn't immediately pull in, but there's now room for it and a new, stable fileSystemLookup
to use.
If you're happy to rebase, this is looking really close.
packages/metro-resolver/src/errors/PackageImportNotResolvedError.js
Outdated
Show resolved
Hide resolved
packages/metro-resolver/src/errors/PackageImportNotResolvedError.js
Outdated
Show resolved
Hide resolved
* 1. `isSubpathDefinedInExports`: checking if an specifier is in an import map | ||
* is the same as checking if an specifier is in an export map | ||
* 2. `matchSubpathFromExports`: matching subpath patterns in an import map | ||
* is the same as matching subpath patterns in an export map |
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.
True but nonetheless, using the "exports" name here is surprising. Before this PR they're private functions so there's no need to preserve the names.
I think I'd rename the functions to "subpaths map" or something as you suggested with @kraenhansen, and move them into a common location (probably under utils
).
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.
- Regarding the naming, I think it's a little tricky. I noticed a lot of comments already written by the team call these imports/export types: "'exports'-like", and I can't think of a better name. To me this feels the most natural name, probably because Node.js docs seems to skirt around giving them a name and just refers to them by pointing to the "exports" field.
- Nevertheless, I've renamed 3 functions and the
ExportMap
type to reflect that they are "'exports'-like" in order to indicate that they work for both importing with "imports" and exporting with "exports". Following your feedback, I've moved these functions to utils.
Let me know your thoughts!
We'll need to update the resolver algorithm docs as well, but I'm happy to take care of that when importing. |
Node allows you to alias to an external package, could you modify your implementation to allow that? Currently |
That's a great point, thanks for spotting that. I think that can land as a follow-up though, I'm wary of holding this PR up further, but I've noted it as something that we need to do asap and before claiming support for |
Yeah I think that's fair. Just one last comment based on my usage of this WIP feature: When there are references to other packages in the imports field, the current implementation will short circuit and throw an error as it considers those values to be invalid, which they are until it is implemented, but I think it would be better to compile the list of invalid values and echo that to the user, but still continue. The reason being that there could be valid values further down the import list and I think it's ideal if those are considered and processed. The reason I would suggest this, is lets say this is released. I then pull down that change and add a custom resolveRequest function to my config to handle the external packages until support is added, but since that short circuit is there, this won't process the "good" subpath imports. For example: |
3fee432
to
78db442
Compare
@robhogan hey Rob, when you get a chance would you mind having another look at this PR. I've tried to address all comments previously raised; please consider it "Ready to Review". Thank you so much! |
78db442
to
ab2d601
Compare
Summary
PR to add support in metro-resolver for resolving import subpaths; the feature discussed in Issue #978 in that reads the
"imports"
key inpackage.json
Test plan
npm run test
After Landing