steve02081504
steve02081504β€’6mo ago

how to clear import cache of an file?

My project uses import to load submodules. And I want to make submodules reloadable without stopping the project: clearing the import cache of all mjs and ts files in the submodule folder and reimporting the entrypoint file. Is this possible to do in deno?
13 Replies
Doctor πŸ€–
Doctor πŸ€–β€’6mo ago
I think the eval method or running these as a worker would be more appropriate. You can't unload an import module from my understanding, but you can make it think your attempt to load it again is a different module, but I wouldn't recommend doing that.
bartlomieju
bartlomiejuβ€’6mo ago
That's correct, there's no way to "unload" a module that was imported
steve02081504
steve02081504OPβ€’6mo ago
can we add one in future?
Doctor πŸ€–
Doctor πŸ€–β€’6mo ago
I think that would go against the spec of the language
steve02081504
steve02081504OPβ€’6mo ago
For latecomers: you can clear the import cache in bun so that you can hot reload files easily. I'm currently trying to move my repo from deno to bun, but it's not going very well. bun's auto-install function is not as powerful as deno's nodemodulesdir=auto + --allow-scripts, this is an absolute fatal blow to my repo moving plan....
Doctor πŸ€–
Doctor πŸ€–β€’6mo ago
What are you trying to do that requires sub modules to be reloadable?
steve02081504
steve02081504OPβ€’6mo ago
hard to describe. My repo allows users to upload char. After decompression or clone from url, main.mjs under the char folder will be loaded by the repo as an entry point to provide services to user. This is the reason why I hope bun’s auto-install can load all packages. I wish char authors can use the packages they want, but bun cannot do this for now. I wish that the reloading feature will make debugging easier for char authors, it would be useful if char could be easily reloaded without restarting the entire server. And I also want to deal with the situation where the user uninstalls the char and then installs a char with the same name but different content.
john smith
john smithβ€’6mo ago
If possible, could you please teach me how to rewrite the deno project into a bun project? I don’t understand bun very well:lemon_deno:
steve02081504
steve02081504OPβ€’6mo ago
if you don't rely too much on deno's auto install and havent use deno's unique framework, move to bun is simple. you just need to replace all node: and npm: stuff to nothing and it's basically all. it's not difficult, just ask AI and try more!
john smith
john smithβ€’6mo ago
oh, thank you! And good luck.
steve02081504
steve02081504OPβ€’18h ago
update: now you can use https://github.com/CyanProjects/done for hot reloading codes
GitHub
GitHub - CyanProjects/done: We finally move to the Done time.
We finally move to the Done time. Contribute to CyanProjects/done development by creating an account on GitHub.
Mrcool πŸ‡΅πŸ‡Έ
I remembered there was a trick that if you add random fragments to the url deno will consider it a new one, might be useful for certain use cases
No description

Did you find this page helpful?