chore: provide an esm distribution
What issue does this pull request resolve?
https://github.com/ajv-validator/ajv/issues/2015
What changes did you make?
I setup the build script to create a second distribution folder containing esm. This is done by running tsc with two flags passed to it, that alter the output directory, and the module format. The rest uses the existing tsconfig.
I passed the module entrypoint of the package json to this distribution, which allows anything that supports ESM to consume a native ESM version. This allows better tree shaking and scope hoisting for supported environments.
This makes no alterations to existing distributions, and the bundles are left unchanged. This only affects the package when consumed via the package.json file in an environment supporting ESM.
Is there anything that requires more attention while reviewing?
I'm a bit confused about why files in the runtime folder assign a code property that contains a require statement in a string. Currently this continues to point to the CJS variants of the files in case this is required
dist-esm needs to be added to the files entry of package.json. I had some issues importing it though - my code is all esm but still pulling from dist. Not sure what I am missing though. I played around with adding exports field without success.
@epoberezkin Can you please review this pull request? I am trying to update my JavaScript project to use ESM and I use Ajv, so this is a show-stopper for me, and I'm sure many others as well.
This looks like a great addition 👍🏻 Has anyone found an alternative solution?
Any updates on this? This is a showstopper for us as well.