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
@@ -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.
Reference in new issue
Block a user