From 723f8db572ee8fc2757665649ce8e060cba868e5 Mon Sep 17 00:00:00 2001 From: TheSparta Date: Sat, 14 Oct 2023 09:01:41 +0000 Subject: [PATCH] Updated dependencies + A few other things (!150) Initially this was going to be an update to dependencies but it seems i got a little carried away! Anyways this PR removes 2 unused dependencies (`jshint` and `utf-8-validate`), and 2 other, `del` and `fs-extra` that were replaced by the built-in `fs/promises`. It also renames all `tsconfig` and `Dockerfile` files, in a way that when viewed in a file tree sorted alphabetically they will be next to each other. It also updates the typescript target to `ES2022`, and changes moduleResolution from `Node` to `Node10` (this isn't an update, they are the same thing but `Node` is now deprecated). It also adds the `node:` discriminator to every import from built-in modules. It also has major changes to the build script, `del` and `fs-extra` were only being used in the build script, it's now using `fs/promises` instead, cleaned up the code from some functions, adds better documentation to a few functions, and renames some gulp tasks and npm scripts to better represent what they actually do. And finally it updates dependencies, except for `atomically` which can't be updated unless the project switches to ESM. Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/150 Co-authored-by: TheSparta Co-committed-by: TheSparta --- .drone.yml | 2 +- LICENSE.md | 2 +- project/.dockerignore | 2 +- project/.swcrc | 4 +- project/Dockerfile | 2 +- project/{docs.Dockerfile => Dockerfile.docs} | 0 project/{pnpm.Dockerfile => Dockerfile.pnpm} | 0 project/gulpfile.mjs | 274 ++++++++---------- project/package.json | 59 ++-- project/rome.json | 4 +- project/src/controllers/GameController.ts | 2 - project/src/di/Serializer.ts | 2 +- project/src/loaders/PreAkiModLoader.ts | 6 +- project/src/models/external/HttpFramework.ts | 2 +- project/src/routers/HttpRouter.ts | 2 +- project/src/routers/ImageRouter.ts | 2 +- .../routers/serializers/BundleSerializer.ts | 2 +- .../routers/serializers/ImageSerializer.ts | 2 +- .../routers/serializers/NotifySerializer.ts | 2 +- project/src/servers/HttpServer.ts | 2 +- project/src/servers/WebSocketServer.ts | 2 +- project/src/servers/http/AkiHttpListener.ts | 4 +- project/src/servers/http/IHttpListener.ts | 2 +- project/src/services/LocalisationService.ts | 2 +- project/src/services/ModCompilerService.ts | 9 +- .../mod/httpListener/HttpListenerMod.ts | 2 +- .../httpListener/HttpListenerModService.ts | 2 +- project/src/utils/App.ts | 8 +- project/src/utils/HashUtil.ts | 2 +- project/src/utils/HttpFileUtil.ts | 4 +- project/src/utils/ObjectId.ts | 2 +- project/src/utils/VFS.ts | 6 +- project/src/utils/Watermark.ts | 29 +- .../utils/logging/AbstractWinstonLogger.ts | 4 +- ...{base_tsconfig.json => tsconfig.base.json} | 11 +- project/tsconfig.json | 6 +- ...{test_tsconfig.json => tsconfig.test.json} | 4 +- ...ef_tsconfig.json => tsconfig.typedef.json} | 4 +- 38 files changed, 223 insertions(+), 253 deletions(-) rename project/{docs.Dockerfile => Dockerfile.docs} (100%) rename project/{pnpm.Dockerfile => Dockerfile.pnpm} (100%) rename project/{base_tsconfig.json => tsconfig.base.json} (70%) rename project/{test_tsconfig.json => tsconfig.test.json} (83%) rename project/{typedef_tsconfig.json => tsconfig.typedef.json} (81%) diff --git a/.drone.yml b/.drone.yml index 67a1728b..9f063bce 100644 --- a/.drone.yml +++ b/.drone.yml @@ -181,7 +181,7 @@ steps: from_secret: DOCKER_PASSWORD username: from_secret: DOCKER_USERNAME - dockerfile: project/docs.Dockerfile + dockerfile: project/Dockerfile.docs context: project/ tags: latest depends_on: diff --git a/LICENSE.md b/LICENSE.md index 5e79ced9..125d5225 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,4 +1,4 @@ -# NCSA Open Source License +# NCSA Open Source License Copyright (c) 2022 Merijn Hendriks. All rights reserved. diff --git a/project/.dockerignore b/project/.dockerignore index d2142a81..67ddc146 100644 --- a/project/.dockerignore +++ b/project/.dockerignore @@ -2,7 +2,7 @@ !src !types -!base_tsconfig.json +!tsconfig.base.json !tsconfig.json !package.json !typedoc.json \ No newline at end of file diff --git a/project/.swcrc b/project/.swcrc index 583be9f0..b1e2021a 100644 --- a/project/.swcrc +++ b/project/.swcrc @@ -9,7 +9,7 @@ "transform": { "decoratorMetadata": true }, - "target": "es2020", + "target": "es2022", "loose": true, "externalHelpers": false, // Requires v1.2.50 or upper and requires target to be es2016 or upper. @@ -27,4 +27,4 @@ }, "sourceMaps":true, "minify": false -} \ No newline at end of file +} diff --git a/project/Dockerfile b/project/Dockerfile index 5d0d9446..7ce530d0 100644 --- a/project/Dockerfile +++ b/project/Dockerfile @@ -5,7 +5,7 @@ WORKDIR /app COPY package.json . RUN yarn -COPY .parcelrc tsconfig.json base_tsconfig.json ./ +COPY .parcelrc tsconfig.json tsconfig.base.json ./ COPY src ./src RUN yarn test:comp-linux diff --git a/project/docs.Dockerfile b/project/Dockerfile.docs similarity index 100% rename from project/docs.Dockerfile rename to project/Dockerfile.docs diff --git a/project/pnpm.Dockerfile b/project/Dockerfile.pnpm similarity index 100% rename from project/pnpm.Dockerfile rename to project/Dockerfile.pnpm diff --git a/project/gulpfile.mjs b/project/gulpfile.mjs index 3e0cf5d2..7a3acba2 100644 --- a/project/gulpfile.mjs +++ b/project/gulpfile.mjs @@ -1,13 +1,12 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import crypto from "crypto"; -import { deleteSync } from "del"; -import fs from "fs-extra"; import gulp from "gulp"; import { exec } from "gulp-execa"; import rename from "gulp-rename"; -import os from "os"; -import path from "path"; +import crypto from "node:crypto"; +import fs from "node:fs/promises"; +import os from "node:os"; +import path from "node:path"; import pkg from "pkg"; import pkgfetch from "pkg-fetch"; import * as ResEdit from "resedit"; @@ -27,8 +26,15 @@ const entries = { }; const licenseFile = "../LICENSE.md"; -// Compilation -const compileTest = async () => exec("swc src -d obj", { stdio }); +/** + * Transpiles the src files into javascript with swc + */ +const compile = async () => await exec("swc src -d obj", { stdio }); + +/** + * Transpiles the src files into javascript with tsc for the profiler run + */ +const compileProfiler = async () => await exec("tsc -p tsconfig.test.json", { stdio }); // Packaging const fetchPackageImage = async () => @@ -40,38 +46,26 @@ const fetchPackageImage = async () => console.log(`fetched node binary at ${fetchedPkg}`); const builtPkg = fetchedPkg.replace("node", "built"); await fs.copyFile(fetchedPkg, builtPkg); - if (process.platform === "win32" || process.platform === "win64") - { - await exec(`dir ${output}`, { - stdio - }); - } - else - { - await exec(`ls ${output}`, { - stdio - }); - } } - catch (e) + catch (e) { console.error(`Error while fetching and patching package image: ${e.message}`); console.error(e.stack); } }; -const updateBuildProperties = async (cb) => +const updateBuildProperties = async () => { - if(os.platform() !== "win32") { - cb(); + if (os.platform() !== "win32") + { return; } - const exe = ResEdit.NtExecutable.from(fs.readFileSync(serverExe)); + const exe = ResEdit.NtExecutable.from(await fs.readFile(serverExe)); const res = ResEdit.NtExecutableResource.from(exe); - + const iconPath = path.resolve(manifest.icon); - const iconFile = ResEdit.Data.IconFile.from(fs.readFileSync(iconPath)); + const iconFile = ResEdit.Data.IconFile.from(await fs.readFile(iconPath)); ResEdit.Resource.IconGroupEntry.replaceIconsForResource( res.entries, @@ -97,104 +91,93 @@ const updateBuildProperties = async (cb) => vi.setProductVersion(...manifest.version.split(".").map(Number)); vi.outputToResourceEntries(res.entries); res.outputResource(exe, true); - fs.writeFileSync(serverExe, Buffer.from(exe.generate())); - - cb(); + await fs.writeFile(serverExe, Buffer.from(exe.generate())); }; -// Copy various asset files to the destination directory -function copyAssets() -{ - return gulp.src(["assets/**/*.json", "assets/**/*.json5", "assets/**/*.png", "assets/**/*.jpg", "assets/**/*.ico"]) - .pipe(gulp.dest(dataDir)); -} +/** + * Copy various asset files to the destination directory + */ +const copyAssets = () => gulp.src(["assets/**/*.json", "assets/**/*.json5", "assets/**/*.png", "assets/**/*.jpg", "assets/**/*.ico"]).pipe(gulp.dest(dataDir)); -// Copy executables from node_modules -function copyExecutables() -{ - return gulp.src(["node_modules/@pnpm/exe/**/*"]) - .pipe(gulp.dest(path.join(dataDir, "@pnpm", "exe"))); -} +/** + * Copy executables from node_modules + */ +const copyExecutables = () => gulp.src(["node_modules/@pnpm/exe/**/*"]).pipe(gulp.dest(path.join(dataDir, "@pnpm", "exe"))); -// Rename and copy the license file -function copyLicense() -{ - return gulp.src([licenseFile]) - .pipe(rename("LICENSE-Server.txt")) - .pipe(gulp.dest(buildDir)); -} +/** + * Rename and copy the license file + */ +const copyLicense = () => gulp.src([licenseFile]).pipe(rename("LICENSE-Server.txt")).pipe(gulp.dest(buildDir)); /** * Writes the latest Git commit hash to the core.json configuration file. - * @param {*} cb Callback to run after completion of function */ -async function writeCommitHashToCoreJSON(cb) +const writeCommitHashToCoreJSON = async () => { - const coreJSONPath = path.resolve(dataDir, "configs", "core.json"); - if (fs.existsSync(coreJSONPath)) + try { - try - { - const coreJSON = fs.readFileSync(coreJSONPath, "utf8"); - const parsed = JSON.parse(coreJSON); - - // Fetch the latest Git commit hash - const gitResult = await exec("git rev-parse HEAD", { stdout: "pipe" }); - - // Update the commit hash in the core.json object - parsed.commit = gitResult.stdout.trim() || ""; + const coreJSONPath = path.resolve(dataDir, "configs", "core.json"); + const coreJSON = await fs.readFile(coreJSONPath, "utf8"); + const parsed = JSON.parse(coreJSON); - // Add build timestamp - parsed.buildTime = new Date().getTime(); - - // Write the updated object back to core.json - fs.writeFileSync(coreJSONPath, JSON.stringify(parsed, null, 4)); - } - catch (error) - { - throw new Error(`Failed to write commit hash to core.json: ${error.message}`); - } + // Fetch the latest Git commit hash + const gitResult = await exec("git rev-parse HEAD", { stdout: "pipe" }); + + // Update the commit hash in the core.json object + parsed.commit = gitResult.stdout.trim() || ""; + + // Add build timestamp + parsed.buildTime = new Date().getTime(); + + // Write the updated object back to core.json + await fs.writeFile(coreJSONPath, JSON.stringify(parsed, null, 4)); } - else + catch (error) { - console.warn(`core.json not found at ${coreJSONPath}. Skipping commit hash update.`); + throw new Error(`Failed to write commit hash to core.json: ${error.message}`); } - - cb(); -} +}; - -// Create a hash file for asset checks -async function createHashFile() +/** + * Create a hash file for asset checks + */ +const createHashFile = async () => { const hashFileDir = path.resolve(dataDir, "checks.dat"); - await fs.createFile(hashFileDir); const assetData = await loadRecursiveAsync("assets/"); const assetDataString = Buffer.from(JSON.stringify(assetData), "utf-8").toString("base64"); await fs.writeFile(hashFileDir, assetDataString); -} +}; // Combine all tasks into addAssets const addAssets = gulp.series(copyAssets, copyExecutables, copyLicense, writeCommitHashToCoreJSON, createHashFile); -// Cleanup -const clean = (cb) => -{ - deleteSync(buildDir, { force: true }); - cb(); -}; -const removeCompiled = async () => fs.rmSync("./obj", { recursive: true, force: true }); +/** + * Cleans the build directory. + */ +const cleanBuild = async () => await fs.rm(buildDir, { recursive: true, force: true }); -// JSON Validation -function getJSONFiles(dir, files = []) +/** + * Cleans the transpiled javascript directory. + */ +const cleanCompiled = async () => await fs.rm("./obj", { recursive: true, force: true }); + +/** + * Recursively builds an array of paths for json files. + * + * @param {fs.PathLike} dir + * @param {string[]} files + * @returns {Promise} + */ +const getJSONFiles = async (dir, files = []) => { - const fileList = fs.readdirSync(dir); - for (const file of fileList) + const fileList = await fs.readdir(dir); + for (const file of fileList) { - const name = path.resolve(dir,file); - if (fs.statSync(name).isDirectory()) + const name = path.resolve(dir, file); + if ((await fs.stat(name)).isDirectory()) { - getJSONFiles(name, files); + getJSONFiles(name, files); } else if (name.slice(-5) === ".json") { @@ -202,30 +185,36 @@ function getJSONFiles(dir, files = []) } } return files; -} - -const validateJSONs = (cb) => +}; + +/** + * Goes through every json file in assets and makes sure they're valid json. + */ +const validateJSONs = async () => { const assetsPath = path.resolve("assets"); - const jsonFileList = getJSONFiles(assetsPath); + const jsonFileList = await getJSONFiles(assetsPath); let jsonFileInProcess = ""; - try + try { - jsonFileList.forEach((jsonFile) => + for (const jsonFile of jsonFileList) { jsonFileInProcess = jsonFile; - const jsonString = fs.readFileSync(jsonFile).toString(); - JSON.parse(jsonString); - }); - cb(); + JSON.parse(await fs.readFile(jsonFile)); + } } - catch (error) + catch (error) { throw new Error(`${error.message} | ${jsonFileInProcess}`); } }; -// Hash helper function +/** + * Hash helper function + * + * @param {crypto.BinaryLike} data + * @returns {string} + */ const generateHashForData = (data) => { const hashSum = crypto.createHash("sha1"); @@ -233,36 +222,29 @@ const generateHashForData = (data) => return hashSum.digest("hex"); }; -// Loader to recursively find all json files in a folder +/** + * Loader to recursively find all json files in a folder + * + * @param {fs.PathLike} filepath + * @returns {} + */ const loadRecursiveAsync = async (filepath) => { const result = {}; - // get all filepaths - const files = fs.readdirSync(filepath).filter((item) => - { - return fs.statSync(path.join(filepath, item)).isFile(); - }); - const directories = fs.readdirSync(filepath).filter((item) => - { - return fs.statSync(path.join(filepath, item)).isDirectory(); - }); + const filesList = await fs.readdir(filepath); - // add file content to result - for (const file of files) + for (const file of filesList) { - if (file.split(".").pop() === "json") + const curPath = path.parse(path.join(filepath, file)); + if ((await fs.stat(path.join(curPath.dir, curPath.base))).isDirectory()) { - const filename = file.split(".").slice(0, -1).join("."); - const filePathAndName = `${filepath}${file}`; - result[filename] = generateHashForData(fs.readFileSync(filePathAndName)); + result[curPath.name] = loadRecursiveAsync(`${filepath}${file}/`); + } + else if (curPath.ext === ".json") + { + result[curPath.name] = generateHashForData(await fs.readFile(`${filepath}${file}`)); } - } - - // deep tree search - for (const dir of directories) - { - result[dir] = loadRecursiveAsync(`${filepath}${dir}/`); } // set all loadRecursive to be executed asynchronously @@ -272,46 +254,44 @@ const loadRecursiveAsync = async (filepath) => { resEntries[resIdx][1] = resResolved[resIdx]; } - + // return the result of all async fetch return Object.fromEntries(resEntries); }; -// Testing -gulp.task("test:debug", async () => exec("ts-node-dev -r tsconfig-paths/register src/ide/TestEntry.ts", { stdio })); - // Main Tasks Generation -const build = (packagingType) => +const build = (packagingType) => { const anonPackaging = () => packaging(entries[packagingType]); anonPackaging.displayName = `packaging-${packagingType}`; - const tasks = [clean, validateJSONs, compileTest, fetchPackageImage, anonPackaging, addAssets, updateBuildProperties, removeCompiled]; + const tasks = [cleanBuild, validateJSONs, compile, fetchPackageImage, anonPackaging, addAssets, updateBuildProperties, cleanCompiled]; return gulp.series(tasks); }; // Packaging Arguments -const packaging = async (entry) => +const packaging = async (entry) => { const target = `${nodeVersion}-${process.platform}-${process.arch}`; + console.log("target", target); const args = [entry, "--compress", "GZip", "--target", target, "--output", serverExe, "--config", pkgConfig]; - try + try { await pkg.exec(args); } - catch (error) + catch (error) { console.error(`Error occurred during packaging: ${error}`); } }; -// Run server -const runSrv = async (cb) => -{ - await exec("Aki.Server.exe", { stdio, cwd: buildDir }); - cb(); -}; - gulp.task("build:debug", build("debug")); gulp.task("build:release", build("release")); gulp.task("build:bleeding", build("bleeding")); -gulp.task("run:server", runSrv); + +gulp.task("run:build", async () => await exec("Aki.Server.exe", { stdio, cwd: buildDir })); +gulp.task("run:debug", async () => await exec("ts-node-dev -r tsconfig-paths/register src/ide/TestEntry.ts", { stdio })); +gulp.task("run:profiler", async () => +{ + await compileProfiler(); + await exec("node --prof --inspect --trace-warnings obj/ide/TestEntry.js", { stdio }); +}); diff --git a/project/package.json b/project/package.json index 94d4329d..b101acf0 100644 --- a/project/package.json +++ b/project/package.json @@ -11,20 +11,19 @@ "node": "18.15.0" }, "scripts": { - "profilerCompile": "tsc -p test_tsconfig.json", - "run:profiler": "npm run profilerCompile && node --prof --inspect --trace-warnings obj/ide/TestEntry.js", - "check:circular": "npx madge --circular --extensions ts ./src/", + "check:circular": "madge --circular --extensions ts ./src/", "lint": "rome ci src --formatter-enabled=false --max-diagnostics=200", "lint:fix": "eslint --fix --ext .ts src/**", - "test:debug": "gulp test:debug", "test:run": "jest --colors --runInBand", "test:coverage": "jest --coverage --maxWorkers=1 --no-cache", "build:release": "cross-env PKG_CACHE_PATH=\"./.pkg-cache\" gulp build:release", "build:debug": "cross-env PKG_CACHE_PATH=\"./.pkg-cache\" gulp build:debug", "build:bleeding": "cross-env PKG_CACHE_PATH=\"./.pkg-cache\" gulp build:bleeding", - "gen:types": "tsc -p typedef_tsconfig.json", - "gen:docs": "typedoc --options ./typedoc.json --entryPointStrategy expand ./src", - "run:server": "gulp run:server" + "run:build": "gulp run:build", + "run:debug": "gulp run:debug", + "run:profiler": "gulp run:profiler", + "gen:types": "tsc -p tsconfig.typedef.json", + "gen:docs": "typedoc --options ./typedoc.json --entryPointStrategy expand ./src" }, "dependencies": { "atomically": "1.7.0", @@ -37,36 +36,33 @@ "semver": "7.5.4", "source-map-support": "0.5.21", "tsyringe": "4.8.0", - "typescript": "5.1.6", - "winston": "3.10.0", + "typescript": "5.2.2", + "winston": "3.11.0", "winston-daily-rotate-file": "4.7.1", - "ws": "8.13.0" + "ws": "8.14.2" }, "devDependencies": { - "@babel/preset-env": "7.22.9", - "@babel/preset-typescript": "7.22.5", - "@jest/globals": "29.6.2", - "@pnpm/exe": "8.8.0", + "@babel/preset-env": "7.23.2", + "@babel/preset-typescript": "7.23.2", + "@jest/globals": "29.7.0", + "@pnpm/exe": "8.9.0", "@swc/cli": "0.1.62", - "@swc/core": "1.3.72", - "@swc/jest": "0.2.27", - "@types/i18n": "0.13.6", - "@types/jest": "29.5.3", - "@types/node": "20.4.5", + "@swc/core": "1.3.92", + "@swc/jest": "0.2.29", + "@types/i18n": "0.13.7", + "@types/jest": "29.5.5", + "@types/node": "18.18.4", "@types/proper-lockfile": "4.1.2", - "@types/semver": "7.5.0", - "@types/ws": "8.5.5", - "@typescript-eslint/eslint-plugin": "6.2.0", - "@typescript-eslint/parser": "6.2.0", + "@types/semver": "7.5.3", + "@types/ws": "8.5.7", + "@typescript-eslint/eslint-plugin": "6.7.5", + "@typescript-eslint/parser": "6.7.5", "cross-env": "7.0.3", - "del": "7.0.0", - "eslint": "8.46.0", - "fs-extra": "11.1.1", + "eslint": "8.51.0", "gulp": "4.0.2", - "gulp-execa": "5.0.0", + "gulp-execa": "5.0.1", "gulp-rename": "2.0.0", - "jest": "29.6.2", - "jshint": "2.13.6", + "jest": "29.7.0", "madge": "6.1.0", "pkg": "5.8.1", "pkg-fetch": "3.5.2", @@ -75,9 +71,8 @@ "ts-jest": "29.1.1", "ts-node-dev": "2.0.0", "tsconfig-paths": "4.2.0", - "typedoc": "0.24.8", - "typemoq": "2.1.0", - "utf-8-validate": "6.0.3" + "typedoc": "0.25.2", + "typemoq": "2.1.0" }, "overrides": { "pkg": { diff --git a/project/rome.json b/project/rome.json index f6cb93b9..c6af5710 100644 --- a/project/rome.json +++ b/project/rome.json @@ -35,8 +35,8 @@ "**/*.js", "**/*.json", "**/*.mjs", - "**/*.Dockerfile", + "**/Dockerfile.*", "**/node_modules/**/*" ] } -} \ No newline at end of file +} diff --git a/project/src/controllers/GameController.ts b/project/src/controllers/GameController.ts index fcbb8dcb..ae55894f 100644 --- a/project/src/controllers/GameController.ts +++ b/project/src/controllers/GameController.ts @@ -43,8 +43,6 @@ import { TimeUtil } from "../utils/TimeUtil"; @injectable() export class GameController { - protected os = require("os"); - protected httpConfig: IHttpConfig; protected coreConfig: ICoreConfig; protected locationConfig: ILocationConfig; diff --git a/project/src/di/Serializer.ts b/project/src/di/Serializer.ts index 9f38b20f..38b2fe5c 100644 --- a/project/src/di/Serializer.ts +++ b/project/src/di/Serializer.ts @@ -1,4 +1,4 @@ -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export class Serializer { diff --git a/project/src/loaders/PreAkiModLoader.ts b/project/src/loaders/PreAkiModLoader.ts index 245c9ed8..a7417629 100644 --- a/project/src/loaders/PreAkiModLoader.ts +++ b/project/src/loaders/PreAkiModLoader.ts @@ -1,6 +1,6 @@ -import { execSync } from "child_process"; -import os from "os"; -import path from "path"; +import { execSync } from "node:child_process"; +import os from "node:os"; +import path from "node:path"; import semver from "semver"; import { DependencyContainer, inject, injectable } from "tsyringe"; import { ModDetails } from "../models/eft/profile/IAkiProfile"; diff --git a/project/src/models/external/HttpFramework.ts b/project/src/models/external/HttpFramework.ts index 8e569239..678353d8 100644 --- a/project/src/models/external/HttpFramework.ts +++ b/project/src/models/external/HttpFramework.ts @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { injectable } from "tsyringe"; import { HttpMethods } from "../../servers/http/HttpMethods"; diff --git a/project/src/routers/HttpRouter.ts b/project/src/routers/HttpRouter.ts index 45283145..80c181b8 100644 --- a/project/src/routers/HttpRouter.ts +++ b/project/src/routers/HttpRouter.ts @@ -1,4 +1,4 @@ -import { IncomingMessage } from "http"; +import { IncomingMessage } from "node:http"; import { injectable, injectAll } from "tsyringe"; import { DynamicRouter, Router, StaticRouter } from "../di/Router"; diff --git a/project/src/routers/ImageRouter.ts b/project/src/routers/ImageRouter.ts index f2ec7992..ee14f1c5 100644 --- a/project/src/routers/ImageRouter.ts +++ b/project/src/routers/ImageRouter.ts @@ -1,4 +1,4 @@ -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { inject, injectable } from "tsyringe"; import { ImageRouteService } from "../services/mod/image/ImageRouteService"; diff --git a/project/src/routers/serializers/BundleSerializer.ts b/project/src/routers/serializers/BundleSerializer.ts index 6082c09d..868c0cf3 100644 --- a/project/src/routers/serializers/BundleSerializer.ts +++ b/project/src/routers/serializers/BundleSerializer.ts @@ -1,4 +1,4 @@ -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { inject, injectable } from "tsyringe"; import { Serializer } from "../../di/Serializer"; diff --git a/project/src/routers/serializers/ImageSerializer.ts b/project/src/routers/serializers/ImageSerializer.ts index b73cb3aa..75d7f959 100644 --- a/project/src/routers/serializers/ImageSerializer.ts +++ b/project/src/routers/serializers/ImageSerializer.ts @@ -1,4 +1,4 @@ -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { inject, injectable } from "tsyringe"; import { Serializer } from "../../di/Serializer"; diff --git a/project/src/routers/serializers/NotifySerializer.ts b/project/src/routers/serializers/NotifySerializer.ts index 2c8e8d2e..e3533a5a 100644 --- a/project/src/routers/serializers/NotifySerializer.ts +++ b/project/src/routers/serializers/NotifySerializer.ts @@ -1,4 +1,4 @@ -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { inject, injectable } from "tsyringe"; import { NotifierController } from "../../controllers/NotifierController"; diff --git a/project/src/servers/HttpServer.ts b/project/src/servers/HttpServer.ts index e17092fe..58fae42b 100644 --- a/project/src/servers/HttpServer.ts +++ b/project/src/servers/HttpServer.ts @@ -1,4 +1,4 @@ -import http, { IncomingMessage, ServerResponse } from "http"; +import http, { IncomingMessage, ServerResponse } from "node:http"; import { inject, injectable, injectAll } from "tsyringe"; import { ApplicationContext } from "../context/ApplicationContext"; diff --git a/project/src/servers/WebSocketServer.ts b/project/src/servers/WebSocketServer.ts index 60fb186e..c551c802 100644 --- a/project/src/servers/WebSocketServer.ts +++ b/project/src/servers/WebSocketServer.ts @@ -1,4 +1,4 @@ -import http, { IncomingMessage } from "http"; +import http, { IncomingMessage } from "node:http"; import { inject, injectable } from "tsyringe"; import WebSocket from "ws"; diff --git a/project/src/servers/http/AkiHttpListener.ts b/project/src/servers/http/AkiHttpListener.ts index 000c2030..48e41565 100644 --- a/project/src/servers/http/AkiHttpListener.ts +++ b/project/src/servers/http/AkiHttpListener.ts @@ -1,6 +1,6 @@ -import { IncomingHttpHeaders, IncomingMessage, ServerResponse } from "http"; +import { IncomingHttpHeaders, IncomingMessage, ServerResponse } from "node:http"; +import zlib from "node:zlib"; import { inject, injectAll, injectable } from "tsyringe"; -import zlib from "zlib"; import { Serializer } from "../../di/Serializer"; import { ILogger } from "../../models/spt/utils/ILogger"; diff --git a/project/src/servers/http/IHttpListener.ts b/project/src/servers/http/IHttpListener.ts index 343d5300..22b8bbd8 100644 --- a/project/src/servers/http/IHttpListener.ts +++ b/project/src/servers/http/IHttpListener.ts @@ -1,4 +1,4 @@ -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; export interface IHttpListener { diff --git a/project/src/services/LocalisationService.ts b/project/src/services/LocalisationService.ts index 17c55b24..0aa8a3e2 100644 --- a/project/src/services/LocalisationService.ts +++ b/project/src/services/LocalisationService.ts @@ -1,12 +1,12 @@ import { I18n } from "i18n"; import { inject, injectable } from "tsyringe"; +import path from "node:path"; import { ILocaleConfig } from "../models/spt/config/ILocaleConfig"; import { ILogger } from "../models/spt/utils/ILogger"; import { DatabaseServer } from "../servers/DatabaseServer"; import { RandomUtil } from "../utils/RandomUtil"; import { LocaleService } from "./LocaleService"; -import path from "path"; /** * Handles translating server text into different langauges diff --git a/project/src/services/ModCompilerService.ts b/project/src/services/ModCompilerService.ts index da7b532a..c7907f2a 100644 --- a/project/src/services/ModCompilerService.ts +++ b/project/src/services/ModCompilerService.ts @@ -1,8 +1,8 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import fs from "fs"; -import path from "path"; +import fs from "node:fs"; +import path from "node:path"; import { inject, injectable } from "tsyringe"; -import { CompilerOptions, ModuleKind, ScriptTarget, TranspileOptions, transpileModule } from "typescript"; +import { CompilerOptions, ModuleKind, ModuleResolutionKind, ScriptTarget, TranspileOptions, transpileModule } from "typescript"; import type { ILogger } from "../models/spt/utils/ILogger"; import { VFS } from "../utils/VFS"; import { HashCacheService } from "./HashCacheService"; @@ -64,8 +64,9 @@ export class ModCompilerService { noEmitOnError: true, noImplicitAny: false, - target: ScriptTarget.ES2020, + target: ScriptTarget.ES2022, module: ModuleKind.CommonJS, + moduleResolution: ModuleResolutionKind.Node10, resolveJsonModule: true, allowJs: true, esModuleInterop: true, diff --git a/project/src/services/mod/httpListener/HttpListenerMod.ts b/project/src/services/mod/httpListener/HttpListenerMod.ts index 7932dc4f..ea34bfb2 100644 --- a/project/src/services/mod/httpListener/HttpListenerMod.ts +++ b/project/src/services/mod/httpListener/HttpListenerMod.ts @@ -1,4 +1,4 @@ -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { IHttpListener } from "../../../servers/http/IHttpListener"; export class HttpListenerMod implements IHttpListener diff --git a/project/src/services/mod/httpListener/HttpListenerModService.ts b/project/src/services/mod/httpListener/HttpListenerModService.ts index ecfab69e..99d65f5e 100644 --- a/project/src/services/mod/httpListener/HttpListenerModService.ts +++ b/project/src/services/mod/httpListener/HttpListenerModService.ts @@ -1,4 +1,4 @@ -import { IncomingMessage, ServerResponse } from "http"; +import { IncomingMessage, ServerResponse } from "node:http"; import { DependencyContainer, injectable } from "tsyringe"; import { IHttpListener } from "../../../servers/http/IHttpListener"; import { HttpListenerMod } from "./HttpListenerMod"; diff --git a/project/src/utils/App.ts b/project/src/utils/App.ts index 4aeb1393..f6ffa6dc 100644 --- a/project/src/utils/App.ts +++ b/project/src/utils/App.ts @@ -1,6 +1,7 @@ import sourcemapSupport from "source-map-support"; import { inject, injectable, injectAll } from "tsyringe"; +import os from "node:os"; import { OnLoad } from "../di/OnLoad"; import { OnUpdate } from "../di/OnUpdate"; import { ILogger } from "../models/spt/utils/ILogger"; @@ -12,7 +13,6 @@ import { TimeUtil } from "./TimeUtil"; export class App { protected onUpdateLastRun = {}; - protected os = require("os"); constructor( @inject("WinstonLogger") protected logger: ILogger, @@ -32,9 +32,9 @@ export class App // execute onLoad callbacks this.logger.info(this.localisationService.getText("executing_startup_callbacks")); - this.logger.debug(`OS: ${this.os.arch()} | ${this.os.version()} | ${process.platform}`); - this.logger.debug(`CPU: ${this.os?.cpus()[0]?.model} cores: ${this.os.availableParallelism()}`); - this.logger.debug(`RAM: ${(this.os.totalmem() / 1024 / 1024 / 1024).toFixed(2)}GB`); + this.logger.debug(`OS: ${os.arch()} | ${os.version()} | ${process.platform}`); + this.logger.debug(`CPU: ${os.cpus()[0]?.model} cores: ${os.cpus().length}`); + this.logger.debug(`RAM: ${(os.totalmem() / 1024 / 1024 / 1024).toFixed(2)}GB`); this.logger.debug(`PATH: ${this.encodingUtil.toBase64(process.argv[0])}`); this.logger.debug(`PATH: ${this.encodingUtil.toBase64(process.execPath)}`); diff --git a/project/src/utils/HashUtil.ts b/project/src/utils/HashUtil.ts index ea9e25a7..896d4e8a 100644 --- a/project/src/utils/HashUtil.ts +++ b/project/src/utils/HashUtil.ts @@ -1,4 +1,4 @@ -import crypto from "crypto"; +import crypto from "node:crypto"; import { inject, injectable } from "tsyringe"; import { TimeUtil } from "./TimeUtil"; diff --git a/project/src/utils/HttpFileUtil.ts b/project/src/utils/HttpFileUtil.ts index f04e8dbb..6101a6ce 100644 --- a/project/src/utils/HttpFileUtil.ts +++ b/project/src/utils/HttpFileUtil.ts @@ -1,5 +1,5 @@ -import fs from "fs"; -import { ServerResponse } from "http"; +import fs from "node:fs"; +import { ServerResponse } from "node:http"; import { inject, injectable } from "tsyringe"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; diff --git a/project/src/utils/ObjectId.ts b/project/src/utils/ObjectId.ts index 36dcf4a9..bca1b9bd 100644 --- a/project/src/utils/ObjectId.ts +++ b/project/src/utils/ObjectId.ts @@ -1,4 +1,4 @@ -import crypto from "crypto"; +import crypto from "node:crypto"; import { TimeUtil } from "./TimeUtil"; import { inject, injectable } from "tsyringe"; diff --git a/project/src/utils/VFS.ts b/project/src/utils/VFS.ts index df828ee2..8a869cc0 100644 --- a/project/src/utils/VFS.ts +++ b/project/src/utils/VFS.ts @@ -1,10 +1,10 @@ import { writeFileSync } from "atomically"; -import fs from "fs"; -import path, { resolve } from "path"; +import fs from "node:fs"; +import path, { resolve } from "node:path"; +import { promisify } from "node:util"; import lockfile from "proper-lockfile"; import "reflect-metadata"; import { inject, injectable } from "tsyringe"; -import { promisify } from "util"; import { IAsyncQueue } from "../models/spt/utils/IAsyncQueue"; import { IUUidGenerator } from "../models/spt/utils/IUuidGenerator"; diff --git a/project/src/utils/Watermark.ts b/project/src/utils/Watermark.ts index f38942eb..2d2b94b4 100644 --- a/project/src/utils/Watermark.ts +++ b/project/src/utils/Watermark.ts @@ -10,21 +10,22 @@ import { LocalisationService } from "../services/LocalisationService"; @injectable() export class WatermarkLocale { + protected description: string[]; + protected warning: string[]; + protected modding: string[]; + constructor( @inject("LocalisationService") protected localisationService: LocalisationService ) - {} - - protected watermark = { - // eslint-disable-next-line @typescript-eslint/naming-convention - "description": [ + { + this.description = [ this.localisationService.getText("watermark-discord_url"), "", this.localisationService.getText("watermark-free_of_charge"), this.localisationService.getText("watermark-paid_scammed"), this.localisationService.getText("watermark-commercial_use_prohibited") - ], - "warning": [ + ]; + this.warning = [ "", this.localisationService.getText("watermark-testing_build"), this.localisationService.getText("watermark-no_support"), @@ -33,29 +34,29 @@ export class WatermarkLocale this.localisationService.getText("watermark-issue_tracker_url"), "", this.localisationService.getText("watermark-use_at_own_risk") - ], - "modding": [ + ]; + this.modding = [ "", this.localisationService.getText("watermark-modding_disabled"), "", this.localisationService.getText("watermark-not_an_issue"), this.localisationService.getText("watermark-do_not_report") - ] - }; + ]; + } public getDescription(): string[] { - return this.watermark.description; + return this.description; } public getWarning(): string[] { - return this.watermark.warning; + return this.warning; } public getModding(): string[] { - return this.watermark.modding; + return this.modding; } } diff --git a/project/src/utils/logging/AbstractWinstonLogger.ts b/project/src/utils/logging/AbstractWinstonLogger.ts index 8a3c3045..2f97a33e 100644 --- a/project/src/utils/logging/AbstractWinstonLogger.ts +++ b/project/src/utils/logging/AbstractWinstonLogger.ts @@ -1,5 +1,5 @@ -import fs from "fs"; -import { promisify } from "util"; +import fs from "node:fs"; +import { promisify } from "node:util"; import winston, { createLogger, format, transports } from "winston"; import DailyRotateFile from "winston-daily-rotate-file"; diff --git a/project/base_tsconfig.json b/project/tsconfig.base.json similarity index 70% rename from project/base_tsconfig.json rename to project/tsconfig.base.json index a5b9984f..9ffde66b 100644 --- a/project/base_tsconfig.json +++ b/project/tsconfig.base.json @@ -1,20 +1,17 @@ { "compilerOptions": { "allowJs": false, - "module": "commonjs", - "target": "es2021", + "module": "CommonJS", + "target": "ES2022", "allowSyntheticDefaultImports": true, - "moduleResolution": "node", + "moduleResolution": "Node10", "esModuleInterop": true, "downlevelIteration": true, "experimentalDecorators": true, "emitDecoratorMetadata": true }, - "lib": [ - "es2020" - ], "include": [ "src/*", "src/**/*" ] -} \ No newline at end of file +} diff --git a/project/tsconfig.json b/project/tsconfig.json index 807391e8..de909065 100644 --- a/project/tsconfig.json +++ b/project/tsconfig.json @@ -1,11 +1,9 @@ { - "extends": "./base_tsconfig.json", + "extends": "./tsconfig.base.json", "compilerOptions": { "resolveJsonModule": true, "outDir": "obj", "declaration": true, - "experimentalDecorators": true, - "emitDecoratorMetadata": true, "baseUrl": ".", "paths": { "@spt-aki/*": [ @@ -22,4 +20,4 @@ "exclude": [ "./user/mods/**/*" ] -} \ No newline at end of file +} diff --git a/project/test_tsconfig.json b/project/tsconfig.test.json similarity index 83% rename from project/test_tsconfig.json rename to project/tsconfig.test.json index adf8fc72..c7d718a9 100644 --- a/project/test_tsconfig.json +++ b/project/tsconfig.test.json @@ -1,5 +1,5 @@ { - "extends": "./base_tsconfig.json", + "extends": "./tsconfig.base.json", "compilerOptions": { "outDir": "obj", "declaration": true, @@ -10,4 +10,4 @@ "./types/**/*", "./src/**/*" ] -} \ No newline at end of file +} diff --git a/project/typedef_tsconfig.json b/project/tsconfig.typedef.json similarity index 81% rename from project/typedef_tsconfig.json rename to project/tsconfig.typedef.json index b5b07739..235104aa 100644 --- a/project/typedef_tsconfig.json +++ b/project/tsconfig.typedef.json @@ -1,5 +1,5 @@ { - "extends": "./base_tsconfig.json", + "extends": "./tsconfig.base.json", "compilerOptions": { "emitDeclarationOnly": true, "declaration": true, @@ -8,4 +8,4 @@ "exclude": [ "./types/**/*" ] -} \ No newline at end of file +}