This repository was archived by the owner on Aug 4, 2021. It is now read-only.
[Do Not Merge] Different strategy for named export mapping (fixes #419) - #420
Closed
bterlson wants to merge 4 commits into
Closed
[Do Not Merge] Different strategy for named export mapping (fixes #419)#420bterlson wants to merge 4 commits into
bterlson wants to merge 4 commits into
Conversation
Contributor
Author
|
Updated to take advantage of rollup/rollup-plugin-node-resolve#244. Tests are now failing as in the current implementation, if you do not have the latest rollup-plugin-node-resolve, you cannot use namedExports keys that are module names. Couple options:
Curious if anyone has preferences here. |
Contributor
|
@bterlson we're gearing up to move this plugin to |
Contributor
Author
|
Since the changes here aren't too extensive, I'm ok closing this and rebuilding it again from its new location. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
#419 observes that a named exports field like:
Won't work right when jquery is not a direct dependency and therefore might not be present in
node_modulesin some package managers, or when multiple copies of jquery exist in your compilation.This PR addresses the problem by not mapping module names to paths up front. Instead, the module name itself is preserved in the
customNamedExportsmap, along with the path.resolve'd path and the realpath (if different). Later during transform, the package scope for each module id is found, its package.jsonnamefield is read, and looked up incustomNamedExports. If an entry is found, that is used, else the mapping for the id as-is is used.On the plus side, we no longer have a dependency on
browserify/resolveand do less work up front. On the minus side, we're doing a lot more work duringtransform, and so I expect on the balance this will be a performance regression. To me, the trade-off seems worth it, but I'll leave the final call to others to decide.Further work if this overall approach is acceptable: map only the module's entrypoints (
main, andbrowserorbrowser-mappedmain). Right now all tests pass as is but this doesn't work for cjs modules which import other cjs modules.