Hello,
I've run into some headache-ing level issues while trying to implement some sort of custom hot-reloading for my discord bot, using ts compiled to cjs with tsc, running on node
-# You might think it's overkill but it's actually really useful considering i'm running everything on docker
Currently compiling ts to cjs, and i've noticed it looks like in ts-compiled cjs, that imported functions are actually copied locally, now idk if it's a shallow or actual copy (assuming the latter given the issue)
Because when invalidating the cache for the exports of a file, and replacing them with the new content, other files using those exported functions would still use the old, invalidated version, unless i was to also reload those files.
The hot-reloading "toolchain" works as follow:
I have a tsc daemon running, watching for changes on the .ts files
When changes are detected, the new files are compiled to cjs and moved to the mounted volume
Inside the bot is a watcher module that will look for changes on the .js files, invalidate the cache for these files and load the new exported contents
Now, i've noticed that imports work differently on ESM but i am not accostumed yet with ESM and am neither a "pro" of TS.
Would compiling to ESM make my life easier regarding a hot-reload of this sort? Or is there some setting of tsc i'm not aware of to help here?
Sorry for the long read, tried to be as explicit as possible !