diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 9a0508f6..cb033ec7 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -28,17 +28,33 @@ jobs: strategy: fail-fast: false matrix: - # Test Node.js 24 and 26 across the Factorio matrix; Node.js 22 runs coverage below. + # To stay within the concurrent job limit, every Factorio version is + # tested on the latest Node.js, and every other supported Node.js + # version only with the latest Factorio. Coverage is performed on the + # oldest supported Node.js. # Node.js release schedule: https://nodejs.org/en/about/releases/ - node-version: [24.x, 26.x] - - # Supported factorio versions are latest stable and one minor version before stable (even if from a previous major) + # Supported factorio versions are latest stable and one minor version before stable (even if from a previous major) + node-version: [26.x] factorio-version: [1.1.110, 2.0.77, 2.1.17] - - # Coverage is performed on the older of the supported node versions + + # The tests run in two halves of similar length on separate runners, + # the clusterioctl, plugin system and instance integration tests and the rest. + tests: [ctl, other] + include: + - node-version: 24.x + factorio-version: 2.1.17 + tests: ctl + - node-version: 24.x + factorio-version: 2.1.17 + tests: other - node-version: 22.x factorio-version: 2.1.17 + tests: ctl + coverage: true + - node-version: 22.x + factorio-version: 2.1.17 + tests: other coverage: true steps: @@ -51,10 +67,10 @@ jobs: run: wget -q -O factorio.tar.gz https://www.factorio.com/get-download/${{ matrix.factorio-version }}/headless/linux64 && tar -xf factorio.tar.gz && rm factorio.tar.gz - name: Run tests if: ${{ !matrix.coverage }} - run: pnpm test + run: pnpm test --grep "^(Integration of Clusterio (clusterioctl|plugin system)|Clusterio Instance) " ${{ matrix.tests == 'other' && '--invert' || '' }} - name: Run coverage if: ${{ matrix.coverage }} - run: pnpm run ci-cover + run: pnpm run ci-cover --grep "^(Integration of Clusterio (clusterioctl|plugin system)|Clusterio Instance) " ${{ matrix.tests == 'other' && '--invert' || '' }} - name: Upload coverage to Codecov if: ${{ matrix.coverage }} uses: codecov/codecov-action@v7 @@ -67,7 +83,7 @@ jobs: if: ${{ !cancelled() }} uses: actions/upload-artifact@v7 with: - name: logs-${{ matrix.node-version }}-${{ matrix.factorio-version }} + name: logs-${{ matrix.node-version }}-${{ matrix.factorio-version }}-${{ matrix.tests }} path: temp/test/logs version-compat: diff --git a/docs/contributing.md b/docs/contributing.md index 5a9adfdb..a206de81 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -339,7 +339,8 @@ The format of this log should be self explanatory, please follow it carefully. P For development, use the latest Node.js LTS release, following the [installation instructions](../README.md#installation). Make sure the Node.js built-in APIs and npm packages you use remain compatible with the supported versions. -The GitHub Actions tests currently run on Node.js 24 and 26 across the Factorio matrix, with Node.js 22 used for coverage; see the [CI workflow](../.github/workflows/node.js.yml) for the version matrix. +The GitHub Actions tests run every Factorio version on the latest Node.js, and every other supported Node.js version with the latest Factorio only, which keeps the number of jobs within GitHub's concurrent job limit. +Coverage is collected on the oldest supported Node.js; see the [CI workflow](../.github/workflows/node.js.yml) for the version matrix. For Factorio, active support covers the latest stable version and the previous major version, using version lines such as 2.1, 2.0 and 1.1 as described in the [Factorio support policy](decisions.md#factorio). Older versions from 0.17 onwards receive passive support where it does not restrict actively supported versions. diff --git a/package.json b/package.json index 8ae0c1d4..47f86fa3 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ ] }, "engines": { - "node": ">=22" + "node": "^22.18.0 || >=24.2.0" }, "workspaces": [ "packages/*", diff --git a/packages/controller/controller.ts b/packages/controller/controller.ts index c21ecb94..e2cdb06a 100644 --- a/packages/controller/controller.ts +++ b/packages/controller/controller.ts @@ -25,10 +25,12 @@ import DailyRotateFile from "winston-daily-rotate-file"; // homebrew modules +// Reduce startup time by lazy compiling schemas. +import "./src/set_lazy_schema_compilation.js"; import * as lib from "@clusterio/lib"; import { ConsoleTransport, levels, logger } from "@clusterio/lib"; -import Controller from "./src/Controller.js"; +import type Controller from "./src/Controller.js"; import UserManager from "./src/UserManager.js"; import UserRecord from "./src/UserRecord.js"; import packageConfig from "@clusterio/controller/package.json" with { type: "json" }; @@ -194,6 +196,7 @@ async function handleBootstrapCommand( } let ctlConfig = new lib.CtlConfig("control"); + const { default: Controller } = await import("./src/Controller.js"); ctlConfig.set("ctl.controller_url", Controller.calculateControllerUrl(controllerConfig)); ctlConfig.set( "ctl.controller_token", @@ -463,6 +466,8 @@ async function startup() { return; } + // Loaded here as the server is not needed by the other commands + const { default: Controller } = await import("./src/Controller.js"); controller = await Controller.fromConfig( controllerConfig, pluginInfos, diff --git a/packages/controller/package.json b/packages/controller/package.json index e968acbd..0d144cc1 100644 --- a/packages/controller/package.json +++ b/packages/controller/package.json @@ -32,7 +32,7 @@ "clusteriocontroller": "./dist/node/controller.js" }, "engines": { - "node": ">=22" + "node": "^22.18.0 || >=24.2.0" }, "dependencies": { diff --git a/packages/controller/src/set_lazy_schema_compilation.ts b/packages/controller/src/set_lazy_schema_compilation.ts new file mode 100644 index 00000000..f5ff3418 --- /dev/null +++ b/packages/controller/src/set_lazy_schema_compilation.ts @@ -0,0 +1,3 @@ +// This needs to be a separate file due to ECMAScript Modules evaluating code in +// imported modules before any code in the file that imports it. +(global as any).lazySchemaCompilation = true; diff --git a/packages/create/package.json b/packages/create/package.json index 00b6e754..ba34a393 100644 --- a/packages/create/package.json +++ b/packages/create/package.json @@ -28,7 +28,7 @@ "clusteriocreate": "./create.js" }, "engines": { - "node": ">=22" + "node": "^22.18.0 || >=24.2.0" }, "dependencies": { diff --git a/packages/ctl/package.json b/packages/ctl/package.json index 48930727..914839ca 100644 --- a/packages/ctl/package.json +++ b/packages/ctl/package.json @@ -32,7 +32,7 @@ "clusterioctl": "./dist/node/ctl.js" }, "engines": { - "node": ">=22" + "node": "^22.18.0 || >=24.2.0" }, "dependencies": { diff --git a/packages/host/host.ts b/packages/host/host.ts index a718fc42..d72d692b 100755 --- a/packages/host/host.ts +++ b/packages/host/host.ts @@ -20,10 +20,12 @@ import winston from "winston"; import "winston-daily-rotate-file"; // internal libraries +// Reduce startup time by lazy compiling schemas. +import "./src/set_lazy_schema_compilation.js"; import * as lib from "@clusterio/lib"; import { ConsoleTransport, levels, logger } from "@clusterio/lib"; -import Host from "./src/Host.js"; +import type Host from "./src/Host.js"; import { createScenarioCommand, handleCreateScenarioCommand } from "./src/create_scenario.js"; import { PairingError, ensurePaired } from "./src/pairing.js"; @@ -254,6 +256,8 @@ async function startHost() { } } + // Loaded here as the server is not needed by the other commands + const { default: Host } = await import("./src/Host.js"); let hostConnector = new HostConnector(hostConfig, pluginInfos); host = await Host.fromConfig( hostConfig, diff --git a/packages/host/package.json b/packages/host/package.json index b552445f..26d1f9fe 100644 --- a/packages/host/package.json +++ b/packages/host/package.json @@ -33,7 +33,7 @@ "clusteriohost": "./dist/node/host.js" }, "engines": { - "node": ">=22" + "node": "^22.18.0 || >=24.2.0" }, "dependencies": { diff --git a/packages/host/src/set_lazy_schema_compilation.ts b/packages/host/src/set_lazy_schema_compilation.ts new file mode 100644 index 00000000..f5ff3418 --- /dev/null +++ b/packages/host/src/set_lazy_schema_compilation.ts @@ -0,0 +1,3 @@ +// This needs to be a separate file due to ECMAScript Modules evaluating code in +// imported modules before any code in the file that imports it. +(global as any).lazySchemaCompilation = true; diff --git a/packages/lib/package.json b/packages/lib/package.json index b38ab998..88d3a177 100644 --- a/packages/lib/package.json +++ b/packages/lib/package.json @@ -46,7 +46,7 @@ "compile_validator": "node scripts/compile_validator.js" }, "engines": { - "node": ">=22" + "node": "^22.18.0 || >=24.2.0" }, "dependencies": { diff --git a/packages/web_ui/package.json b/packages/web_ui/package.json index 13c6551d..3aa99c7a 100644 --- a/packages/web_ui/package.json +++ b/packages/web_ui/package.json @@ -29,7 +29,7 @@ "test": "echo \"Error: no test specified\" && exit 1" }, "engines": { - "node": ">=22" + "node": "^22.18.0 || >=24.2.0" }, "dependencies": { diff --git a/plugins/global_chat/package.json b/plugins/global_chat/package.json index eda028c1..fb58ed99 100644 --- a/plugins/global_chat/package.json +++ b/plugins/global_chat/package.json @@ -30,7 +30,7 @@ "test": "echo \"Error: run tests from root\" && exit 1" }, "engines": { - "node": ">=22" + "node": "^22.18.0 || >=24.2.0" }, "peerDependencies": { diff --git a/plugins/player_auth/package.json b/plugins/player_auth/package.json index e3bde80e..24028e8f 100644 --- a/plugins/player_auth/package.json +++ b/plugins/player_auth/package.json @@ -30,7 +30,7 @@ "test": "echo \"Error: run tests from root\" && exit 1" }, "engines": { - "node": ">=22" + "node": "^22.18.0 || >=24.2.0" }, "peerDependencies": { diff --git a/plugins/player_sync/package.json b/plugins/player_sync/package.json index 6836b0ce..68bcdbc4 100644 --- a/plugins/player_sync/package.json +++ b/plugins/player_sync/package.json @@ -30,7 +30,7 @@ "test": "echo \"Error: run tests from root\" && exit 1" }, "engines": { - "node": ">=22" + "node": "^22.18.0 || >=24.2.0" }, "peerDependencies": { diff --git a/plugins/research_sync/package.json b/plugins/research_sync/package.json index 19df29e0..c409a5f5 100644 --- a/plugins/research_sync/package.json +++ b/plugins/research_sync/package.json @@ -30,7 +30,7 @@ "test": "echo \"Error: run tests from root\" && exit 1" }, "engines": { - "node": ">=22" + "node": "^22.18.0 || >=24.2.0" }, "peerDependencies": { diff --git a/plugins/statistics_exporter/package.json b/plugins/statistics_exporter/package.json index b46f9958..0f9d78ad 100644 --- a/plugins/statistics_exporter/package.json +++ b/plugins/statistics_exporter/package.json @@ -30,7 +30,7 @@ "test": "echo \"Error: run tests from root\" && exit 1" }, "engines": { - "node": ">=22" + "node": "^22.18.0 || >=24.2.0" }, "peerDependencies": { diff --git a/plugins/subspace_storage/package.json b/plugins/subspace_storage/package.json index ee5f47d5..2b3e5de6 100644 --- a/plugins/subspace_storage/package.json +++ b/plugins/subspace_storage/package.json @@ -30,7 +30,7 @@ "test": "echo \"Error: run tests from root\" && exit 1" }, "engines": { - "node": ">=22" + "node": "^22.18.0 || >=24.2.0" }, "peerDependencies": { diff --git a/test/integration/index.js b/test/integration/index.js index c28b9a7e..e29d96a2 100644 --- a/test/integration/index.js +++ b/test/integration/index.js @@ -217,17 +217,17 @@ export function exec(command, options = {}) { } export function execController(...args) { - args[0] = `node --enable-source-maps ../../packages/controller ${args[0]}`; + args[0] = `node --enable-source-maps ../../packages/controller/dist/node/controller.js ${args[0]}`; return exec(...args); } export function execHost(...args) { - args[0] = `node --enable-source-maps ../../packages/host ${args[0]}`; + args[0] = `node --enable-source-maps ../../packages/host/dist/node/host.js ${args[0]}`; return exec(...args); } export function execCtlProcess(...args) { - args[0] = `node --enable-source-maps ../../packages/ctl ${args[0]}`; + args[0] = `node --enable-source-maps ../../packages/ctl/dist/node/ctl.js ${args[0]}`; return exec(...args); } diff --git a/test/integration/link.js b/test/integration/link.js index 012d545d..20404542 100644 --- a/test/integration/link.js +++ b/test/integration/link.js @@ -169,7 +169,9 @@ describe("Integration of lib/link", function() { it("should close old connections from the same address", async function() { slowTest(this); - const hostConnectorFirst = new TestHostConnector(url, 0.2); + // Without a link the disconnect prepare goes unanswered and the controller waits 10 s for it + const hostLinkFirst = new lib.Link(new TestHostConnector(url, 0.2)); + const hostConnectorFirst = hostLinkFirst.connector; hostConnectorFirst.token = hostConnector.token; hostConnectorFirst.hostId = hostConnector.hostId; const onceClose = events.once(hostConnectorFirst, "close");