@sourceacademy/runner-module-loader
v0.1.0
Published
The runner plugin for the module loader in Source Academy
Readme
Features
The plugin provides an interface to load modules with a module ID
Installation
yarn add @sourceacademy/runner-module-loader
# OR
npm i @sourceacademy/runner-module-loader
# OR
pnpm add @sourceacademy/runner-module-loaderStructure
This package (@sourceacademy/runner-module-loader) contains the ModuleLoaderRunnerPlugin class — a Conductor runner plugin that an evaluator can call to load modules.
API Reference
| Name | Description |
|------|-------------|
| instance | The singleton instance of the plugin. |
| async requestModule(moduleName: string): Promise<IModulePlugin> | Request a module by name from the host plugin. Rejects with an error if the module is not found. |
Usage
After installation, import ModuleLoaderRunnerPlugin and register it with the Conductor evaluator. When evaluating import statements, call requestModule to load the module.
...
const pluginObj = await ModuleLoaderRunnerPlugin.instance.requestModule(moduleName);
context.nativeStorage.loadedModules[moduleName] = Object.fromEntries(
pluginObj?.exports.map(t => [t.symbol, t]) || [],
);
...Further reading
- For the shared protocol types and IDs, see
@sourceacademy/common-module-loader - For the host-side plugin that accepts the module directory URL, see
@sourceacademy/web-module-loader - The plugins wiki covers how Conductor plugins communicate
