-
-
Notifications
You must be signed in to change notification settings - Fork 594
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
fix(commonjs): do not create fake named exports #427
Conversation
This is tough. It's a breaking change for anyone relying on the long-running bad behavior. It's a fix to anyone impacted negatively (issue reporter). Not sure which way to lean on this. |
@lukastaegert since |
Not sure. The plugin will still create named exports, just not in some edge case scenarios. I think you would only notice this if directly bundling an affected file as an entry point. For everyone else, this is a bug fix. But I guess you are right. |
I think that this makes a much healthier interop. I've seen weird unexpected exports in tests, even in those subtle cases of named exports vs default export, cjs vs es. They are gone now after this is merged. |
It is kind of fixing v12 to how it was supposed to work. |
If a common.js module has named exports (and |
Disclaimer: I'm sleep deprived because of spending the time I should've been sleeping on debugging. So at this point I might be missing something. But here's more or less what I've gathered from staring at diffs and changelogs. Feel free to correct me. I'm not all that familiar with CJS-ESM interop standards, but at least Babel converts ESM to CJS along the lines of what @FredKSchott describes. However, here it is a bit more complicated. Commonjs-plugin tries to convert CJS to ESM, which can be handled by rollup. Prior to this PR, Sorry if my explanation is overly convoluted. |
BREAKING CHANGE * fix(commonjs): do not create fake named exports * chore(commonjs): remove unneeded check
Rollup Plugin Name:
commonjs
This PR contains:
Are tests included?
Breaking Changes?
If yes, then include "BREAKING CHANGES:" in the first commit message body, followed by a description of what is breaking.
List any relevant issue numbers:
#423
Description
This one came up via #423 where a lot of unused assignments were added to the code. As it turns out, this plugin was already running its own version of "synthetic named exports", which unfortunately was providing sub-optimal results that did not work well with circular references and also left some non-treeshakeable residue.
This fixes this by only rendering named exports when we do not have to pick them off
module.exports
. In that situation, we rather leave this to Rollup'ssyntheticNamedExports
handling.Also, this adds a
/*@__PURE__*/
annotation tounwrapExports
because otherwise some unused default exports were leaving some calls in the code that were again not treeshakeable.