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",