mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-16 23:30:41 +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,8 +1,6 @@
|
||||
"use strict";
|
||||
const assert = require("assert").strict;
|
||||
const mock = require("../mock");
|
||||
import * as mock from "../mock.js";
|
||||
|
||||
const host = require("@clusterio/host");
|
||||
import * as host from "@clusterio/host";
|
||||
|
||||
describe("host/src/BaseHostPlugin", function() {
|
||||
describe("class BaseHostPlugin", function() {
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
"use strict";
|
||||
const assert = require("assert").strict;
|
||||
const mock = require("../mock");
|
||||
import assert from "node:assert/strict";
|
||||
import * as mock from "../mock.js";
|
||||
|
||||
const host = require("@clusterio/host");
|
||||
import * as host from "@clusterio/host";
|
||||
|
||||
describe("host/src/BaseInstancePlugin", function() {
|
||||
describe("class BaseInstancePlugin", function() {
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
"use strict";
|
||||
const assert = require("assert").strict;
|
||||
const path = require("path");
|
||||
import assert from "node:assert/strict";
|
||||
import path from "node:path";
|
||||
|
||||
const lib = require("@clusterio/lib");
|
||||
const { PlayerStats, wait } = lib;
|
||||
const Instance = require("@clusterio/host/dist/node/src/Instance").default;
|
||||
const { MockConnector, MockServer } = require("../mock");
|
||||
import * as lib from "@clusterio/lib";
|
||||
import { PlayerStats, wait } from "@clusterio/lib";
|
||||
import Instance from "@clusterio/host/dist/node/src/Instance.js";
|
||||
import { MockConnector, MockServer } from "../mock.js";
|
||||
|
||||
const addr = lib.Address.fromShorthand;
|
||||
|
||||
|
||||
+4
-5
@@ -1,9 +1,8 @@
|
||||
"use strict";
|
||||
const assert = require("assert").strict;
|
||||
const path = require("path");
|
||||
import assert from "node:assert/strict";
|
||||
import path from "node:path";
|
||||
|
||||
const { FactorioServer } = require("@clusterio/host/dist/node/src/server");
|
||||
const { _exportLocale } = require("@clusterio/host/dist/node/src/export");
|
||||
import { FactorioServer } from "@clusterio/host/dist/node/src/server.js";
|
||||
import { _exportLocale } from "@clusterio/host/dist/node/src/export.js";
|
||||
|
||||
|
||||
describe("host/src/export", function() {
|
||||
|
||||
+6
-7
@@ -1,11 +1,10 @@
|
||||
"use strict";
|
||||
const assert = require("assert").strict;
|
||||
const fs = require("node:fs/promises");
|
||||
const JSZip = require("jszip");
|
||||
const path = require("path");
|
||||
import assert from "node:assert/strict";
|
||||
import fs from "node:fs/promises";
|
||||
import JSZip from "jszip";
|
||||
import path from "node:path";
|
||||
|
||||
const lib = require("@clusterio/lib");
|
||||
const patch = require("@clusterio/host/dist/node/src/patch");
|
||||
import * as lib from "@clusterio/lib";
|
||||
import * as patch from "@clusterio/host/dist/node/src/patch.js";
|
||||
|
||||
|
||||
describe("host/patch", function() {
|
||||
|
||||
+9
-11
@@ -1,14 +1,12 @@
|
||||
"use strict";
|
||||
const assert = require("assert").strict;
|
||||
const events = require("events");
|
||||
const fs = require("node:fs/promises");
|
||||
const path = require("path");
|
||||
import assert from "node:assert/strict";
|
||||
import events from "node:events";
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
|
||||
const hostServer = require("@clusterio/host/dist/node/src/server");
|
||||
const lib = require("@clusterio/lib");
|
||||
const { wait } = lib;
|
||||
const { testLines } = require("../lib/factorio/lines");
|
||||
const { slowTest, externalTest } = require("../integration");
|
||||
import * as hostServer from "@clusterio/host/dist/node/src/server.js";
|
||||
import { Link, wait } from "@clusterio/lib";
|
||||
import { testLines } from "../lib/factorio/lines.js";
|
||||
import { slowTest, externalTest } from "../integration/index.js";
|
||||
|
||||
|
||||
describe("host/server", function() {
|
||||
@@ -326,7 +324,7 @@ describe("host/server", function() {
|
||||
static jsonSchema = { type: "number" };
|
||||
static fromJSON(json) { return new this(json); }
|
||||
}
|
||||
let eventFromJSON = lib.Link.eventFromJSON(NumberEvent, "NumberEvent");
|
||||
let eventFromJSON = Link.eventFromJSON(NumberEvent, "NumberEvent");
|
||||
ipcServer.handle("bad_event", async () => { eventFromJSON("not a number"); });
|
||||
ipcServer.emit("ipc-bad_event", {});
|
||||
await new Promise(resolve => setImmediate(resolve));
|
||||
|
||||
Reference in new issue
Block a user