From 7cef5528b308963e3a63eec632e4447f667c2f08 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Mon, 3 May 2021 21:38:23 +0200 Subject: [PATCH 1/7] Check for 0.16 startup string Adjust the regex for detecting startup to also work with 0.16 as updateTick was called mapTick before 0.17. Note: This commit does not imply 0.16 is going to be supported by Cluestio. --- packages/lib/factorio/server.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/lib/factorio/server.js b/packages/lib/factorio/server.js index 005727b7..9ba551d3 100644 --- a/packages/lib/factorio/server.js +++ b/packages/lib/factorio/server.js @@ -375,7 +375,7 @@ const outputHeuristics = [ // Message indicating the server is done starting up { - filter: { type: "log", message: /^updateTick\(\d+\) changing state from\(CreatingGame\) to\(InGame\)$/ }, + filter: { type: "log", message: /^(update|map)Tick\(\d+\) changing state from\(CreatingGame\) to\(InGame\)$/ }, action: function() { this._notifyGameReady().catch((err) => { this.emit("error", err); }); }, From 95b2262cc3b0663afb96f4b00dcfcc45f574f722 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Tue, 4 May 2021 14:10:13 +0200 Subject: [PATCH 2/7] Remove log rotation Remove log rotation as Factorio implemented its own log rotation an eternety ago and the cluster log already contains all the log entries. --- CHANGELOG.md | 1 + packages/slave/slave.js | 14 -------------- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 302db369..eba715c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -76,6 +76,7 @@ UPS statistics is exported by the statistics exporter plugin. - Master server now defaults to hosting on https on port 8443. - Renamed client to slave. +- Removed rotation of factorio-current.log files. ### Breaking Changes diff --git a/packages/slave/slave.js b/packages/slave/slave.js index 2ee280b2..aff5d472 100755 --- a/packages/slave/slave.js +++ b/packages/slave/slave.js @@ -384,20 +384,6 @@ class Instance extends libLink.Link { ); } - this.logger.verbose("Rotating old logs..."); - // clean old log file to avoid crash - try { - let logPath = this.path("factorio-current.log"); - let stat = await fs.stat(logPath); - if (stat.isFile()) { - let logFilename = `factorio-${Math.floor(Date.parse(stat.mtime)/1000)}.log`; - await fs.rename(logPath, this.path(logFilename)); - this.logger.verbose(`Log rotated as ${logFilename}`); - } - } catch (err) { - this.logger.error(`Error rotating logs:\n${err.stack}`); - } - // eslint-disable-next-line no-use-before-define await symlinkMods(this, "sharedMods"); } From b0067eccc6f7661dc5cdaa06b7d289354794a026 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Sat, 15 May 2021 21:34:29 +0200 Subject: [PATCH 3/7] Use node plugin for Eslint The Node.js specific rules for Eslint were deprecated in favour of the node plugin for Eslint. Add node plugin for eslint and switch over to using its rules, fixing any issues detected. --- .eslintrc.js | 93 +++++++++++++++++++++++--- package.json | 1 + packages/ctl/ctl.js | 2 +- packages/ctl/package.json | 1 + packages/lib/config/index.js | 8 ++- packages/lib/factorio/index.js | 11 +-- packages/lib/is_deep_strict_equal.js | 5 +- packages/lib/link/connectors.js | 2 +- packages/lib/link/index.js | 11 +-- packages/lib/plugin_loader.js | 2 +- packages/lib/shared_commands.js | 2 +- packages/master/.npmignore | 1 + packages/master/master.js | 4 +- packages/master/src/Master.js | 4 +- packages/slave/slave.js | 6 +- plugins/global_chat/.npmignore | 1 + plugins/player_auth/.npmignore | 1 + plugins/research_sync/.npmignore | 1 + plugins/statistics_exporter/.npmignore | 1 + plugins/subspace_storage/.npmignore | 1 + test/integration/index.js | 2 +- test/package.json | 8 +-- 22 files changed, 129 insertions(+), 39 deletions(-) create mode 100644 packages/master/.npmignore create mode 100644 plugins/global_chat/.npmignore create mode 100644 plugins/player_auth/.npmignore create mode 100644 plugins/research_sync/.npmignore create mode 100644 plugins/statistics_exporter/.npmignore create mode 100644 plugins/subspace_storage/.npmignore diff --git a/.eslintrc.js b/.eslintrc.js index 49d9ea77..3dfec3f3 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,5 +1,8 @@ "use strict"; module.exports = { + "plugins": [ + "node", + ], "env": { "node": true, "commonjs": true, @@ -18,6 +21,8 @@ module.exports = { "rules": { "prefer-arrow-callback": "off", "no-invalid-this": "off", + "node/no-unpublished-import": "off", + "node/no-unpublished-require": "off", }, }, { @@ -31,6 +36,44 @@ module.exports = { "jsx": true, }, }, + "rules": { + "node/callback-return": "off", + "node/exports-style": "off", + "node/file-extension-in-import": "off", + "node/global-require": "off", + "node/handle-callback-err": "off", + "node/no-callback-literal": "off", + "node/no-deprecated-api": "off", + "node/no-exports-assign": "off", + "node/no-extraneous-import": "off", + "node/no-extraneous-require": "off", + "node/no-missing-import": "off", + "node/no-missing-require": "off", + "node/no-mixed-requires": "off", + "node/no-new-require": "off", + "node/no-path-concat": "off", + "node/no-process-env": "off", + "node/no-process-exit": "off", + "node/no-restricted-require": "off", + "node/no-sync": "off", + "node/no-unpublished-bin": "off", + "node/no-unpublished-import": "off", + "node/no-unpublished-require": "off", + "node/no-unsupported-features/es-builtins": "off", + "node/no-unsupported-features/es-syntax": "off", + "node/no-unsupported-features/node-builtins": "off", + "node/prefer-global/buffer": "off", + "node/prefer-global/console": "off", + "node/prefer-global/process": "off", + "node/prefer-global/text-decoder": "off", + "node/prefer-global/text-encoder": "off", + "node/prefer-global/url-search-params": "off", + "node/prefer-global/url": "off", + "node/prefer-promises/dns": "off", + "node/prefer-promises/fs": "off", + "node/process-exit-as-throw": "off", + "node/shebang": "off", + }, }, ], @@ -46,7 +89,6 @@ module.exports = { "block-scoped-var": "error", "block-spacing": "error", "brace-style": ["error", "1tbs", { "allowSingleLine": true }], - "callback-return": "off", "camelcase": "off", "capitalized-comments": "off", "class-methods-use-this": "off", @@ -81,10 +123,8 @@ module.exports = { "function-call-argument-newline": "off", "function-paren-newline": "off", "generator-star-spacing": ["error", { "before": false, "after": true }], - "global-require": "error", "grouped-accessor-pairs": "error", "guard-for-in": "error", - "handle-callback-err": "error", "id-blacklist": "error", "id-length": "off", "id-match": "error", @@ -160,7 +200,6 @@ module.exports = { ], }, ], - "no-mixed-requires": "error", "no-multi-assign": "error", "no-multi-spaces": "error", "no-multi-str": "error", @@ -172,19 +211,14 @@ module.exports = { "no-new": "error", "no-new-func": "error", "no-new-object": "error", - "no-new-require": "error", "no-new-wrappers": "error", "no-octal-escape": "error", "no-param-reassign": "off", - "no-path-concat": "error", "no-plusplus": ["error", { "allowForLoopAfterthoughts": true }], - "no-process-env": "error", - "no-process-exit": "error", "no-proto": "error", "no-restricted-exports": "error", "no-restricted-globals": "error", "no-restricted-imports": "error", - "no-restricted-modules": "error", "no-restricted-properties": "error", "no-restricted-syntax": "error", "no-return-assign": "error", @@ -194,7 +228,6 @@ module.exports = { "no-sequences": "error", "no-shadow": ["error", { "allow": ["yargs"] }], "no-spaced-func": "error", - "no-sync": "error", "no-tabs": ["error", { "allowIndentationTabs": true }], "no-template-curly-in-string": "error", "no-ternary": "off", @@ -279,5 +312,45 @@ module.exports = { "wrap-regex": "off", "yield-star-spacing": "error", "yoda": ["error", "never", { "exceptRange": true }], + + "node/callback-return": "off", + "node/exports-style": "off", + "node/file-extension-in-import": "off", + "node/global-require": "error", + "node/handle-callback-err": "error", + "node/no-callback-literal": "error", + "node/no-deprecated-api": "error", + "node/no-exports-assign": "error", + "node/no-extraneous-import": "error", + "node/no-extraneous-require": "error", + "node/no-missing-import": "error", + "node/no-missing-require": "error", + "node/no-mixed-requires": "error", + "node/no-new-require": "error", + "node/no-path-concat": "error", + "node/no-process-env": "error", + "node/no-process-exit": "error", + "node/no-restricted-require": "off", + "node/no-sync": "error", + "node/no-unpublished-bin": "error", + "node/no-unpublished-import": "error", + "node/no-unpublished-require": [ + "error", + { "allowModules": ["webpack", "webpack-merge", "webpack-dev-middleware"] }, + ], + "node/no-unsupported-features/es-builtins": "error", + "node/no-unsupported-features/es-syntax": "error", + "node/no-unsupported-features/node-builtins": "error", + "node/prefer-global/buffer": "error", + "node/prefer-global/console": "error", + "node/prefer-global/process": "error", + "node/prefer-global/text-decoder": "error", + "node/prefer-global/text-encoder": "error", + "node/prefer-global/url-search-params": "error", + "node/prefer-global/url": "error", + "node/prefer-promises/dns": "off", + "node/prefer-promises/fs": "off", + "node/process-exit-as-throw": "error", + "node/shebang": "error", }, }; diff --git a/package.json b/package.json index c9395cc1..d4e94e05 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ }, "devDependencies": { "eslint": "^7.25.0", + "eslint-plugin-node": "^11.1.0", "jsdoc": "^3.6.6", "lerna": "^4.0.0", "mocha": "^8.4.0", diff --git a/packages/ctl/ctl.js b/packages/ctl/ctl.js index 693d29df..20243a75 100755 --- a/packages/ctl/ctl.js +++ b/packages/ctl/ctl.js @@ -962,7 +962,7 @@ async function startControl() { control.shutdown().catch(err => { setBlocking(true); logger.error(err.stack); - // eslint-disable-next-line no-process-exit + // eslint-disable-next-line node/no-process-exit process.exit(1); }); }); diff --git a/packages/ctl/package.json b/packages/ctl/package.json index 7d8bac3c..3de3307d 100644 --- a/packages/ctl/package.json +++ b/packages/ctl/package.json @@ -22,6 +22,7 @@ "as-table": "^1.0.31", "fs-extra": "^8.1.0", "phin": "^3.5.1", + "set-blocking": "^2.0.0", "winston": "^3.3.3", "yargs": "^14.2.0" }, diff --git a/packages/lib/config/index.js b/packages/lib/config/index.js index f95014ff..858c7712 100644 --- a/packages/lib/config/index.js +++ b/packages/lib/config/index.js @@ -1,11 +1,13 @@ -/* eslint-disable global-require */ /** * Configuration System * @author Hornwitser * @module lib/config */ "use strict"; +const classes = require("./classes"); +const definitions = require("./definitions"); + module.exports = { - ...require("./classes"), - ...require("./definitions"), + ...classes, + ...definitions, }; diff --git a/packages/lib/factorio/index.js b/packages/lib/factorio/index.js index 8fad79b5..5b296c99 100644 --- a/packages/lib/factorio/index.js +++ b/packages/lib/factorio/index.js @@ -1,12 +1,15 @@ -/* eslint-disable global-require */ /** * Library for interfacing with Factorio Servers and saves. * @module lib/factorio * @author Hornwitser */ "use strict"; +const export_ = require("./export"); +const patch = require("./patch"); +const server = require("./server"); + module.exports = { - ...require("./export"), - ...require("./patch"), - ...require("./server"), + ...export_, + ...patch, + ...server, }; diff --git a/packages/lib/is_deep_strict_equal.js b/packages/lib/is_deep_strict_equal.js index 3dae54dc..87e010d4 100644 --- a/packages/lib/is_deep_strict_equal.js +++ b/packages/lib/is_deep_strict_equal.js @@ -1,7 +1,8 @@ -/* eslint-disable global-require */ +/* eslint-disable node/global-require */ "use strict"; -// eslint-disable-next-line no-process-env +// eslint-disable-next-line node/no-process-env if (process.env.APP_ENV === "browser") { + // eslint-disable-next-line node/no-extraneous-require module.exports = require("fast-deep-equal/es6"); } else { module.exports = require("util").isDeepStrictEqual; diff --git a/packages/lib/link/connectors.js b/packages/lib/link/connectors.js index 8b797fbb..d7a4fd2f 100644 --- a/packages/lib/link/connectors.js +++ b/packages/lib/link/connectors.js @@ -249,7 +249,7 @@ class WebSocketClientConnector extends WebSocketBaseConnector { // Open WebSocket to master logger.verbose(`SOCKET | connecting to ${url}`); - // eslint-disable-next-line no-process-env + // eslint-disable-next-line node/no-process-env if (process.env.APP_ENV === "browser") { this._socket = new WebSocket(url); diff --git a/packages/lib/link/index.js b/packages/lib/link/index.js index 7a49b181..a156979c 100644 --- a/packages/lib/link/index.js +++ b/packages/lib/link/index.js @@ -1,12 +1,15 @@ -/* eslint-disable global-require */ /** * Library for message based communication between nodes * @module lib/link * @author Hornwitser */ "use strict"; +const link = require("./link"); +const messages = require("./messages"); +const connectors = require("./connectors"); + module.exports = { - ...require("./link"), - ...require("./messages"), - ...require("./connectors"), + ...link, + ...messages, + ...connectors, }; diff --git a/packages/lib/plugin_loader.js b/packages/lib/plugin_loader.js index b784776b..f06e332d 100644 --- a/packages/lib/plugin_loader.js +++ b/packages/lib/plugin_loader.js @@ -1,4 +1,4 @@ -/* eslint-disable global-require */ +/* eslint-disable node/global-require */ /** * Helpers for loading plugins in Node.js * @module lib/plugin_loader diff --git a/packages/lib/shared_commands.js b/packages/lib/shared_commands.js index 2cc378af..51155323 100644 --- a/packages/lib/shared_commands.js +++ b/packages/lib/shared_commands.js @@ -55,7 +55,7 @@ async function handlePluginCommand(args, pluginList, pluginListPath) { let pluginInfo; try { - // eslint-disable-next-line global-require + // eslint-disable-next-line node/global-require pluginInfo = require(path.posix.join(pluginPath, "info")); } catch (err) { logger.error(`Unable to import plugin info from ${args.path}:\n${err.stack}`); diff --git a/packages/master/.npmignore b/packages/master/.npmignore new file mode 100644 index 00000000..6de001d8 --- /dev/null +++ b/packages/master/.npmignore @@ -0,0 +1 @@ +webpack.config.js diff --git a/packages/master/master.js b/packages/master/master.js index 8c29a8a2..ce2bb4ee 100755 --- a/packages/master/master.js +++ b/packages/master/master.js @@ -322,7 +322,7 @@ async function startup() { if (secondSigint) { setBlocking(true); logger.fatal("Caught second interrupt, terminating immediately"); - // eslint-disable-next-line no-process-exit + // eslint-disable-next-line node/no-process-exit process.exit(1); } @@ -335,7 +335,7 @@ async function startup() { if (secondSigterm) { setBlocking(true); logger.fatal("Caught second termination, terminating immediately"); - // eslint-disable-next-line no-process-exit + // eslint-disable-next-line node/no-process-exit process.exit(1); } diff --git a/packages/master/src/Master.js b/packages/master/src/Master.js index b6741603..ccadbf3a 100644 --- a/packages/master/src/Master.js +++ b/packages/master/src/Master.js @@ -118,7 +118,7 @@ class Master { // Start webpack development server if enabled if (args.dev || args.devPlugin) { logger.warn("Webpack development mode enabled"); - /* eslint-disable global-require */ + /* eslint-disable node/global-require, node/no-unpublished-require */ const webpack = require("webpack"); const webpackDevMiddleware = require("webpack-dev-middleware"); const webpackConfigs = []; @@ -136,7 +136,7 @@ class Master { webpackConfigs.push(config); } } - /* eslint-enable global-require */ + /* eslint-enable node/global-require, node/no-unpublished-require */ const compiler = webpack(webpackConfigs); this.devMiddleware = webpackDevMiddleware(compiler, {}); diff --git a/packages/slave/slave.js b/packages/slave/slave.js index aff5d472..b8f36374 100755 --- a/packages/slave/slave.js +++ b/packages/slave/slave.js @@ -1413,7 +1413,7 @@ class Slave extends libLink.Link { +--------------------------------------------------------------------+ ${err.stack}` ); - // eslint-disable-next-line no-process-exit + // eslint-disable-next-line node/no-process-exit process.exit(1); } } @@ -1619,7 +1619,7 @@ async function startSlave() { if (secondSigint) { setBlocking(true); logger.fatal("Caught second interrupt, terminating immediately"); - // eslint-disable-next-line no-process-exit + // eslint-disable-next-line node/no-process-exit process.exit(1); } @@ -1632,7 +1632,7 @@ async function startSlave() { if (secondSigterm) { setBlocking(true); logger.fatal("Caught second termination, terminating immediately"); - // eslint-disable-next-line no-process-exit + // eslint-disable-next-line node/no-process-exit process.exit(1); } diff --git a/plugins/global_chat/.npmignore b/plugins/global_chat/.npmignore new file mode 100644 index 00000000..6de001d8 --- /dev/null +++ b/plugins/global_chat/.npmignore @@ -0,0 +1 @@ +webpack.config.js diff --git a/plugins/player_auth/.npmignore b/plugins/player_auth/.npmignore new file mode 100644 index 00000000..6de001d8 --- /dev/null +++ b/plugins/player_auth/.npmignore @@ -0,0 +1 @@ +webpack.config.js diff --git a/plugins/research_sync/.npmignore b/plugins/research_sync/.npmignore new file mode 100644 index 00000000..6de001d8 --- /dev/null +++ b/plugins/research_sync/.npmignore @@ -0,0 +1 @@ +webpack.config.js diff --git a/plugins/statistics_exporter/.npmignore b/plugins/statistics_exporter/.npmignore new file mode 100644 index 00000000..6de001d8 --- /dev/null +++ b/plugins/statistics_exporter/.npmignore @@ -0,0 +1 @@ +webpack.config.js diff --git a/plugins/subspace_storage/.npmignore b/plugins/subspace_storage/.npmignore new file mode 100644 index 00000000..6de001d8 --- /dev/null +++ b/plugins/subspace_storage/.npmignore @@ -0,0 +1 @@ +webpack.config.js diff --git a/test/integration/index.js b/test/integration/index.js index d15bb15e..3b4b6766 100644 --- a/test/integration/index.js +++ b/test/integration/index.js @@ -46,7 +46,7 @@ class TestControlConnector extends libLink.WebSocketClientConnector { // Mark that this test takes a lot of time, or depeneds on a test // that takes a lot of time. function slowTest(test) { - // eslint-disable-next-line no-process-env + // eslint-disable-next-line node/no-process-env if (process.env.FAST_TEST) { test.skip(); } diff --git a/test/package.json b/test/package.json index 1f11c8c9..205930a2 100644 --- a/test/package.json +++ b/test/package.json @@ -5,10 +5,10 @@ "node": ">=12" }, "dependencies": { - "@clusterio/ctl": "2.0.0-alpha.5", - "@clusterio/lib": "2.0.0-alpha.5", - "@clusterio/master": "2.0.0-alpha.5", - "@clusterio/slave": "2.0.0-alpha.5", + "@clusterio/ctl": "^2.0.0-alpha.6", + "@clusterio/lib": "^2.0.0-alpha.6", + "@clusterio/master": "^2.0.0-alpha.6", + "@clusterio/slave": "^2.0.0-alpha.6", "express": "^4.16.2", "fs-extra": "^8.1.0", "jsonwebtoken": "^8.2.1", From 0ae4fa0d2e79f1c3cfe1bad3f3a13a8cc727e5b8 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Sat, 15 May 2021 22:51:40 +0200 Subject: [PATCH 4/7] Create equipment grid when deserializing it Create equipment grid for items that support it and doesn't currently have a grid. Fixes deserialization of spidertron equipment grids. --- .../slave/modules/clusterio/serialize.lua | 37 ++++++++++++++++++- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/packages/slave/modules/clusterio/serialize.lua b/packages/slave/modules/clusterio/serialize.lua index ee247e63..434a7fd2 100644 --- a/packages/slave/modules/clusterio/serialize.lua +++ b/packages/slave/modules/clusterio/serialize.lua @@ -2,18 +2,44 @@ -- Based on code from playerManager and trainTeleports local serialize = {} +local function version_to_table(version) + local t = {} + for p in string.gmatch(version, "%d+") do + t[#t + 1] = tonumber(p) + end + return t +end + -- 0.17 compatibility -local supports_bar, get_bar, has_bar +local supports_bar, get_bar, has_bar, version if (pcall(function() local mods = script.active_mods end)) then supports_bar = "supports_bar" get_bar = "get_bar" set_bar = "set_bar" + version = version_to_table(script.active_mods.base) else supports_bar = "hasbar" get_bar = "getbar" set_bar = "setbar" + version = version_to_table("0.17.69") end +-- returns true if the game version is greater than or equal to the given version +local function version_ge(comp) + comp = version_to_table(comp) + for i=1, 3 do + if comp[i] > version[i] then + return false + elseif comp[i] < version[i] then + return true + end + end + return true +end + +local has_create_grid = version_ge("1.1.7") + + -- Equipment Grids are serialized into an array of equipment entries -- where ench entry is a table with the following fields: -- n: name @@ -173,7 +199,14 @@ function serialize.deserialize_item_stack(slot, entry) slot.allow_manual_label_change = label.a end if entry.g then - serialize.deserialize_equipment_grid(slot.grid, entry.g) + if slot.grid then + serialize.deserialize_equipment_grid(slot.grid, entry.g) + elseif slot.type == "item-with-entity-data" and has_create_grid then + slot.create_grid() + serialize.deserialize_equipment_grid(slot.grid, entry.g) + else + print("Error: Attempt to deserialize equipment grid on an unsupported entity") + end end if entry.i then local sub_inventory = slot.get_inventory(defines.inventory.item_main) From e94662350ab75bf9940bb18e918bf7a5aefc94a4 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Sat, 15 May 2021 22:54:13 +0200 Subject: [PATCH 5/7] Support symbolic links to modules Ignore files instead checking if the entry is a directory looking for modules to patch in. This is to support symbolic link to modules. --- packages/slave/slave.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/slave/slave.js b/packages/slave/slave.js index b8f36374..93f3eb79 100755 --- a/packages/slave/slave.js +++ b/packages/slave/slave.js @@ -453,7 +453,7 @@ class Instance extends libLink.Link { // Find stand alone modules to load // XXX for now only the included clusterio module is loaded for (let entry of await fs.readdir(path.join(__dirname, "modules"), { withFileTypes: true })) { - if (entry.isDirectory()) { + if (!entry.isFile()) { if (modules.has(entry.name)) { throw new Error(`Module with name ${entry.name} already exists in a plugin`); } From 4014eb4ec2096085879dcec0096e0017f58921a4 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Sat, 15 May 2021 23:19:18 +0200 Subject: [PATCH 6/7] Fix log query broken after refactor Add missing levels import from the logging library in ControlConnection.js. --- packages/master/src/ControlConnection.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/master/src/ControlConnection.js b/packages/master/src/ControlConnection.js index b640a005..a592a6ce 100644 --- a/packages/master/src/ControlConnection.js +++ b/packages/master/src/ControlConnection.js @@ -6,7 +6,7 @@ const winston = require("winston"); const libConfig = require("@clusterio/lib/config"); const libErrors = require("@clusterio/lib/errors"); const libLink = require("@clusterio/lib/link"); -const { logger } = require("@clusterio/lib/logging"); +const { levels, logger } = require("@clusterio/lib/logging"); const libLoggingUtils = require("@clusterio/lib/logging_utils"); const libPlugin = require("@clusterio/lib/plugin"); const libPrometheus = require("@clusterio/lib/prometheus"); From 19ebee4697556c569fa3018b938c6e74946b5319 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Sun, 16 May 2021 20:36:09 +0200 Subject: [PATCH 7/7] Remove PluginsContext The plugins are available as a property on the Control provided by the ControlContext which makes the PluginsContext redundant. Remove it and use ControlContext to retreive the plugin list in the app. --- packages/web_ui/src/bootstrap.jsx | 2 +- packages/web_ui/src/components/App.jsx | 9 +++------ packages/web_ui/src/components/LoginForm.jsx | 4 ++-- packages/web_ui/src/components/PluginViewPage.jsx | 4 ++-- packages/web_ui/src/components/PluginsPage.jsx | 4 ++-- packages/web_ui/src/components/SiteLayout.jsx | 4 ++-- packages/web_ui/src/index.jsx | 1 - 7 files changed, 12 insertions(+), 16 deletions(-) diff --git a/packages/web_ui/src/bootstrap.jsx b/packages/web_ui/src/bootstrap.jsx index 2de400dc..54bd091e 100644 --- a/packages/web_ui/src/bootstrap.jsx +++ b/packages/web_ui/src/bootstrap.jsx @@ -90,5 +90,5 @@ export default async function bootstrap() { controlConnector.setTimeout(15); let control = new Control(controlConnector, plugins); - ReactDOM.render(, document.getElementById("root")); + ReactDOM.render(, document.getElementById("root")); } diff --git a/packages/web_ui/src/components/App.jsx b/packages/web_ui/src/components/App.jsx index 085618d1..dd36eac4 100644 --- a/packages/web_ui/src/components/App.jsx +++ b/packages/web_ui/src/components/App.jsx @@ -7,7 +7,6 @@ import { logger } from "@clusterio/lib/logging"; import ErrorBoundary from "./ErrorBoundary"; import SiteLayout from "./SiteLayout"; import ControlContext from "./ControlContext"; -import PluginsContext from "./PluginsContext"; import LoginForm from "./LoginForm"; import { Card, Spin, Typography } from "antd"; @@ -95,11 +94,9 @@ export default function App(props) { return ( - - - {page} - - + + {page} + ); diff --git a/packages/web_ui/src/components/LoginForm.jsx b/packages/web_ui/src/components/LoginForm.jsx index 7e78b915..e44f2ecf 100644 --- a/packages/web_ui/src/components/LoginForm.jsx +++ b/packages/web_ui/src/components/LoginForm.jsx @@ -3,7 +3,7 @@ import { Button, Card, Divider, Form, Image, Input, List, Space, Spin, Typograph import LockOutlined from "@ant-design/icons/LockOutlined"; import logo from "../images/logo.png"; -import PluginsContext from "./PluginsContext"; +import ControlContext from "./ControlContext"; const { Paragraph, Text } = Typography; @@ -33,7 +33,7 @@ function TokenAuth(props) { } export default function LoginForm(props) { - let plugins = useContext(PluginsContext); + let plugins = useContext(ControlContext).plugins; let loginForms = []; for (let plugin of plugins.values()) { diff --git a/packages/web_ui/src/components/PluginViewPage.jsx b/packages/web_ui/src/components/PluginViewPage.jsx index 4ab2955f..f6ef29de 100644 --- a/packages/web_ui/src/components/PluginViewPage.jsx +++ b/packages/web_ui/src/components/PluginViewPage.jsx @@ -2,14 +2,14 @@ import React, { useEffect, useContext, useState } from "react"; import { useHistory, useParams } from "react-router-dom"; import { Alert, Descriptions, Spin } from "antd"; -import PluginsContext from "./PluginsContext"; +import ControlContext from "./ControlContext"; import PageLayout from "./PageLayout"; import { notifyErrorHandler } from "../util/notify"; export default function PluginViewPage() { let params = useParams(); - let plugins = useContext(PluginsContext); + let plugins = useContext(ControlContext).plugins; let [pluginList, setPluginList] = useState(null); let pluginName = params.name; diff --git a/packages/web_ui/src/components/PluginsPage.jsx b/packages/web_ui/src/components/PluginsPage.jsx index 6c9390f2..e93483bc 100644 --- a/packages/web_ui/src/components/PluginsPage.jsx +++ b/packages/web_ui/src/components/PluginsPage.jsx @@ -3,12 +3,12 @@ import { useHistory } from "react-router-dom"; import { Table } from "antd"; import notify from "../util/notify"; -import PluginsContext from "./PluginsContext"; +import ControlContext from "./ControlContext"; import PageLayout from "./PageLayout"; export default function PluginsPage() { - let plugins = useContext(PluginsContext); + let plugins = useContext(ControlContext).plugins; let history = useHistory(); let [pluginList, setPluginList] = useState([]); diff --git a/packages/web_ui/src/components/SiteLayout.jsx b/packages/web_ui/src/components/SiteLayout.jsx index eded71c2..843d3e6b 100644 --- a/packages/web_ui/src/components/SiteLayout.jsx +++ b/packages/web_ui/src/components/SiteLayout.jsx @@ -7,7 +7,7 @@ import webUiPackage from "../../package.json"; import { useAccount } from "../model/account"; import ErrorBoundary from "./ErrorBoundary"; import ErrorPage from "./ErrorPage"; -import PluginsContext from "./PluginsContext"; +import ControlContext from "./ControlContext"; import { pages } from "../pages"; const { Header, Sider } = Layout; @@ -17,7 +17,7 @@ export default function SiteLayout(props) { let history = useHistory(); let [currentSidebarPath, setCurrentSidebarPath] = useState(null); let account = useAccount(); - let plugins = useContext(PluginsContext); + let plugins = useContext(ControlContext).plugins; function SetSidebar(setSidebarProps) { useEffect(() => { diff --git a/packages/web_ui/src/index.jsx b/packages/web_ui/src/index.jsx index b411ddc0..2f783d08 100644 --- a/packages/web_ui/src/index.jsx +++ b/packages/web_ui/src/index.jsx @@ -8,7 +8,6 @@ export * from "./model/item_metadata.jsx"; export { default as ControlContext } from "./components/ControlContext"; -export { default as PluginsContext } from "./components/PluginsContext"; export { default as BaseConfigTree } from "./components/BaseConfigTree"; export { default as InstanceConfigTree } from "./components/InstanceConfigTree";