feathersjs / feathers

The API and real-time application framework
https://feathersjs.com
MIT License
14.98k stars 743 forks source link

[FR] ESM exports of front-end packages #3207

Open FossPrime opened 1 year ago

FossPrime commented 1 year ago

We already do this for deno, and as we transpile from good TS, this should be fairly easy to wholesale. From my experience it's a matter of adding a single word to the transpiling tool.

Summary of the benefits (I'm missing a bunch, but I feel like this should not have been kicked down the can so I'll reiterate them here):

I've encountered this again while using a search-and-replace plugin to patch another Feathers issue. To use the plugin in a node module, the dependency I'm patching has to be a module too...

I've also seen issues with unpkg's module mode. There are also some performance benefits that can be had if we use module only settings in a few places like Vite. As we don't have HMR, and this is such a massive monorepo, every millisecond counts.

Screenshot 2023-06-05 00 31 48 Screenshot 2023-06-05 00 55 49

P.S. The same build tool that generates JS from TS can do it as an argument, and it does it with search and replace, so it does not significantly add to build time.


Looks like this has been surprisingly long in the making https://github.com/feathersjs/feathers/pull/2665/files

The changes look fairly minor, there are just a lot of small ones. It seems like we can do it package by package.

daffl commented 1 year ago

If someone can get that PR updated and everything passing I'd be ecstatic but @fratzinger spend a good amount of time on it and then I put about another week or so in and couldn't get it to work in a way that keeps it compatible with all environments that the modules can run in. From all I can tell this appears to be a lot more complicated than just adding the ESM build.

FossPrime commented 1 year ago

this appears to be a lot more complicated than just adding the ESM build.

I've done it a million times and it's well charted road. It's hard to say way will break, but we've kept dependencies updated and we're a bit late to the party... which is all good news.

I would love to work on this, but this monorepo is such a bear. I tried using YARN 2 and PNPM PlugNPlay mode... that just revealed how poorly connected eslint, mocha and lerna are internally.

I'll try to work on a few modules one by one, I don't see why not. Basically the same situation Python 2 to Python 3 migrations had.

daffl commented 1 year ago

For contributing you shouldn't run into any problems if you use plain old npm and follow the contribution steps. Like I said, a few people haven now spent quite a bit of time on this without success so any actual hands-on help would be very much appreciated.