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

+4 -5
View File
@@ -1,13 +1,12 @@
"use strict";
const libPlugin = require("@clusterio/lib/plugin");
const { BaseControlPlugin, CommandTree, Command } = require("@clusterio/lib");
const { ChatEvent } = require("./messages");
const libCommand = require("@clusterio/lib/command");
const globalChatCommands = new libCommand.CommandTree({
const globalChatCommands = new CommandTree({
name: "global-chat", description: "Global Chat plugin commands",
});
globalChatCommands.add(new libCommand.Command({
globalChatCommands.add(new Command({
definition: ["shout <message>", "Send message to all instances", (yargs) => {
yargs.positional("message", { describe: "message to send", type: "string" });
}],
@@ -16,7 +15,7 @@ globalChatCommands.add(new libCommand.Command({
},
}));
class ControlPlugin extends libPlugin.BaseControlPlugin {
class ControlPlugin extends BaseControlPlugin {
async addCommands(rootCommand) {
rootCommand.add(globalChatCommands);
}
+3 -4
View File
@@ -2,8 +2,7 @@
* @module
*/
"use strict";
const libPlugin = require("@clusterio/lib/plugin");
const libLuaTools = require("@clusterio/lib/lua_tools");
const lib = require("@clusterio/lib");
const { ChatEvent } = require("./messages");
@@ -17,7 +16,7 @@ function removeTags(content) {
return content.replace(/(\[gps=-?\d+,-?\d+\]|\[train=\d+\])/g, "");
}
class InstancePlugin extends libPlugin.BaseInstancePlugin {
class InstancePlugin extends lib.BaseInstancePlugin {
async init() {
this.messageQueue = [];
this.instance.handle(ChatEvent, this.handleChatEvent.bind(this));
@@ -35,7 +34,7 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin {
async handleChatEvent(event) {
// TODO check if cross server chat is enabled
let content = `[${event.instanceName}] ${removeTags(event.content)}`;
await this.sendRcon(`/sc game.print('${libLuaTools.escapeString(content)}')`, true);
await this.sendRcon(`/sc game.print('${lib.escapeString(content)}')`, true);
}
sendChat(message) {
+2 -2
View File
@@ -1,6 +1,6 @@
"use strict";
const assert = require("assert").strict;
const libLink = require("@clusterio/lib/link");
const lib = require("@clusterio/lib");
const mock = require("../../../test/mock");
const lines = require("../../../test/lib/factorio/lines");
@@ -26,7 +26,7 @@ describe("global_chat plugin", function() {
let instancePlugin;
before(async function() {
libLink.Link.register(ChatEvent);
lib.Link.register(ChatEvent);
instancePlugin = new instance.InstancePlugin(info, new mock.MockInstance(), new mock.MockHost());
await instancePlugin.init();
});