mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-13 23:14:53 +09:00
Migrate to ECMAScript Modules
Migrate the usage of CommonJS specific code and imports to ESM. Roughly summarised this: - Changes all require() calls to import statement or expressions. - Changes usage of module.exports to export statements. - Replaces require.resolve with import.meta.resolve. - Replaces conditional imports with conditional subpath imports. - Replaces module === require.main with import.meta.main. - Adds the full filename with extention to all relative imports. - Changes all usage of __dirname and __filename to their import.meta equivalents. - Sets "type": "module" in package.json files. - Removes usage of "use strict". - Adds .ts an an alias of .js for the webpack build. Due to differences in how require and import resolves files the plugin entrypoints will have to include the filename and extension after this migration in order to work.
This commit is contained in:
1 parent
b69111dda3
commit
5dcaca4d0b
261 files changed
+1115
-1330
No files matched your search
@@ -1,6 +1,5 @@
|
||||
"use strict";
|
||||
const mock = require("../mock");
|
||||
const controller = require("@clusterio/controller");
|
||||
import * as mock from "../mock.js";
|
||||
import * as controller from "@clusterio/controller";
|
||||
|
||||
describe("controller/src/BaseControllerPlugin", function() {
|
||||
describe("class BaseControllerPlugin", function() {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
"use strict";
|
||||
const assert = require("assert").strict;
|
||||
const { ControlConnection } = require("@clusterio/controller");
|
||||
import assert from "node:assert/strict";
|
||||
import { ControlConnection } from "@clusterio/controller";
|
||||
|
||||
describe("controller/src/ControlConnection", function() {
|
||||
describe(".handleControllerRestartRequest()", function() {
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
"use strict";
|
||||
const path = require("node:path");
|
||||
const assert = require("assert").strict;
|
||||
const { Controller, HostRecord, InstanceRecord, UserRecord } = require("@clusterio/controller");
|
||||
const { EventEmitter } = require("stream");
|
||||
const events = require("node:events");
|
||||
const http = require("node:http");
|
||||
const express = require("express");
|
||||
import path from "node:path";
|
||||
import assert from "node:assert/strict";
|
||||
import { Controller, HostRecord, InstanceRecord, UserRecord } from "@clusterio/controller";
|
||||
import events, { EventEmitter } from "node:events";
|
||||
import http from "node:http";
|
||||
import express from "express";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
const {
|
||||
import {
|
||||
ControllerConfig, Address, RequestError,
|
||||
InstanceConfig, SystemInfo, Role, ModPack,
|
||||
addPluginConfigFields,
|
||||
} = require("@clusterio/lib");
|
||||
} from "@clusterio/lib";
|
||||
|
||||
class MockEvent {}
|
||||
|
||||
@@ -33,10 +32,12 @@ class MockInstanceConfig extends EventEmitter {
|
||||
}
|
||||
|
||||
describe("controller/src/Controller", function() {
|
||||
describe("class Controller", function() {
|
||||
describe("class Controller", async function() {
|
||||
/** @type {Controller} */
|
||||
let controller, mockInstanceConfig;
|
||||
const controllerVersion = require("@clusterio/controller/package.json").version;
|
||||
const controllerVersion = (
|
||||
await import("@clusterio/controller/package.json", { with: { type: "json" }})
|
||||
).default.version;
|
||||
before(async function() {
|
||||
const controllerConfig = new ControllerConfig("controller", { "controller.version": controllerVersion });
|
||||
controller = new Controller({}, [], controllerConfig);
|
||||
@@ -245,7 +246,7 @@ describe("controller/src/Controller", function() {
|
||||
controller.config.restartRequired = false;
|
||||
controller.pluginInfos[0] = {
|
||||
name: "restart_test",
|
||||
packagePath: require.resolve("@clusterio/controller/package.json"),
|
||||
packagePath: fileURLToPath(import.meta.resolve("@clusterio/controller/package.json")),
|
||||
version: controllerVersion,
|
||||
};
|
||||
});
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"use strict";
|
||||
const assert = require("assert").strict;
|
||||
const lib = require("@clusterio/lib");
|
||||
const { User } = require("@clusterio/controller");
|
||||
import assert from "node:assert/strict";
|
||||
import * as lib from "@clusterio/lib";
|
||||
import { User } from "@clusterio/controller";
|
||||
|
||||
describe("controller/src/User", function() {
|
||||
describe("class User", function() {
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
"use strict";
|
||||
const assert = require("assert").strict;
|
||||
const { HostDetails } = require("@clusterio/lib");
|
||||
const { HostRecord } = require("@clusterio/controller");
|
||||
import assert from "node:assert/strict";
|
||||
import { HostDetails } from "@clusterio/lib";
|
||||
import { HostRecord } from "@clusterio/controller";
|
||||
|
||||
const { testMatrix, testRoundTripJsonSerialisable } = require("../common");
|
||||
import { testMatrix, testRoundTripJsonSerialisable } from "../common.js";
|
||||
|
||||
describe("controller/HostRecord", function () {
|
||||
const samplePlugins = new Map([
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
"use strict";
|
||||
const assert = require("assert").strict;
|
||||
const fs = require("node:fs/promises");
|
||||
const http = require("http");
|
||||
const https = require("https");
|
||||
const util = require("util");
|
||||
const events = require("node:events");
|
||||
import assert from "node:assert/strict";
|
||||
import fs from "node:fs/promises";
|
||||
import http from "node:http";
|
||||
import https from "node:https";
|
||||
import util from "node:util";
|
||||
import events from "node:events";
|
||||
|
||||
const HttpCloser = require("@clusterio/controller/dist/node/src/HttpCloser").default;
|
||||
import HttpCloser from "@clusterio/controller/dist/node/src/HttpCloser.js";
|
||||
|
||||
// Time to wait during async operations to ensure they happened in order.
|
||||
const tick = 20;
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
"use strict";
|
||||
const assert = require("assert").strict;
|
||||
const lib = require("@clusterio/lib");
|
||||
import assert from "node:assert/strict";
|
||||
import * as lib from "@clusterio/lib";
|
||||
|
||||
const { Controller, InstanceRecord, InstanceManager } = require("@clusterio/controller");
|
||||
import { Controller, InstanceRecord, InstanceManager } from "@clusterio/controller";
|
||||
|
||||
describe("controller/InstanceManager", function () {
|
||||
/** @type {Controller} */
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
"use strict";
|
||||
const assert = require("assert").strict;
|
||||
const lib = require("@clusterio/lib");
|
||||
const { InstanceRecord } = require("@clusterio/controller");
|
||||
import assert from "node:assert/strict";
|
||||
import * as lib from "@clusterio/lib";
|
||||
import { InstanceRecord } from "@clusterio/controller";
|
||||
|
||||
const { testMatrix, testRoundTripJsonSerialisable } = require("../common");
|
||||
import { testMatrix, testRoundTripJsonSerialisable } from "../common.js";
|
||||
|
||||
describe("controller/InstanceRecord", function () {
|
||||
/** @type {lib.InstanceConfig} */
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"use strict";
|
||||
const assert = require("assert").strict;
|
||||
const { Role, SubscribableDatastore } = require("@clusterio/lib");
|
||||
const { User } = require("@clusterio/controller");
|
||||
import assert from "node:assert/strict";
|
||||
import { Role, SubscribableDatastore } from "@clusterio/lib";
|
||||
import { User } from "@clusterio/controller";
|
||||
|
||||
describe("controller/User", function () {
|
||||
/** @type {SubscribableDatastore<UserRecord>} */
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
"use strict";
|
||||
const path = require("path");
|
||||
const fs = require("node:fs/promises");
|
||||
const assert = require("assert").strict;
|
||||
const jwt = require("jsonwebtoken");
|
||||
const { Role, SubscribableDatastore, ControllerConfig } = require("@clusterio/lib");
|
||||
const { UserRecord, UserManager } = require("@clusterio/controller");
|
||||
import path from "node:path";
|
||||
import fs from "node:fs/promises";
|
||||
import assert from "node:assert/strict";
|
||||
import jwt from "jsonwebtoken";
|
||||
import { Role, SubscribableDatastore, ControllerConfig } from "@clusterio/lib";
|
||||
import { UserRecord, UserManager } from "@clusterio/controller";
|
||||
|
||||
const TEMP_DIR = path.join("temp", "test", "UserManager");
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
"use strict";
|
||||
const assert = require("assert").strict;
|
||||
const { UserDetails, PlayerStats } = require("@clusterio/lib");
|
||||
const { UserRecord } = require("@clusterio/controller");
|
||||
import assert from "node:assert/strict";
|
||||
import { UserDetails, PlayerStats } from "@clusterio/lib";
|
||||
import { UserRecord } from "@clusterio/controller";
|
||||
|
||||
const { testMatrix, testRoundTripJsonSerialisable } = require("../common");
|
||||
import { testMatrix, testRoundTripJsonSerialisable } from "../common.js";
|
||||
|
||||
describe("controller/UserRecord", function () {
|
||||
it("should be round trip serialisable", function () {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"use strict";
|
||||
const assert = require("assert").strict;
|
||||
const { Controller, WsServer } = require("@clusterio/controller");
|
||||
const { ControllerConfig } = require("@clusterio/lib");
|
||||
import assert from "node:assert/strict";
|
||||
import { Controller, WsServer } from "@clusterio/controller";
|
||||
import { ControllerConfig } from "@clusterio/lib";
|
||||
|
||||
describe("controller/src/WsServer", function() {
|
||||
describe("class WsServer", function() {
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
"use strict";
|
||||
const assert = require("assert").strict;
|
||||
const events = require("events");
|
||||
const FormData = require("form-data");
|
||||
const http = require("http");
|
||||
import assert from "node:assert/strict";
|
||||
import events from "node:events";
|
||||
import FormData from "form-data";
|
||||
import http from "node:http";
|
||||
|
||||
const { wait } = require("@clusterio/lib");
|
||||
const routes = require("@clusterio/controller/dist/node/src/routes");
|
||||
const mock = require("../mock");
|
||||
import { wait } from "@clusterio/lib";
|
||||
import * as routes from "@clusterio/controller/dist/node/src/routes.js";
|
||||
import * as mock from "../mock.js";
|
||||
|
||||
describe("controller/src/routes", function() {
|
||||
let controller;
|
||||
|
||||
Reference in new issue
Block a user