This PR adds ESM support by adding an index.mjs file and the appropiate package.json field (module), I also added exports. 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.
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 mime-db@2.0.0. 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.
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: https://github.com/evanw/esbuild/issues/1828 https://github.com/rollup/rollup/issues/4274Another 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 mime-db@2.0.0. 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.