fastest-validator
fastest-validator copied to clipboard
Develop in ESM?
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.
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?
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?
Yes, it would be great!. Thanks in advance.
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
I would like to keep Jest. But there is jest-babel plugin that it can compile the tests before running.