mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-13 23:14:53 +09:00
Fix plugin version not being loaded
Load the version of the plugin from its package.json file and document this requirement in the writing plugins document.
This commit is contained in:
1 parent
c5a14db8ea
commit
1b0b245484
3 files changed
+23
-9
No files matched your search
+15
-8
@@ -39,8 +39,21 @@ The basic file structure of a plugin is the following.
|
||||
+- module.json
|
||||
+- plugin.lua
|
||||
|
||||
The most important file is the `info.js` file. Without it the plugin
|
||||
will not recognized by Clusterio. Here's an example of it:
|
||||
Clusterio plugins are Node.js packages that can be published on npm for
|
||||
ease of installation and distribution. The usual guides for creating
|
||||
such packages apply. At minimum the `package.json` file must contain a
|
||||
version entry.
|
||||
|
||||
A possible workflow for developing plugins is to place the plugin in a
|
||||
sub-directory of where clusterio has been installed, and rely on Node.js
|
||||
searching up the folder heirarchy for it to find `@clusterio/lib`. To
|
||||
add it to `plugin-list.json` so that it gets loaded use the `plugin add
|
||||
<path>` sub-command to either clusteriomaster, clusterioslave or
|
||||
clusterioctl. Note that it's important that the path starts with ./ or
|
||||
../ (use .\ or ..\ on Windows).
|
||||
|
||||
For a plugin the most important file is the `info.js` file. Without it
|
||||
the plugin will not recognized by Clusterio. Here's an example of it:
|
||||
|
||||
const link = require('@clusterio/lib/link'); // For messages
|
||||
|
||||
@@ -48,7 +61,6 @@ will not recognized by Clusterio. Here's an example of it:
|
||||
name: "foo_frobber",
|
||||
title: "Foo Frobber",
|
||||
description: "Does advanced frobnication",
|
||||
version: "0.8.1",
|
||||
instanceEntrypoint: "instance",
|
||||
masterEntrypoint: "master",
|
||||
messages: {
|
||||
@@ -68,11 +80,6 @@ The following properties are recognized:
|
||||
**description**:
|
||||
Brief description of what the plugin does. Currently not used.
|
||||
|
||||
**version**:
|
||||
Semver compatible version string of the plugin. Currently only
|
||||
servers as the default for the Clusterio module embedded in the
|
||||
plugin, if any.
|
||||
|
||||
**instanceEntrypoint**:
|
||||
Path to a Node.js module relative to the plugin directory which
|
||||
contains the InstancePlugin class definition for this plugin. This
|
||||
|
||||
@@ -402,9 +402,11 @@ async function loadPluginInfos(pluginList) {
|
||||
let plugins = [];
|
||||
for (let [pluginName, pluginPath] of pluginList) {
|
||||
let pluginInfo;
|
||||
let pluginPackage;
|
||||
|
||||
try {
|
||||
pluginInfo = require(path.posix.join(pluginPath, "info"));
|
||||
pluginPackage = require(path.posix.join(pluginPath, "package.json"));
|
||||
|
||||
} catch (err) {
|
||||
throw new errors.PluginError(pluginName, err);
|
||||
@@ -417,6 +419,7 @@ async function loadPluginInfos(pluginList) {
|
||||
}
|
||||
|
||||
pluginInfo.requirePath = pluginPath;
|
||||
pluginInfo.version = pluginPackage.version;
|
||||
plugins.push(pluginInfo);
|
||||
}
|
||||
return plugins;
|
||||
|
||||
+5
-1
@@ -54,6 +54,10 @@ describe("lib/plugin", function() {
|
||||
path.join(pluginPath, "info.js"),
|
||||
`module.exports = { name: "${infoName}" };`
|
||||
);
|
||||
await fs.outputFile(
|
||||
path.join(pluginPath, "package.json"),
|
||||
'{ "version": "0.0.1" }'
|
||||
);
|
||||
}
|
||||
|
||||
await writePlugin(testPlugin, "test");
|
||||
@@ -71,7 +75,7 @@ describe("lib/plugin", function() {
|
||||
it("should load test plugin", async function() {
|
||||
assert.deepEqual(
|
||||
await plugin.loadPluginInfos(new Map([["test", path.resolve(testPlugin)]])),
|
||||
[{ name: "test", requirePath: path.resolve(testPlugin) }]
|
||||
[{ name: "test", version: "0.0.1", requirePath: path.resolve(testPlugin) }]
|
||||
);
|
||||
});
|
||||
it("should reject on broken plugin", async function() {
|
||||
|
||||
Reference in new issue
Block a user