chookscord / framework

Fast Discord.JS Framework
https://guide.chooks.app
MIT License
21 stars 4 forks source link

feat: ESM support #25

Closed Chooks22 closed 2 years ago

Chooks22 commented 3 years ago

Not sure if bundler is necessarily needed, might just hack in another tsconfig file or just do it in the build script.

Biggest road block here is hot reloading, since commonjs' equivalent for require.cachecurrently in use is not available in es modules.

The following snippet seems to work, and switching between esm and cjs should be straightforward, but it leads to memory leaks in dev mode.

export function uncachedImport(path) {
  return import(`${path}?update=${Date.now()}`);
}
Chooks22 commented 2 years ago

Moving to implement a feature for hot reloading that might lock this project in CommonJS.

If anyone more versed in ES Modules' caching in node is interested (or can at least give insights), dm me at discord Chooks22#6725

Chooks22 commented 2 years ago

A small update on this:

I have a working prototype for this locally. Still not yet fully tested and not 100% sure I will be able to integrate, but things are looking pretty good.

How it works is splitting the cli commands to its own global package (so running chooks directly in the terminal), then having maybe separate code for esm/cjs (not yet tested), with the esm code being accessible with the --esm flag.

The outcome will be a new global cli package, and whats left of the current framework will be a new "core" package. And since it's a trimmed down version of what it used to be, the current lib, types, and validation packages will be merged for simplicity.