-
Notifications
You must be signed in to change notification settings - Fork 44
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
Add ESM Support. #36
base: latest
Are you sure you want to change the base?
Add ESM Support. #36
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am looking forward to ESM support in this package! I added some suggestions to the commits in this PR.
@iarna any ETA on this getting merged? |
Related: trying to use with vite gives |
I use vite, got error: Uncaught ReferenceError: global is not defined. ESM support would be nice.So I made an ESM verion,works well with vite |
use iarna-toml-esm |
Probably makes sense to use https://github.com/squirrelchat/smol-toml |
Yes, I find it in TOML offical repo. But iarna-toml repo is the first search result when I search "TOML" key word by github search bar |
This PR adds full ESM support for all viable versions (Node 12-14 and above), while also maintaining full CommonJS support in every version. This is achieved through a very simple wrapper file that re-exports CommonJS code as ESM, but only when an
import
statement is used instead ofrequire()
.Node 12-13 have highly experimental ESM support that may require a flag and/or a subpath (
import "@iarna/toml/esm"
) in order to function. If you don't wish to support this, or if you find the/esm
subpath messy, you could easily remove the"./esm": "./toml-esm.mjs"
line from thepackage.json
file, while still maintaining full ESM support in Node 14 and all later versions.I was unsure if any documentation is necessary for this change, but I would think at most a small note would be enough. Feel free to let me know if (and ideally what kind of) documentation is necessary.
Fixes #32