ajv icon indicating copy to clipboard operation
ajv copied to clipboard

chore: provide an esm distribution

Open me4502 opened this issue 3 years ago • 4 comments

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

me4502 avatar Nov 15 '22 06:11 me4502

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.

cyberwombat avatar Dec 20 '22 22:12 cyberwombat

@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.

Zamiell avatar Feb 02 '23 23:02 Zamiell

This looks like a great addition 👍🏻 Has anyone found an alternative solution?

dasa avatar Oct 04 '23 17:10 dasa

Any updates on this? This is a showstopper for us as well.

phoenix-oes avatar Aug 28 '24 18:08 phoenix-oes