Load all plugin types through one short lived PluginLoader

PluginLoader.load takes the plugin type, context, export name and base
class as options and is used by the controller, host, instance, ctl, web
interface and migrations. Module imports go through #plugin_module so the
node variant stays out of the web bundle. loadPlugin.ts and the loading
half of plugin_loader.ts are merged into it.

The loader lives for one load. Plugins reach it through context.plugins,
with waitFor(name, timeoutMs) and checkInstalled(name), replacing the
waitForPlugin methods. Waiting on a plugin that is not in the load list or
failed to load settles right away, as loading can't finish while the
waiting entrypoint is still running.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
bbassieandClaude Opus 5.5 committed 2026-11-20 21:29:23 +00:00
1 parent 7f688d2ed0
commit c1ea4d470b
20 files changed
+500 -522

No files matched your search

+9 -37
View File
@@ -77,7 +77,6 @@ export default class Controller {
hooks = new ControllerHooks(logger);
/** Plugins which are currently loaded */
loadedPlugins: Set<lib.PluginNodeEnvInfo> = new Set();
private _pluginLoader = new lib.PluginLoader(logger);
/** Latest versions of plugins on npm, as shown on the plugins page */
pluginLatestVersionCache: lib.LatestVersionCache = new Map();
@@ -1580,20 +1579,6 @@ export default class Controller {
}
}
/**
* Wait for another plugin to load
*
* @param waiter - Name of the plugin waiting, used in warnings.
* @param name - Name of the plugin to wait for.
* @param timeoutMs - Time to wait before giving up.
* @returns
* What the plugin's entrypoint returned, or undefined with a
* warning logged if it did not load.
*/
waitForPlugin<T = unknown>(waiter: string, name: string, timeoutMs?: number) {
return this._pluginLoader.waitFor<T>(waiter, name, timeoutMs);
}
async loadPlugins() {
const toLoad: lib.PluginNodeEnvInfo[] = [];
for (let pluginInfo of this.pluginInfos) {
@@ -1621,29 +1606,16 @@ export default class Controller {
toLoad.push(pluginInfo);
}
const context = { metrics, logger, controller: this };
await this._pluginLoader.load(toLoad, async pluginInfo => {
let api;
try {
api = await lib.loadPlugin(
pluginInfo,
"controller",
context,
"ControllerPlugin",
BaseControllerPlugin,
);
} catch (err: any) {
if (err.code === "InstallationError") {
throw err;
}
throw new lib.PluginError(pluginInfo.name, err);
}
logger.info(`Loaded plugin ${pluginInfo.name}`);
return api;
const { loaded } = await lib.PluginLoader.load({
type: "controller",
context: { metrics, controller: this },
logger,
installed: this.pluginInfos,
load: toLoad,
exportName: "ControllerPlugin",
baseClass: BaseControllerPlugin,
});
for (const pluginInfo of toLoad) {
for (const pluginInfo of loaded.keys()) {
this.loadedPlugins.add(pluginInfo);
}
}