Bromeon/js-sandbox

Support modules

Opened this issue · 3 comments

I think the default Deno runtime options don't support module resolution. I'm not familiar with the Deno API, how difficult would it be to enable this feature?

I assume you mean something like this? https://deno.land/manual/examples/import_export

I'm not sure if I want to support dynamically loading modules from the internet (for sandboxing reasons), or implement a complex dependency resolution. For local JS modules (import/export), I would need to look into them and what Deno offers.

Do you have a concrete use case in mind?

Yes, forgive me for being so terse. Importing both local modules and modules from node_modules would be interesting. The use case for this would be to be able to use libraries from NPM within the sandbox.

Sorry for the late reply. Back then there was no easy way to have modules in an embedded Rust application.
Directions I got were:

  • try to use swc and its bundler
  • look how Deno's CLI crate does it
    • however that spans caching, module loader and a few unrelated things
  • use the deno_core dependency resolver, but provide own module loader

Probably the last option is the most promising, but it would need more research to know what exactly it entails. Maybe documentation on this part has improved in the meantime, if someone has experience or inputs, that would be helpful!