Skip to content
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): convert module.exports with __esModule property(#939) #942

Merged
merged 5 commits into from Jul 24, 2021

Conversation

githoniel
Copy link
Contributor

@githoniel githoniel commented Jul 16, 2021

Rollup Plugin Name: commonjs

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

List any relevant issue numbers: #939

Description

transform commonjs as module.exports = { __esModule: true, default: ... } to wrap runtime code

@guybedford
Copy link
Contributor

@githoniel as well as the unit test here, could you include a full end-to-end test of the original use case provided in #939?

It looks like the output of that test is currently:

{ default: 'symbol', __esModule };
'symbol2'

Can you clarify what the output of that same test becomes with this PR?

@shellscape shellscape force-pushed the master branch 2 times, most recently from 486cc69 to 34ba4ce Compare July 16, 2021 14:41
@githoniel
Copy link
Contributor Author

githoniel commented Jul 16, 2021

@guybedford thank for your time.

Look at this https://replit.com/@githoniel/rollup-plugin-repro-1 or the linked issue #939

many old package include babel-runtime publish its code like below

module.exports = { "default": require("core-js/features/object/get-own-property-descriptor"), __esModule: true };

import it will get an object as { "default": getOwnPropertyDescriptorFn, __esModule: true } with commojs plugin but should get getOwnPropertyDescriptorFn itself, it is not wrapped by

export function getDefaultExportFromCjs (x) {
    return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
}

I have add test sample for it

@guybedford
Copy link
Contributor

One issue here is this is the opposite interop pattern to Node.js itself... making this plugin unsuitable for building Node.js applications.

@githoniel
Copy link
Contributor Author

githoniel commented Jul 18, 2021

any idea?shall we add option like target: 'browse' | 'node'? or detect environment at runtime?

@guybedford
Copy link
Contributor

@githoniel I believe this is supposed to be controled by the defaultIsModuleExports configuration option - https://github.com/rollup/plugins/tree/master/packages/commonjs#defaultismoduleexports. So this PR should be sure to follow the semantics of that option as well I think.

@githoniel
Copy link
Contributor Author

@githoniel I believe this is supposed to be controled by the defaultIsModuleExports configuration option - https://github.com/rollup/plugins/tree/master/packages/commonjs#defaultismoduleexports. So this PR should be sure to follow the semantics of that option as well I think.

I have make it work and update new tests

Copy link
Contributor

@guybedford guybedford left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work checking these cases, thanks for the PR.

@guybedford
Copy link
Contributor

I know the prettier issue is unrelated, but are you able to get the CI to pass on this PR?

@guybedford guybedford merged commit 7757aeb into rollup:master Jul 24, 2021
@guybedford
Copy link
Contributor

Finally passing - thanks again for your work on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants