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: allow cjs version of packages to export a default value #943

Merged
merged 3 commits into from
Nov 30, 2023

Conversation

straker
Copy link
Contributor

@straker straker commented Nov 21, 2023

This adds an esbuild plugin to "fix" the esbuild problem of having export default a changed into module.exports.default = a instead of modules.exports = a. Using the plugin removes the build warnings we get from esbuild when we tried to add module.exports into the code to do this manually.

Closes #948

@straker straker requested a review from a team as a code owner November 21, 2023 21:07
@straker straker changed the title chore: allow csj to export a default value fix: allow cjs version of packages to export a default value Nov 21, 2023
Comment on lines +4 to +9
* "Fixes" the esbuild problem of exporting the CJS default export as `module.exports.default`
* instead of `module.exports`. The plugin appends a block of code to the file that takes the
* `.default` module export and re-exports it as `module.exports`. It then takes all named
* exports and re-exports them as part of the `module.exports` under the same name. This also
* gives the benefit of exporting the `.default` module which allows us to support all 3 export
* styles: the default export, `.default` export, and named exports.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there an issue with ESBuild open on this? If not, could you submit one? This feels like it would be a generally useful feature.

WilcoFiers
WilcoFiers previously approved these changes Nov 27, 2023
Copy link
Contributor

@WilcoFiers WilcoFiers left a comment

Choose a reason for hiding this comment

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

Small nitpick, up to you.

utils/esbuild-plugin-cjs-interop.ts Outdated Show resolved Hide resolved
@straker straker merged commit b5aee34 into develop Nov 30, 2023
30 checks passed
@straker straker deleted the cjs-interop branch November 30, 2023 15:00
@github-actions github-actions bot mentioned this pull request Nov 30, 2023
@dequejenn dequejenn mentioned this pull request Dec 5, 2023
@github-actions github-actions bot mentioned this pull request Jan 9, 2024
@github-actions github-actions bot mentioned this pull request Jan 23, 2024
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.

webdriverjs 4.7.3 broke default export in CJS
2 participants