Feature: Arbitrary sources for module source text
GeoffreyBooth opened this issue · comments
- I want to load modules from a database and not from the filesystem.
- I want to load modules from a URL.
Use case 6. Related to use case 38, about --eval
for ESM code.
This can be partially solved by the vm.Module
constructor and linking and evaluating the module yourself. Obviously it's not that elegant so I wouldn't call it a done solution, but at the very least the use case is accomplishable.
Perhaps the --loader
flag thing would also enable this use case, but I'm not too familiar with it.
Sorry I don't understand this use case, could you please provide a few examples?
Are the following example in this use case?
import tty from "unix:///dev/tty0"
import file from "file://tmp/foo"
import something from "tcp://localhost"
Pinging @ceejbot as this was their use case.
I would expect that there'd be a way to do both of the following:
- programmatically create a module, perhaps with VM.module, from an arbitrary string, and define it to be importable at some path
- define a custom loader that can handle custom URL protocols, or custom paths, that can load source text in real time.