Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds ESM support by adding an
index.mjs
file and the appropiate package.json field (module
), I also addedexports
. The import uses the experimental JSON module syntax (https://nodejs.org/api/esm.html#json-modules), which requires Node 16.14+.I also added a Github workflow and a new test file that uses Node's test runner. FWIW, the tests merged at some point in the future.
An alternative would be to use
createRequire
, but it does not seem well supported by bundlers:evanw/esbuild#1828
rollup/rollup#4274
Another alternative would be to just drop CommonJS altogether, and only provide a ESM export, dropping Node 0 - 16.13 support, and bumping one major version to [email protected]. After all, everything up to Node 14 has reached EOL, even Node 16 is getting close. That way, the
engines
field in the package.json could also be adjusted appropiately.Maybe some years down the line...
PS: It's 2023, I think it's OK to drop some old Node versions and io.js from the CI :)
It could be massively simplified by just using a node-version matrix entry and the setup-node GH action.