-
-
Notifications
You must be signed in to change notification settings - Fork 601
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): produce code which works when __esModule is already defined #1379
Conversation
2eccaf5
to
5435a30
Compare
@shellscape I am a bit confused. I ran tests locally and they passed. What do I need to make GitHub run tests for this PR? |
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.
I agree with the change but it would be very useful to add one test case for why you introduced the change. Otherwise, there is nothing preventing anyone who does not know about the problems from reintroducing the change.
As I understand it was an issue with an external dependency? You could for instance extend the esm-externals-undefined
test with a new external dependency that defines __esModule
in the way that your problematic dependency does (there is a checked-in node_modules folder in test
for these kinds of dependencies).
5435a30
to
c64666b
Compare
I did not find |
Ah I am sorry, it is in the |
I'll try to write test in
I think it does cover. For what I've seen, the code throws an exception at a runtime when the
No, that test fails without my changes. As I wrote, "the test I've added fails without |
|
But it also means that this is exactly a situation where we would want the wrapper, because we now have an ES module namespace without a prototype. I very much hope that this is not what your dependency did, at least that is why I think this change is ok.
I would have assumed your dependency was not ESM but rather an external CommonJS module that does this: exports.__esModule = true which would have the same effect but is a more real-world use-case. |
c64666b
to
e00d06e
Compare
The only case where I managed to get Also, I moved my existing test to |
e00d06e
to
bd064cf
Compare
bd064cf
to
b95d889
Compare
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.
Awesome, thank you very much for sticking with me!
Thank you! Your comments helped a lot in both understanding code better and improving merge request. One last thing. Do you have access to merge and publish a new version? If not, can you please tag someone to let this merged and published? |
In plugins, we would usually let the PR wait for some days so that others can add their comments before merging. |
@bhovhannes the CI failure was a workflow that validates the title of your PR. we use conventional commit format in this repo. I've fixed that for you and as soon as CI passes we should be able to merge. |
Thanks! |
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:
Description
Opening this MR after short discussion in https://github.com/rollup/plugins/pull/1038/files#r1048162869.
I have an issue in upgrading from
"@rollup/plugin-commonjs"@21.1.0
to"@rollup/plugin-commonjs"@latest
. I tracked problem down to version"@rollup/plugin-commonjs"@22.0.0
and it looks like all changes from"@rollup/plugin-commonjs"@21.1.0
to"@rollup/plugin-commonjs"@22.0.0
are in #1038.After looking into what was changed I noticed that the
if (n.__esModule) return n;
check ingetAugmentedNamespace
helper was removed.Unfortunately my codebase is complex and I cannot disclose code of some npm packages we have. But at least one of them already defines
__esModule
property. When commonjs plugin decides to usegetAugmentedNamespace
helper on that module it creates a broken code, because when being run, code ofgetAugmentedNamespace
helper attempts to define__esModule
property. That property already exists and code throws an exception.