From 02f8cd7639b8a51ad19c4f3b9c0f403e3c5a735e Mon Sep 17 00:00:00 2001 From: hengwuming Date: Sun, 5 Apr 2026 12:38:57 +0800 Subject: [PATCH] fix(server): use fs-extra default import compat Issue: #75 Reason: - mrpack deployment could fail under ESM with "fs.readFile is not a function" - importing fs-extra via is not reliable in this runtime Changes: - add a shared fs-extra compatibility wrapper - switch mrpack and related deployment modules to use the wrapper Refs: #75 --- server/src/modules/game/othergame/factorio-deployer.ts | 4 ++-- server/src/modules/game/othergame/minecraft-server-api.ts | 4 ++-- server/src/modules/game/othergame/mrpack-server-api.ts | 4 ++-- server/src/modules/game/othergame/unified-functions.ts | 4 ++-- server/src/utils/fsExtraCompat.ts | 4 ++++ 5 files changed, 12 insertions(+), 8 deletions(-) create mode 100644 server/src/utils/fsExtraCompat.ts diff --git a/server/src/modules/game/othergame/factorio-deployer.ts b/server/src/modules/game/othergame/factorio-deployer.ts index f6c310d..2aba805 100644 --- a/server/src/modules/game/othergame/factorio-deployer.ts +++ b/server/src/modules/game/othergame/factorio-deployer.ts @@ -1,6 +1,6 @@ import axios from 'axios'; import express, { Request, Response } from 'express'; -import * as fs from 'fs-extra'; +import fs from '../../../utils/fsExtraCompat.js'; import { promises as fsPromises, existsSync } from 'fs'; import { createWriteStream, createReadStream } from 'fs'; import * as path from 'path'; @@ -1061,4 +1061,4 @@ export class FactorioDeployer { return null; } } -} \ No newline at end of file +} diff --git a/server/src/modules/game/othergame/minecraft-server-api.ts b/server/src/modules/game/othergame/minecraft-server-api.ts index c10117c..474fab0 100644 --- a/server/src/modules/game/othergame/minecraft-server-api.ts +++ b/server/src/modules/game/othergame/minecraft-server-api.ts @@ -1,5 +1,5 @@ import axios from 'axios'; -import * as fs from 'fs-extra'; +import fs from '../../../utils/fsExtraCompat.js'; import { promises as fsPromises, existsSync, readdirSync } from 'fs'; import { createWriteStream } from 'fs'; import * as path from 'path'; @@ -1240,4 +1240,4 @@ export async function validateJavaEnvironment(): Promise { } // 默认导出主类 -export default MinecraftServerDownloader; \ No newline at end of file +export default MinecraftServerDownloader; diff --git a/server/src/modules/game/othergame/mrpack-server-api.ts b/server/src/modules/game/othergame/mrpack-server-api.ts index 331a1b9..23d59b9 100644 --- a/server/src/modules/game/othergame/mrpack-server-api.ts +++ b/server/src/modules/game/othergame/mrpack-server-api.ts @@ -1,5 +1,5 @@ import axios from 'axios'; -import * as fs from 'fs-extra'; +import fs from '../../../utils/fsExtraCompat.js'; import { promises as fsPromises, existsSync, readdirSync } from 'fs'; import { createWriteStream } from 'fs'; import * as path from 'path'; @@ -1024,4 +1024,4 @@ export class MrpackServerAPI { // ==================== 导出 ==================== -export default MrpackServerAPI; \ No newline at end of file +export default MrpackServerAPI; diff --git a/server/src/modules/game/othergame/unified-functions.ts b/server/src/modules/game/othergame/unified-functions.ts index 9401e0d..78e6700 100644 --- a/server/src/modules/game/othergame/unified-functions.ts +++ b/server/src/modules/game/othergame/unified-functions.ts @@ -3,7 +3,7 @@ // 移除所有API相关代码,专注于核心功能 import axios from 'axios'; -import * as fs from 'fs-extra'; +import fs from '../../../utils/fsExtraCompat.js'; import { createWriteStream, mkdtemp } from 'fs'; import { promises as fsPromises } from 'fs'; import * as path from 'path'; @@ -2056,4 +2056,4 @@ export async function deployBedrockServer(options: BedrockDeployOptions): Promis } // 默认导出统一部署函数 -export default deployGameServer; \ No newline at end of file +export default deployGameServer; diff --git a/server/src/utils/fsExtraCompat.ts b/server/src/utils/fsExtraCompat.ts new file mode 100644 index 0000000..3a9e203 --- /dev/null +++ b/server/src/utils/fsExtraCompat.ts @@ -0,0 +1,4 @@ +import fsExtra from 'fs-extra' + +export { fsExtra } +export default fsExtra