mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-15 15:24:52 +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,6 @@
|
||||
import { CommandTree, Command } from "@clusterio/lib";
|
||||
import { BaseCtlPlugin } from "@clusterio/ctl";
|
||||
import { ChatEvent } from "./messages";
|
||||
import { ChatEvent } from "./messages.js";
|
||||
|
||||
const globalChatCommands = new CommandTree({
|
||||
name: "global-chat", description: "Global Chat plugin commands",
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import type * as lib from "@clusterio/lib";
|
||||
|
||||
import { ChatEvent } from "./messages";
|
||||
import { ChatEvent } from "./messages.js";
|
||||
|
||||
export const plugin: lib.PluginDeclaration = {
|
||||
name: "global_chat",
|
||||
title: "Global Chat",
|
||||
description: "Forwards chat between instances.",
|
||||
instanceEntrypoint: "dist/node/instance",
|
||||
ctlEntrypoint: "dist/node/control",
|
||||
instanceEntrypoint: "dist/node/instance.js",
|
||||
ctlEntrypoint: "dist/node/control.js",
|
||||
|
||||
features: [
|
||||
"ScriptCommands",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as lib from "@clusterio/lib";
|
||||
import { BaseInstancePlugin } from "@clusterio/host";
|
||||
import { ChatEvent } from "./messages";
|
||||
import { ChatEvent } from "./messages.js";
|
||||
|
||||
/**
|
||||
* Removes server-specific tags from messages.
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
"access": "public"
|
||||
},
|
||||
|
||||
"type": "module",
|
||||
"main": "dist/node/index.js",
|
||||
"scripts": {
|
||||
"prepare": "tsc --build && webpack-cli --mode production",
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
"use strict";
|
||||
const assert = require("assert").strict;
|
||||
const lib = require("@clusterio/lib");
|
||||
|
||||
const mock = require("../../../test/mock");
|
||||
const lines = require("../../../test/lib/factorio/lines");
|
||||
const instance = require("../dist/node/instance");
|
||||
const info = require("../dist/node/index").plugin;
|
||||
const { ChatEvent } = require("../dist/node/messages");
|
||||
import assert from "node:assert/strict";
|
||||
|
||||
import * as mock from "../../../test/mock.js";
|
||||
import * as lines from "../../../test/lib/factorio/lines.js";
|
||||
import * as instance from "../dist/node/instance.js";
|
||||
import { plugin as info } from "../dist/node/index.js";
|
||||
import { ChatEvent } from "../dist/node/messages.js";
|
||||
|
||||
describe("global_chat plugin", function() {
|
||||
describe("removeTags()", function() {
|
||||
|
||||
File renamed without changes.
@@ -1,10 +1,10 @@
|
||||
import { BaseControllerPlugin, type InstanceRecord } from "@clusterio/controller";
|
||||
import type { IpcPlayerData } from "./messages";
|
||||
import type { IpcPlayerData } from "./messages.js";
|
||||
|
||||
import fs from "node:fs/promises";
|
||||
import path from "path";
|
||||
import * as lib from "@clusterio/lib";
|
||||
import * as msg from "./messages";
|
||||
import * as msg from "./messages.js";
|
||||
|
||||
async function loadDatabase(config: lib.ControllerConfig, logger: lib.Logger) {
|
||||
let itemsPath = path.resolve(config.get("controller.database_directory"), "inventories.json");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import * as lib from "@clusterio/lib";
|
||||
import * as messages from "./messages";
|
||||
import * as messages from "./messages.js";
|
||||
|
||||
declare module "@clusterio/lib" {
|
||||
export interface InstanceConfigFields {
|
||||
@@ -22,7 +22,7 @@ export const plugin: lib.PluginDeclaration = {
|
||||
title: "Inventory sync",
|
||||
description: "Synchronizes players inventories between instances",
|
||||
|
||||
instanceEntrypoint: "dist/node/instance",
|
||||
instanceEntrypoint: "dist/node/instance.js",
|
||||
instanceConfigFields: {
|
||||
"inventory_sync.rcon_chunk_size": {
|
||||
title: "Rcon inventory chunk size",
|
||||
@@ -33,7 +33,7 @@ export const plugin: lib.PluginDeclaration = {
|
||||
},
|
||||
},
|
||||
|
||||
controllerEntrypoint: "dist/node/controller",
|
||||
controllerEntrypoint: "dist/node/controller.js",
|
||||
controllerConfigFields: {
|
||||
"inventory_sync.player_lock_timeout": {
|
||||
title: "Player Lock Timeout",
|
||||
|
||||
@@ -2,7 +2,7 @@ import * as lib from "@clusterio/lib";
|
||||
import { BaseInstancePlugin } from "@clusterio/host";
|
||||
import {
|
||||
AcquireRequest, AcquireResponse, ReleaseRequest, UploadRequest, DownloadRequest, DownloadResponse, IpcPlayerData,
|
||||
} from "./messages";
|
||||
} from "./messages.js";
|
||||
|
||||
type IpcPlayerName = {
|
||||
player_name: string
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
"access": "public"
|
||||
},
|
||||
|
||||
"type": "module",
|
||||
"main": "dist/node/index.js",
|
||||
"scripts": {
|
||||
"prepare": "tsc --build && webpack-cli --mode production",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import React, { useContext, useEffect, useState } from "react";
|
||||
|
||||
import { BaseWebPlugin, PageLayout, PageHeader, ControlContext } from "@clusterio/web_ui";
|
||||
import { DatabaseStatsRequest, DatabaseStatsResponse } from "../messages";
|
||||
import { DatabaseStatsRequest, DatabaseStatsResponse } from "../messages.js";
|
||||
|
||||
import "./style.css";
|
||||
|
||||
|
||||
File renamed without changes.
@@ -4,11 +4,10 @@ import util from "util";
|
||||
import jwt from "jsonwebtoken";
|
||||
|
||||
import { Static } from "@sinclair/typebox";
|
||||
import * as lib from "@clusterio/lib";
|
||||
import { BaseControllerPlugin } from "@clusterio/controller";
|
||||
const { basicType } = lib;
|
||||
import { basicType, RequestError } from "@clusterio/lib";
|
||||
|
||||
import { FetchPlayerCodeRequest, PlayerAuthServer, SetVerifyCodeRequest } from "./messages";
|
||||
import { FetchPlayerCodeRequest, PlayerAuthServer, SetVerifyCodeRequest } from "./messages.js";
|
||||
|
||||
|
||||
async function generateCode(length: number): Promise<string> {
|
||||
@@ -207,7 +206,7 @@ export class ControllerPlugin extends BaseControllerPlugin {
|
||||
|
||||
let entry = this.players.get(player);
|
||||
if (!entry || entry.expiresMs < Date.now()) {
|
||||
throw new lib.RequestError("invalid player");
|
||||
throw new RequestError("invalid player");
|
||||
}
|
||||
|
||||
entry.verifyCode = verifyCode;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import * as lib from "@clusterio/lib";
|
||||
import * as messages from "./messages";
|
||||
import * as messages from "./messages.js";
|
||||
|
||||
declare module "@clusterio/lib" {
|
||||
export interface InstanceConfigFields {
|
||||
@@ -16,8 +16,8 @@ export const plugin: lib.PluginDeclaration = {
|
||||
name: "player_auth",
|
||||
title: "Player Auth",
|
||||
description: "Provides authentication to the cluster via logging into a Factorio server.",
|
||||
controllerEntrypoint: "dist/node/controller",
|
||||
instanceEntrypoint: "dist/node/instance",
|
||||
controllerEntrypoint: "dist/node/controller.js",
|
||||
instanceEntrypoint: "dist/node/instance.js",
|
||||
webEntrypoint: "./web",
|
||||
controllerConfigFields: {
|
||||
"player_auth.code_length": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { BaseInstancePlugin } from "@clusterio/host";
|
||||
|
||||
import { FetchPlayerCodeRequest, SetVerifyCodeRequest } from "./messages";
|
||||
import { FetchPlayerCodeRequest, SetVerifyCodeRequest } from "./messages.js";
|
||||
|
||||
type IpcPlayerAuth = {
|
||||
type: "open_dialog",
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
"access": "public"
|
||||
},
|
||||
|
||||
"type": "module",
|
||||
"main": "dist/node/index.js",
|
||||
"scripts": {
|
||||
"prepare": "tsc --build && webpack-cli --mode production",
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
"use strict";
|
||||
const assert = require("assert").strict;
|
||||
const jwt = require("jsonwebtoken");
|
||||
import assert from "node:assert/strict";
|
||||
import jwt from "jsonwebtoken";
|
||||
|
||||
const mock = require("../../../test/mock");
|
||||
import * as mock from "../../../test/mock.js";
|
||||
|
||||
const controller = require("../dist/node/controller");
|
||||
const instance = require("../dist/node/instance");
|
||||
const info = require("../dist/node/index").plugin;
|
||||
const { FetchPlayerCodeRequest, SetVerifyCodeRequest, PlayerAuthServer } = require("../dist/node/messages");
|
||||
const { testRoundTripJsonSerialisable, testMatrix } = require("../../../test/common");
|
||||
const lib = require("@clusterio/lib");
|
||||
import * as controller from "../dist/node/controller.js";
|
||||
import * as instance from "../dist/node/instance.js";
|
||||
import { plugin as info } from "../dist/node/index.js";
|
||||
import { FetchPlayerCodeRequest, SetVerifyCodeRequest, PlayerAuthServer } from "../dist/node/messages.js";
|
||||
import { testRoundTripJsonSerialisable, testMatrix } from "../../../test/common.js";
|
||||
import * as lib from "@clusterio/lib";
|
||||
|
||||
|
||||
function postJSON(url, body) {
|
||||
|
||||
@@ -3,7 +3,7 @@ import React, { useEffect, useState } from "react";
|
||||
import { BaseWebPlugin, notifyErrorHandler } from "@clusterio/web_ui";
|
||||
import { Alert, Button, Form, Input, Modal, Space, Spin, Typography } from "antd";
|
||||
|
||||
import { PlayerAuthServer } from "../messages";
|
||||
import { PlayerAuthServer } from "../messages.js";
|
||||
import "./style.css";
|
||||
|
||||
const { Paragraph, Text } = Typography;
|
||||
|
||||
File renamed without changes.
@@ -4,7 +4,7 @@ import { BaseControllerPlugin } from "@clusterio/controller";
|
||||
import { Static } from "@sinclair/typebox";
|
||||
|
||||
import * as lib from "@clusterio/lib";
|
||||
const { RateLimiter } = lib;
|
||||
import { RateLimiter } from "@clusterio/lib";
|
||||
|
||||
import {
|
||||
ContributionEvent,
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
TechnologySync,
|
||||
SyncTechnologiesRequest,
|
||||
TechnologyProgress,
|
||||
} from "./messages";
|
||||
} from "./messages.js";
|
||||
|
||||
type Technology = {
|
||||
level: number,
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import type * as lib from "@clusterio/lib";
|
||||
|
||||
import * as messages from "./messages";
|
||||
import * as messages from "./messages.js";
|
||||
|
||||
export const plugin: lib.PluginDeclaration = {
|
||||
name: "research_sync",
|
||||
title: "Research Sync",
|
||||
description: "Synchronises technology research progress between instances.",
|
||||
instanceEntrypoint: "dist/node/instance",
|
||||
controllerEntrypoint: "dist/node/controller",
|
||||
instanceEntrypoint: "dist/node/instance.js",
|
||||
controllerEntrypoint: "dist/node/controller.js",
|
||||
|
||||
features: [
|
||||
"SavePatching",
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
FinishedEvent,
|
||||
TechnologySync,
|
||||
SyncTechnologiesRequest,
|
||||
} from "./messages";
|
||||
} from "./messages.js";
|
||||
|
||||
// ./module/sync.lua
|
||||
type IpcContribution = {
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
"access": "public"
|
||||
},
|
||||
|
||||
"type": "module",
|
||||
"main": "dist/node/index.js",
|
||||
"scripts": {
|
||||
"prepare": "tsc --build && webpack-cli --mode production",
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
// These are libraries that does not have any units test, they are
|
||||
// required here in order to track coverage for them.
|
||||
|
||||
"use strict";
|
||||
require("../dist/node/instance");
|
||||
require("../dist/node/controller");
|
||||
import "../dist/node/instance.js";
|
||||
import "../dist/node/controller.js";
|
||||
File renamed without changes.
@@ -12,7 +12,7 @@ export const plugin: lib.PluginDeclaration = {
|
||||
description:
|
||||
"Provides in-game item/fluid production, builds, kills, and pollution "+
|
||||
"statistics to the cluster's Prometheus endpoint.",
|
||||
instanceEntrypoint: "dist/node/instance",
|
||||
instanceEntrypoint: "dist/node/instance.js",
|
||||
instanceConfigFields: {
|
||||
"statistics_exporter.command_timeout": {
|
||||
title: "Command Timeout",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import * as lib from "@clusterio/lib";
|
||||
import { BaseInstancePlugin } from "@clusterio/host";
|
||||
|
||||
const { Gauge } = lib;
|
||||
import { Gauge } from "@clusterio/lib";
|
||||
|
||||
type IpcStats = {
|
||||
game_tick: number,
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
"access": "public"
|
||||
},
|
||||
|
||||
"type": "module",
|
||||
"main": "dist/node/index.js",
|
||||
"scripts": {
|
||||
"prepare": "tsc --build && webpack-cli --mode production",
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
"use strict";
|
||||
const assert = require("assert").strict;
|
||||
import assert from "node:assert/strict";
|
||||
|
||||
const mock = require("../../../test/mock");
|
||||
const instance = require("../dist/node/instance");
|
||||
const info = require("../dist/node/index").plugin;
|
||||
import * as mock from "../../../test/mock.js";
|
||||
import * as instance from "../dist/node/instance.js";
|
||||
import { plugin as info } from "../dist/node/index.js";
|
||||
|
||||
|
||||
describe("statistics_exporter plugin", function() {
|
||||
|
||||
File renamed without changes.
@@ -4,10 +4,10 @@ import fs from "node:fs/promises";
|
||||
import path from "path";
|
||||
|
||||
import * as lib from "@clusterio/lib";
|
||||
const { Counter, Gauge } = lib;
|
||||
import { Counter, Gauge } from "@clusterio/lib";
|
||||
|
||||
import * as routes from "./routes";
|
||||
import * as dole from "./dole";
|
||||
import * as routes from "./routes.js";
|
||||
import * as dole from "./dole.js";
|
||||
|
||||
import {
|
||||
Item,
|
||||
@@ -16,7 +16,7 @@ import {
|
||||
GetStorageRequest,
|
||||
UpdateStorageEvent,
|
||||
SetStorageSubscriptionRequest,
|
||||
} from "./messages";
|
||||
} from "./messages.js";
|
||||
|
||||
|
||||
const exportCounter = new Counter(
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import * as doleNN from "./dole_nn_base";
|
||||
import * as doleNN from "./dole_nn_base.js";
|
||||
|
||||
import * as lib from "@clusterio/lib";
|
||||
const { Gauge } = lib;
|
||||
import { Gauge } from "@clusterio/lib";
|
||||
|
||||
|
||||
const prometheusNNDoleGauge = new Gauge(
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import * as lib from "@clusterio/lib";
|
||||
import * as messages from "./messages";
|
||||
import * as messages from "./messages.js";
|
||||
|
||||
declare module "@clusterio/lib" {
|
||||
export interface ControllerConfigFields {
|
||||
@@ -22,7 +22,7 @@ export const plugin: lib.PluginDeclaration = {
|
||||
name: "subspace_storage",
|
||||
title: "Subspace Storage",
|
||||
description: "Provides shared storage across instances for the Subspace Storage mod",
|
||||
instanceEntrypoint: "dist/node/instance",
|
||||
instanceEntrypoint: "dist/node/instance.js",
|
||||
instanceConfigFields: {
|
||||
"subspace_storage.log_item_transfers": {
|
||||
title: "Log Item Transfers",
|
||||
@@ -32,7 +32,7 @@ export const plugin: lib.PluginDeclaration = {
|
||||
},
|
||||
},
|
||||
|
||||
controllerEntrypoint: "dist/node/controller",
|
||||
controllerEntrypoint: "dist/node/controller.js",
|
||||
controllerConfigFields: {
|
||||
"subspace_storage.division_method": {
|
||||
title: "Division Method",
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
GetStorageRequest,
|
||||
UpdateStorageEvent,
|
||||
Item,
|
||||
} from "./messages";
|
||||
} from "./messages.js";
|
||||
|
||||
type IpcItems = [name: string, count: number, quality: string][];
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
"access": "public"
|
||||
},
|
||||
|
||||
"type": "module",
|
||||
"main": "dist/node/index.js",
|
||||
"scripts": {
|
||||
"prepare": "tsc --build && webpack-cli --mode production",
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
// These are libraries that does not have any units test, they are
|
||||
// required here in order to track coverage for them.
|
||||
|
||||
"use strict";
|
||||
require("../dist/node/instance");
|
||||
require("../dist/node/controller");
|
||||
require("../dist/node/dole");
|
||||
require("../dist/node/dole_nn_base");
|
||||
import "../dist/node/instance.js";
|
||||
import "../dist/node/controller.js";
|
||||
import "../dist/node/dole.js";
|
||||
import "../dist/node/dole_nn_base.js";
|
||||
@@ -1,8 +1,7 @@
|
||||
"use strict";
|
||||
const assert = require("assert").strict;
|
||||
import assert from "node:assert/strict";
|
||||
|
||||
const routes = require("../dist/node/routes");
|
||||
const { get } = require("../../../test/integration");
|
||||
import * as routes from "../dist/node/routes.js";
|
||||
import { get } from "../../../test/integration/index.js";
|
||||
|
||||
|
||||
describe("subspace_storage endpoints", function() {
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
useExportLocale, useExportPrototypeMetadata, useDefaultModPack, FactorioIcon,
|
||||
useTableQueryState, useColumnSearch,
|
||||
} from "@clusterio/web_ui";
|
||||
import { GetStorageRequest, Item, SetStorageSubscriptionRequest, UpdateStorageEvent } from "../messages";
|
||||
import { GetStorageRequest, Item, SetStorageSubscriptionRequest, UpdateStorageEvent } from "../messages.js";
|
||||
|
||||
import "./style.css";
|
||||
|
||||
|
||||
File renamed without changes.
Reference in new issue
Block a user