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 hasDefaultExport to ModuleInfo #4356
Conversation
Thank you for your contribution! ❤️You can try out this pull request locally by installing Rollup via npm install rollup/rollup#module-info-exports or load it into the REPL: |
646c9a1
to
8d216c3
Compare
Codecov Report
@@ Coverage Diff @@
## master #4356 +/- ##
=======================================
Coverage 98.69% 98.69%
=======================================
Files 205 205
Lines 7331 7334 +3
Branches 2084 2086 +2
=======================================
+ Hits 7235 7238 +3
Misses 36 36
Partials 60 60
Continue to review full report at Codecov.
|
Looks good. I don't see an issue implementing this in the Vite dev server once we need to support it. Thanks for keeping us in the loop @lukastaegert! |
That is good. Turns out I would really love to have this quickly to fix an issue with rollup/plugins#1038 so I will merge this. |
fa1d934
to
c917565
Compare
8d216c3
to
c2f0e1c
Compare
c2f0e1c
to
7466889
Compare
This PR contains:
Are tests included?
Breaking Changes?
List any relevant issue numbers:
Description
This is the second Plugin API extension I am working on at the moment. This time the goal is to ease to creation of proxy modules that just "reexport everything" from another module.
The problem here is that
does NOT reexport everything from "foo"—it just reexports all NAMED exports. But if there was a default export, it will be lost (not sure why things were designed that way, but that is what the specs say and what Rollup does). So if you also want to reexport the default export as well, you have to know whether it exists before writing the proxy.
My suggestion (implemented in this PR) is to add a flag
hasDefaultExport: boolean | null
toModuleInfo
. The valuenull
is used for external modules and before the module has been parsed.When you
const moduleInfo = await this.load({id})
, then you can be sure that (if the module exists),moduleInfo.hasDefaultExport
is the correct value.@yyx990803, @patak-dev, @antfu, @marvinhagemeister not sure if this would be a problem to implement in Vite or WMR. My hope was that you already have some kind of information available, in the worst case you could probably do something with regular expressions executed when accessing a getter to figure this out.
Here is an example from the docs that shows how to use this:
I also considered if we should make the names of all exports available, but the problem here would be how to handle namespace reexports: If we do it right, we would need to merge the named exports of another module, and the logic would quickly get complicated and problematic, or invent a special syntax for that case, or ignore that case, none of which seemed right to me. So that is why I would go for this boolean for now.