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

Better ESM/CJS support #648

Open
vladmoroz opened this issue Sep 27, 2024 · 0 comments
Open

Better ESM/CJS support #648

vladmoroz opened this issue Sep 27, 2024 · 0 comments
Assignees
Labels
bug 🐛 Something doesn't work core Infrastructure work going on behind the scenes status: waiting for maintainer These issues haven't been looked at yet by a maintainer

Comments

@vladmoroz
Copy link
Contributor

vladmoroz commented Sep 27, 2024

Current issues

  • Defaults to CJS even for modern Node
    • node folder for CJS is misleading and not discoverable
    • View source action in VS Code goes to the (hard to read) CJS version
  • package.json doesn’t specify the type field
  • ESM code is missing extensions
    • ESM version can't be used without a bunlder
    • Makes it incompatible with moduleResolution: "Node" | "NodeNext"

Suggestions

My preferred implementation would be to do what we learned from doing the dual package in Radix Themes (see on unpkg):

  • type: "commonjs" in the root package.json
  • type: "module" in the esm folder package.json
  • exports field with require and import declarations
  • Explicit cjs and esm folders in the built package
    • Makes it easy for consumers to find the right version if they need to explicitly point their tooling to the ESM/CJS version
  • Extensions in source code
    • No build tooling would be needed to transform extensions
    • ESLint can enforce this and auto add them, VSC support is good too

publint can be a good way to check if all looks good:
https://publint.dev/@base_ui/[email protected]
https://publint.dev/@radix-ui/[email protected]

Some details on the possible implementations:
https://www.sensedeep.com/blog/posts/2021/how-to-create-single-source-npm-module.html

@github-actions github-actions bot added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Sep 27, 2024
@vladmoroz vladmoroz added core Infrastructure work going on behind the scenes bug 🐛 Something doesn't work labels Sep 27, 2024
@atomiks atomiks assigned michaldudak and unassigned atomiks Sep 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work core Infrastructure work going on behind the scenes status: waiting for maintainer These issues haven't been looked at yet by a maintainer
Projects
None yet
Development

No branches or pull requests

3 participants