Move export for plugin declaration (#555)

Change the expected exported name of plugin declarations to be "plugin"
at the main entrypoint instead of the default export.  This makes the
plugin's code organisation more flexible especially when using CommonJS
JavaScript modules as they can export additional symbols from the
plugin declaration file.
This commit is contained in:
Hornwitser authored and GitHub committed 2024-01-18 20:31:52 +01:00
1 parent 8884116ee9
commit b0f6c95fca
33 files changed
+71 -62

No files matched your search

+5 -5
View File
@@ -12,11 +12,11 @@ const lib = require("@clusterio/lib");
const { LineSplitter, ConsoleTransport, logger } = lib;
// Make sure permissions from plugins are loaded
require("../../plugins/global_chat/dist/plugin/info");
require("../../plugins/player_auth/dist/plugin/info");
require("../../plugins/research_sync/dist/plugin/info");
require("../../plugins/statistics_exporter/dist/plugin/info");
require("../../plugins/subspace_storage/dist/plugin/info");
require("../../plugins/global_chat/dist/plugin/index");
require("../../plugins/player_auth/dist/plugin/index");
require("../../plugins/research_sync/dist/plugin/index");
require("../../plugins/statistics_exporter/dist/plugin/index");
require("../../plugins/subspace_storage/dist/plugin/index");
const subspaceStorageVersion = "1.99.8";
const subspaceStorageGitHubTag = "1.99.6"; // Tag subspaceStorageVersion was released under on GitHub
+5 -5
View File
@@ -18,18 +18,18 @@ describe("lib/plugin_loader", function() {
before(async function() {
async function writePlugin(pluginPath, infoName) {
await fs.outputFile(
path.join(pluginPath, "info.js"),
`module.exports.default = { name: "${infoName}" };`
path.join(pluginPath, "index.js"),
`module.exports.plugin = { name: "${infoName}" };`
);
await fs.outputFile(
path.join(pluginPath, "package.json"),
'{ "version": "0.0.1", "main":"info.js" }'
'{ "version": "0.0.1" }'
);
}
await writePlugin(testPlugin, "test");
await writePlugin(brokenPlugin, "broken");
await fs.outputFile(path.join(brokenPlugin, "info.js"), "Syntax Error");
await fs.outputFile(path.join(brokenPlugin, "index.js"), "Syntax Error");
await writePlugin(invalidPlugin, "wrong");
});
@@ -49,7 +49,7 @@ describe("lib/plugin_loader", function() {
let brokenMessage;
try {
// eslint-disable-next-line node/global-require
require(path.resolve(brokenPlugin, "info.js"));
require(path.resolve(brokenPlugin));
} catch (err) {
brokenMessage = err.message;
}