fastest-validator icon indicating copy to clipboard operation
fastest-validator copied to clipboard

Develop in ESM?

Open lukeed opened this issue 7 years ago • 5 comments

Hey,

I was thinking – this library could really benefit from developing with ESM. It's small enough to be used in the browser, but can also be cheaply inlined into servers. Load & parse times get quicker, too.

Very little has to change! ...especially since the codebase is already so neatly organized.

The only draw back is that it involves a build step before publishing, which I used to be against, but it's served me well since adopting the practice for Node.js modules & especially with browser-and-Node.js compatible modules.

The final build would be a single file (one for ESM and one for CJS) that exports the Validator class. You also need to add a module entry to package.json and that's it~!quicker.

lukeed avatar Nov 25 '18 21:11 lukeed

Hi,

it sounds interesting. Currently, there is a build step before publishing, because rollup bundles the code for browsers. What other tasks should we do?

icebob avatar Nov 25 '18 21:11 icebob

Oh, ha! I missed that.

It's just missing a module entry (for consumers to continue developing in ESM).

Would you like a PR that addresses this & makes some other build optimizations?

lukeed avatar Nov 25 '18 21:11 lukeed

Yes, it would be great!. Thanks in advance.

icebob avatar Nov 25 '18 21:11 icebob

Hmm... jest is being a pain in the butt with ESM. There's no require hook exposed.

Are you okay if I use Babel for testing only? The alternatives are to

(a) do a separate CJS build for testing only (preserving individual files)

(b) use a different test framework that exposes the node require hook (so that esm can be used)

I generally use tape but don't want to mess with your testing unless you want it

lukeed avatar Nov 25 '18 23:11 lukeed

I would like to keep Jest. But there is jest-babel plugin that it can compile the tests before running.

icebob avatar Nov 26 '18 08:11 icebob