validator.js icon indicating copy to clipboard operation
validator.js copied to clipboard

feat: Fix interop with cjs-module-lexer

Open benasher44 opened this issue 1 year ago • 9 comments

This moves the main validator exports to validator-main.js (avoid conflict with top-level validator.js when running build), which then allows both a default and named exports in the index by re-exporting. By doing this, we get a CJS validator that also can be name-imported in node ESM.

Checklist

  • [x] PR contains only changes related; no stray files, etc.
  • [x] README updated (where applicable)
  • [ ] Tests written (where applicable)
  • [x] References provided in PR (where applicable)

benasher44 avatar Feb 28 '24 04:02 benasher44

Well I got pretty far just with this small change, but now I can't figure out how to get the AMD test to pass… any pointers there?

benasher44 avatar Feb 28 '24 05:02 benasher44

I also tried without adding a file to re-export from + just copy pasting all of the exports in the default export as named exports, but that has the same issue (seemingly) breaking AMD.

benasher44 avatar Feb 28 '24 17:02 benasher44

When building babel does give a warning;

Using named and default exports together. Consumers of your bundle will have to use validator['default'] to access the default export, which may not be what you want. Use `exports: 'named'` to disable this warning

That's also what seems to be changed in the built files. Apart from the expected additional exports it also returned validator before but now that's part of exports['default']. Unfortunately I have no experience with AMD to help out further

WikiRik avatar Mar 01 '24 12:03 WikiRik

No problem. Thanks anyway! Yeah that's what I discovered as well. I did all kinds of inspection there and couldn't figure out a different way to get to the original module object shape it was expecting before :(

benasher44 avatar Mar 01 '24 14:03 benasher44

Might just be a Babel thing. I know there is an outdated PR from one of the maintainers that tried to overhaul the config (also because we're on old versions of Babel and Rollup); https://github.com/validatorjs/validator.js/pull/1869

Maybe a smaller version of that is the way to go, but merging PRs is often quite slow with the current maintainers, see #2376

WikiRik avatar Mar 01 '24 15:03 WikiRik

It could be, but in my local build, I tried with the latest version of Babel 8, which didn't change anything.

benasher44 avatar Mar 01 '24 15:03 benasher44

I'll take a look at this while on my dev machine. But this is not a disruptive change like what I've seen in the past. Happy to see this land once all t's are crossed.

profnandaa avatar Mar 05 '24 13:03 profnandaa

@profnandaa any chance you'll have time to look soon?

benasher44 avatar Apr 20 '24 19:04 benasher44

Bisakah aplikasi crome itu di perketat suapaya kalaw saya main slot engine tidak kalah tolong dibantu

kojang123 avatar Jan 09 '25 14:01 kojang123