Add typed hook system for plugins

Replace invokeHook and the per plugin on* methods with AsyncHook
collections on the controller, host, instance, clusterioctl and web
control objects. Plugin entrypoints export a default function that
receives a load context and attaches handlers to the hooks it needs.
Class exports still load through fromContext with a deprecation
warning. The create templates and docs use the entrypoint function.

This is clusterio/clusterio#921 recreated on top of master after the
ESM migration and the PluginDeclaration permissions change.

Closes #730

Co-Authored-By: Cooldude2606 <25043174+Cooldude2606@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
committed 2026-09-11 22:49:09 +00:00
1 parent 8c03ac15ab
commit 7122cbccf8
64 files changed
+1878 -1184

No files matched your search

+9 -9
View File
@@ -1,6 +1,6 @@
import * as lib from "@clusterio/lib";
import packageJson from "../../package.json";
import BaseWebPlugin, { type InputComponent } from "../BaseWebPlugin";
import * as WebPlugin from "../BaseWebPlugin";
const { logFilter, logger } = lib;
@@ -51,9 +51,13 @@ export class Control extends lib.Link {
/** Roles of the account this control link is connected as. */
accountRoles: lib.AccountRole[] | null = null;
/** Plugins loaded in the web interface */
public plugins = new Map<string, BaseWebPlugin>();
public inputComponents: Record<string, InputComponent> = {};
public hooks = new WebPlugin.WebHooks(logger);
public plugins = new Map<string, WebPlugin.BaseWebPlugin>();
public loadedPlugins = new Map<string, lib.PluginWebpackEnvInfo>();
public inputComponents = new Map<string, WebPlugin.InputComponent>();
public extensionComponents: Partial<WebPlugin.ExtensionComponents> = {};
public loginForms: WebPlugin.PluginLoginForm[] = [];
public pages: WebPlugin.PluginPage[] = [];
/** Updates not handled by the subscription service */
accountUpdateHandlers: accountHandler[] = [];
@@ -101,11 +105,7 @@ export class Control extends lib.Link {
});
for (let event of ["connect", "drop", "resume", "close"] as const) {
this.connector.on(event, () => {
for (let plugin of this.plugins.values()) {
plugin.onControllerConnectionEvent(event);
}
});
this.connector.on(event, this.hooks.controllerConnectionEvent.listener);
}
this.handle(lib.AccountUpdateEvent, this.handleAccountUpdateEvent.bind(this));