mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-23 00:13:13 +09:00
Add checkEnabled and rename plugin loading files
plugins.checkEnabled(name) tells if a plugin is in the load list. #plugin_module is renamed to #import_plugin. loadPluginMigrations moves into PluginLoader.ts, leaving plugin_loader.ts with plugin discovery and details, so it is renamed to plugin_info.ts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
68c5ea82e7
commit
47c84fc289
12 files changed
+118
-101
No files matched your search
@@ -211,4 +211,61 @@ describe("lib/PluginLoader", function() {
|
||||
assert.equal(plugins.checkInstalled("missing"), false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("plugins.checkEnabled()", function() {
|
||||
it("should check the load list", async function() {
|
||||
const pluginInfo = info("test", "function.js");
|
||||
await load([pluginInfo], { installed: [pluginInfo, { name: "off" }] });
|
||||
const { plugins } = controller.loadedWith;
|
||||
assert.equal(plugins.checkEnabled("test"), true);
|
||||
assert.equal(plugins.checkEnabled("off"), false);
|
||||
assert.equal(plugins.checkEnabled("missing"), false);
|
||||
});
|
||||
});
|
||||
describe("loadPluginMigrations()", function() {
|
||||
const baseDir = path.resolve("temp", "test", "plugin", "migration_plugin");
|
||||
before(async function() {
|
||||
await fs.mkdir(baseDir, { recursive: true });
|
||||
await fs.writeFile(path.join(baseDir, "migrations.js"), `
|
||||
export default function(context) {
|
||||
context.hooks.controllerConfig.attach(context.plugin.name, config => {
|
||||
config.migratedBy = context.plugin.name;
|
||||
return config;
|
||||
});
|
||||
}
|
||||
`);
|
||||
await fs.writeFile(path.join(baseDir, "throwing.js"), `
|
||||
export default function() { throw new Error("load failed"); }
|
||||
`);
|
||||
});
|
||||
afterEach(function() {
|
||||
lib.ControllerConfig.pluginMigrations.clear();
|
||||
lib.Config.pluginVersions.clear();
|
||||
});
|
||||
|
||||
function migrationInfo(entrypoint) {
|
||||
return {
|
||||
name: "test",
|
||||
version: "1.0.0",
|
||||
packagePath: path.join(baseDir, "package.json"),
|
||||
migrationEntrypoint: entrypoint,
|
||||
};
|
||||
}
|
||||
|
||||
it("should attach migrations from the migration entrypoint", async function() {
|
||||
await lib.loadPluginMigrations([migrationInfo("migrations.js"), { name: "other" }]);
|
||||
assert.deepEqual([...lib.ControllerConfig.pluginMigrations.attached], ["test"]);
|
||||
assert.deepEqual(lib.ControllerConfig.pluginMigrations.reduce({}), { migratedBy: "test" });
|
||||
});
|
||||
it("should register the version of every plugin", async function() {
|
||||
await lib.loadPluginMigrations([migrationInfo("migrations.js"), { name: "other", version: "2.0.0" }]);
|
||||
assert.deepEqual([...lib.Config.pluginVersions], [["test", "1.0.0"], ["other", "2.0.0"]]);
|
||||
});
|
||||
it("should reject with a PluginError if the entrypoint throws", async function() {
|
||||
await assert.rejects(
|
||||
lib.loadPluginMigrations([migrationInfo("throwing.js")]),
|
||||
err => err instanceof lib.PluginError && err.pluginName === "test"
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -8,7 +8,7 @@ import * as lib from "@clusterio/lib";
|
||||
import { computePluginStatuses, planUpdate } from "../../packages/web_ui/src/util/plugin_status.ts";
|
||||
|
||||
|
||||
describe("lib/plugin_loader", function() {
|
||||
describe("lib/plugin_info", function() {
|
||||
describe("loadPluginInfos()", function() {
|
||||
let baseDir = path.join("temp", "test", "plugin");
|
||||
let missingPlugin = path.join(baseDir, "missing_plugin");
|
||||
@@ -121,52 +121,6 @@ describe("lib/plugin_loader", function() {
|
||||
);
|
||||
});
|
||||
});
|
||||
describe("loadPluginMigrations()", function() {
|
||||
const baseDir = path.resolve("temp", "test", "plugin", "migration_plugin");
|
||||
before(async function() {
|
||||
await fs.mkdir(baseDir, { recursive: true });
|
||||
await fs.writeFile(path.join(baseDir, "migrations.js"), `
|
||||
export default function(context) {
|
||||
context.hooks.controllerConfig.attach(context.plugin.name, config => {
|
||||
config.migratedBy = context.plugin.name;
|
||||
return config;
|
||||
});
|
||||
}
|
||||
`);
|
||||
await fs.writeFile(path.join(baseDir, "throwing.js"), `
|
||||
export default function() { throw new Error("load failed"); }
|
||||
`);
|
||||
});
|
||||
afterEach(function() {
|
||||
lib.ControllerConfig.pluginMigrations.clear();
|
||||
lib.Config.pluginVersions.clear();
|
||||
});
|
||||
|
||||
function info(entrypoint) {
|
||||
return {
|
||||
name: "test",
|
||||
version: "1.0.0",
|
||||
packagePath: path.join(baseDir, "package.json"),
|
||||
migrationEntrypoint: entrypoint,
|
||||
};
|
||||
}
|
||||
|
||||
it("should attach migrations from the migration entrypoint", async function() {
|
||||
await lib.loadPluginMigrations([info("migrations.js"), { name: "other" }]);
|
||||
assert.deepEqual([...lib.ControllerConfig.pluginMigrations.attached], ["test"]);
|
||||
assert.deepEqual(lib.ControllerConfig.pluginMigrations.reduce({}), { migratedBy: "test" });
|
||||
});
|
||||
it("should register the version of every plugin", async function() {
|
||||
await lib.loadPluginMigrations([info("migrations.js"), { name: "other", version: "2.0.0" }]);
|
||||
assert.deepEqual([...lib.Config.pluginVersions], [["test", "1.0.0"], ["other", "2.0.0"]]);
|
||||
});
|
||||
it("should reject with a PluginError if the entrypoint throws", async function() {
|
||||
await assert.rejects(
|
||||
lib.loadPluginMigrations([info("throwing.js")]),
|
||||
err => err instanceof lib.PluginError && err.pluginName === "test"
|
||||
);
|
||||
});
|
||||
});
|
||||
describe("loadPluginList()", async function() {
|
||||
const old_cwd = process.cwd();
|
||||
const baseDir = path.join("temp", "test", "plugin_list");
|
||||
Reference in new issue
Block a user