barthofu / tscord

🤖 A fully-featured discord bot template written in Typescript, intended to provide a framework that's easy to use, extend and modify
https://tscord.discbot.app
MIT License
251 stars 19 forks source link

Migrate from `cjs` to `esm` #154

Open barthofu opened 8 months ago

barthofu commented 8 months ago

This draft PR is an attempt to ~finaly~ migrate from CJS to ESM.

Problem(s)

The most important problem is that ts-node (for dev) doesn't support tsconfig.paths aliases resolution in ESM. I've managed to quite fix that using a custom loader (./loader.js).

We also want to keep the commands and events HMR.

What I've done so far

  1. Switch tsconfig.target and tsconfig.module to esnext
  2. Complete the tsnode config block in the tsconfig json file
  3. Change the case dep which was CJS-only with change-case.
  4. Remove automatic DI in constructors in favor of a resolveDependencies 4.1 because of the error Cannot access X before initialization
  5. but now i got a max memory call stack error...

Solutions

  1. find a good loader file and make all of this work in ESM (currently being tested)
  2. find a way to build ts -> js on watch and serve the dev process from the js files, while keeping the HMR and speed advantages

Notes

zumbiepig commented 2 months ago

@barthofu You could get rid of ts-node completely by using Bun. It is a drop-in replacement for Node.js, and it supports running TypeScript files directly.