Add waitForPlugin and load plugins concurrently

Plugins can wait for another plugin on the same controller, host or
instance with waitForPlugin(waiter, name, timeoutMs). It resolves to what
the other plugin's entrypoint returned, or to undefined with a warning
naming both plugins if it is not loaded once loading finishes or the
timeout runs out.

Plugin entrypoints now run concurrently so a plugin can await a plugin
later in the list from its entrypoint. loadedPlugins is still filled in
plugin list order, as the instance builds its Lua module list from it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
bbassieandClaude Opus 5.5 committed 2026-11-19 14:24:56 +00:00
1 parent eefb4be44b
commit c8e52e7bde
12 files changed
+408 -29

No files matched your search

+28 -5
View File
@@ -77,6 +77,7 @@ 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();
@@ -1317,8 +1318,22 @@ 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 context = { metrics, logger, controller: this };
const toLoad: lib.PluginNodeEnvInfo[] = [];
for (let pluginInfo of this.pluginInfos) {
try {
const manifestPath = path.posix.join(pluginInfo.requirePath, "dist", "web", "manifest.json");
@@ -1341,17 +1356,20 @@ export default class Controller {
continue;
}
toLoad.push(pluginInfo);
}
const context = { metrics, logger, controller: this };
await this._pluginLoader.load(toLoad, async pluginInfo => {
let api;
try {
await lib.loadPlugin(
api = await lib.loadPlugin(
pluginInfo,
"controller",
context,
"ControllerPlugin",
BaseControllerPlugin,
);
this.loadedPlugins.add(pluginInfo);
} catch (err: any) {
if (err.code === "InstallationError") {
throw err;
@@ -1360,6 +1378,11 @@ export default class Controller {
}
logger.info(`Loaded plugin ${pluginInfo.name}`);
return api;
});
for (const pluginInfo of toLoad) {
this.loadedPlugins.add(pluginInfo);
}
}