Flatten lib namespace

Move all functions and classes currently available through lib/name and
libName to be under a single flat namespace in lib.  This make
reorganising the lib namespace much simpler as the location of symbols
can move without breaking the consumers of lib.

The multi-entrypoint design was already problematic for the web plugin
system which couldn't effectively use it due to how webpack's shared
module system is awkward to set up with multiple entrypoints per package.
This commit is contained in:
Hornwitser committed 2023-07-28 16:03:29 +02:00
1 parent bb58670597
commit bfe119eaa3
143 files changed
+1798 -1918

No files matched your search

+8 -8
View File
@@ -3,8 +3,8 @@ const assert = require("assert").strict;
const fs = require("fs-extra");
const path = require("path");
const libPluginLoader = require("@clusterio/lib/plugin_loader");
const { escapeRegExp } = require("@clusterio/lib/helpers");
const lib = require("@clusterio/lib");
const { escapeRegExp } = lib;
describe("lib/plugin_loader", function() {
@@ -34,13 +34,13 @@ describe("lib/plugin_loader", function() {
it("should throw on missing plugin", async function() {
await assert.rejects(
libPluginLoader.loadPluginInfos(new Map([["missing", missingPlugin]]), []),
lib.loadPluginInfos(new Map([["missing", missingPlugin]]), []),
new RegExp(`^Error: PluginError: Cannot find module '${escapeRegExp(missingPlugin)}/info'`)
);
});
it("should load test plugin", async function() {
assert.deepEqual(
await libPluginLoader.loadPluginInfos(new Map([["test", path.resolve(testPlugin)]])),
await lib.loadPluginInfos(new Map([["test", path.resolve(testPlugin)]])),
[{ name: "test", version: "0.0.1", requirePath: path.resolve(testPlugin) }]
);
});
@@ -53,13 +53,13 @@ describe("lib/plugin_loader", function() {
brokenMessage = err.message;
}
await assert.rejects(
libPluginLoader.loadPluginInfos(new Map([["broken", path.resolve(brokenPlugin)]])),
lib.loadPluginInfos(new Map([["broken", path.resolve(brokenPlugin)]])),
{ message: `PluginError: ${brokenMessage}` }
);
});
it("should reject on invalid plugin", async function() {
await assert.rejects(
libPluginLoader.loadPluginInfos(new Map([["invalid", path.resolve(invalidPlugin)]])),
lib.loadPluginInfos(new Map([["invalid", path.resolve(invalidPlugin)]])),
{ message: `Expected plugin at ${path.resolve(invalidPlugin)} to be named invalid but got wrong` }
);
});
@@ -80,7 +80,7 @@ describe("lib/plugin_loader", function() {
});
it("should throw if class is missing from entrypoint", async function() {
await assert.rejects(
libPluginLoader.loadControllerPluginClass({
lib.loadControllerPluginClass({
name: "test",
controllerEntrypoint: "controller",
requirePath: path.resolve(missingClass),
@@ -94,7 +94,7 @@ describe("lib/plugin_loader", function() {
});
it("should throw if class is not a subclass of BaseControllerPlugin", async function() {
await assert.rejects(
libPluginLoader.loadControllerPluginClass({
lib.loadControllerPluginClass({
name: "test",
controllerEntrypoint: "controller",
requirePath: path.resolve(wrongParentClass),