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

[Feature request] Provide exports that work in the browser? #25

Closed
LeaVerou opened this issue Jul 15, 2024 · 4 comments · Fixed by #26
Closed

[Feature request] Provide exports that work in the browser? #25

LeaVerou opened this issue Jul 15, 2024 · 4 comments · Fixed by #26
Labels
enhancement New feature or request

Comments

@LeaVerou
Copy link

LeaVerou commented Jul 15, 2024

Thank you for making this!

Currently this package is very hard to import directly in the browser, even with import maps.

@cyyynthia
Copy link
Member

Hmm, that makes sense as the package is bundled as cjs to maximize compatibility for people stuck in cjs for whatever reason, and I don't dual-bundle to keep the build process simple so there's no esm entrypoint... Does importing the package from esm.sh (https://esm.sh/smol-toml@1.2.2) work?

@LeaVerou
Copy link
Author

LeaVerou commented Jul 16, 2024

Yes, it does (and is what I had done until now) but introducing a CDN dependency for that is suboptimal.
I'll be cheeky and suggest ESM only if you're only doing a single bundle. It’s the future for Node too :)

@cyyynthia
Copy link
Member

I'll be cheeky and suggest ESM only if you're only doing a single bundle. It’s the future for Node too

Well, I used to do that until version 1.2.0 released May 15th this year. I too am a believer in ESM-only but the sad reality is that we're far from bring there yet, and I've had quite a few people ask me for CJS support, including markdownlint-cli for instance.

The space of toml libraries in the JS ecosystem being quite empty, I decided to go the CJS route to offer something to people still on CJS, kind of as a duty to offer a viable path for people who are on CJS but want a good quality lightweight lib for parsing modern toml files.

The recent plans Node is working on allowing require to work for synchronous ESM would solve 99% of the issues in the library side of things, and I'm extremely annoyed that this isn't something that was worked on day 1 but here we are.

It's reasonable to except a library to be ESM-friendly; when I evaluated if it was viable to just export CJS I honestly overlooked your case where true ESM is mandatory. It's also reasonable to consider the external CDN route suboptimal. I'll look into dual-bundling the lib, I can probably just output ESM first and just throw the result in esbuild for an ugly CJS-friendly entrypoint 👍🏻

@LeaVerou
Copy link
Author

Thank you so much!!

The space of toml libraries in the JS ecosystem being quite empty

The space of toml libraries that use ESM that also works in the browser is even more empty lol — I think yours might be the first!

@cyyynthia cyyynthia added the enhancement New feature or request label Jul 16, 2024
cyyynthia added a commit that referenced this issue Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants