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

feat: add option for interop default in cjs #947

Merged
merged 5 commits into from Aug 2, 2023
Merged

feat: add option for interop default in cjs #947

merged 5 commits into from Aug 2, 2023

Conversation

sxzz
Copy link
Collaborator

@sxzz sxzz commented Jul 8, 2023

Description

Introduce a new option cjsInterop.

In the CJS file, if there's only an export default, then make it to module.exports = _default, instead of module.exports = { default: _default }.

For dts files, it will replace export { _default as default } with export = _default

Usage

// before
const mod = require('something').default

// after
const mod = require('something')

Relate issues

Closes #572

Additional Information

It would be really helpful for removing tons of post-build scripts.

sucrase also had an option enableLegacyBabel5ModuleInterop, with the same effect.

@vercel
Copy link

vercel bot commented Jul 8, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
tsup ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 29, 2023 7:22am

@egoist
Copy link
Owner

egoist commented Jul 28, 2023

Can you also update the docs?

@sxzz
Copy link
Collaborator Author

sxzz commented Jul 29, 2023

@egoist Done

@sxzz sxzz merged commit d870f4e into egoist:dev Aug 2, 2023
8 checks passed
@sxzz sxzz deleted the feat/cjs-interop branch August 2, 2023 15:05
@github-actions
Copy link

github-actions bot commented Aug 2, 2023

🎉 This PR is included in version 7.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

Possible to have export default emit as module.exports
2 participants