[babel-plugin] custom module resolution support #1293
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What changed / motivation ?
At HubSpot we use a homegrown package manager for frontend packages that is optimized for our (mostly) closed ecosystem. This can present challenges when integrating third-party tooling but, more often than not, the tooling will support a way to configure module resolution.
This PR introduces a
"custom"type to theunstable_moduleResolutionconfiguration option that will allow us and others to plug-in our own resolution algorithm without relying on forks or error-pronepatch-packagepatches. When using"custom"module resolution the consumer will need to provide their implementations forfilePathResolver(), andgetCanonicalFilePath().I have tested this branch locally and it works for our needs. I am currently using
patch-packageon top of0.16.2, although patching bundled code can be tricky and hard to maintain.Acknowledgments
filePathResolver()andgetCanonicalFilePath()leaks implementation details, or at least internal function naming, to the public API. If you prefer something more generic please recommend something.function. I wasn't sure if you were intentionally trying to limit the config only static values but I don't see another way.Omissions
experimental_crossFileParsing.createShortFilename()still has a implicit dependency on node_modules resolution for non-"haste"module resolution. I'm not familiar enough with that part of the codebase but we can add support in the future.Linked PR/Issues
This seems like it could be useful to resolve/workaround #1282
Pre-flight checklist
Contribution Guidelines