Terminology: Modules and Resources #232
Description
As part of the chat between @bmeck and myself around how the main module map, hooks, and vm.SourceTextModule
should interact, we agreed that it would make sense to split the concept of "loading" and "loaders" into generic resource loading and the module system as a user of resource loading. The result were three separate concerns which are split between the module- and the resource system:
locate
: Turning a relative reference and a context into an absolute location.retrieve
: Retrieving a resource (content and associated meta data) from an absolute location.- Interpretation of a resource as a module.
Only the last item would be the job of the module system. The advantage is that modules could use the resource system to load additional data and reuse all the infrastructure. It would also allow writing web-compatible code that includes data files.
@bmeck did a write-up of a potential design for a resource API for node, including suggested hooks: https://docs.google.com/document/d/12-xJcMHH6r0QQG4fprQvHG1OO-OpZ-fSdxDIT8eKqKk/edit
The idea is to end up with a system where customizations (hooks) could be written in a way that can be fully isolated from application code, be it in a separate thread in node or in a service worker in the browser. And in most cases it should be possible to design it to have the same plugins/hooks in both environments.