From b1a40e7a2095a4189a7ed6b1e015eb8bd51e6c30 Mon Sep 17 00:00:00 2001 From: Dorian Niemiec Date: Fri, 18 Oct 2024 20:08:52 +0200 Subject: [PATCH] chore: rename the cluster shim method and function, because it's also for Deno 2, not just for Bun --- src/handlers/serverErrorHandler.js | 2 +- src/index.js | 4 ++-- src/middleware/blocklist.js | 2 +- src/middleware/nonStandardCodesAndHttpAuthentication.js | 2 +- src/utils/{clusterBunShim.js => clusterShim.js} | 4 ++-- src/utils/serverconsole.js | 2 +- tests/middleware/blocklist.test.js | 4 ++-- .../middleware/nonStandardCodesAndHttpAuthentication.test.js | 4 ++-- 8 files changed, 12 insertions(+), 12 deletions(-) rename src/utils/{clusterBunShim.js => clusterShim.js} (99%) diff --git a/src/handlers/serverErrorHandler.js b/src/handlers/serverErrorHandler.js index 94b6cf9..1781e4e 100644 --- a/src/handlers/serverErrorHandler.js +++ b/src/handlers/serverErrorHandler.js @@ -1,5 +1,5 @@ const os = require("os"); -const cluster = require("../utils/clusterBunShim.js"); +const cluster = require("../utils/clusterShim.js"); const serverErrorDescs = require("../res/serverErrorDescriptions.js"); let serverconsole = {}; let attmts = 5; diff --git a/src/index.js b/src/index.js index 972d25d..fd19193 100644 --- a/src/index.js +++ b/src/index.js @@ -199,7 +199,7 @@ if (!fs.existsSync(process.dirname + "/mods")) if (!fs.existsSync(process.dirname + "/temp")) fs.mkdirSync(process.dirname + "/temp"); -const cluster = require("./utils/clusterBunShim.js"); // Cluster module with shim for Bun +const cluster = require("./utils/clusterShim.js"); // Cluster module with shim for Bun const legacyModWrapper = require("./utils/legacyModWrapper.js"); const generateErrorStack = require("./utils/generateErrorStack.js"); const { @@ -1453,7 +1453,7 @@ function SVRJSFork() { err.message == "Not implemented: cluster.fork" ) { // If cluster.fork throws a NotImplementedError, shim cluster module - cluster.bunShim(); + cluster.shim(); if ( !threadLimitWarned && cluster.__shimmed__ && diff --git a/src/middleware/blocklist.js b/src/middleware/blocklist.js index a204d53..258aa29 100644 --- a/src/middleware/blocklist.js +++ b/src/middleware/blocklist.js @@ -1,4 +1,4 @@ -const cluster = require("../utils/clusterBunShim.js"); +const cluster = require("../utils/clusterShim.js"); const ipBlockList = require("../utils/ipBlockList.js"); let blocklist = ipBlockList(process.serverConfig.blacklist); diff --git a/src/middleware/nonStandardCodesAndHttpAuthentication.js b/src/middleware/nonStandardCodesAndHttpAuthentication.js index bf452ef..745cd4c 100644 --- a/src/middleware/nonStandardCodesAndHttpAuthentication.js +++ b/src/middleware/nonStandardCodesAndHttpAuthentication.js @@ -4,7 +4,7 @@ const createRegex = require("../utils/createRegex.js"); const ipMatch = require("../utils/ipMatch.js"); const matchHostname = require("../utils/matchHostname.js"); const ipBlockList = require("../utils/ipBlockList.js"); -const cluster = require("../utils/clusterBunShim.js"); +const cluster = require("../utils/clusterShim.js"); const svrjsInfo = require("../../svrjs.json"); const { name } = svrjsInfo; diff --git a/src/utils/clusterBunShim.js b/src/utils/clusterShim.js similarity index 99% rename from src/utils/clusterBunShim.js rename to src/utils/clusterShim.js index 5818af4..a9b75c4 100644 --- a/src/utils/clusterBunShim.js +++ b/src/utils/clusterShim.js @@ -15,7 +15,7 @@ if (!process.singleThreaded) { // Cluster & IPC shim for Bun and Deno - cluster.bunShim = () => { + cluster.shim = () => { cluster.isMaster = !process.env.NODE_UNIQUE_ID; cluster.isPrimary = cluster.isMaster; cluster.isWorker = !cluster.isMaster; @@ -220,7 +220,7 @@ if (!process.singleThreaded) { (cluster.isMaster === undefined || (cluster.isMaster && process.env.NODE_UNIQUE_ID)) ) { - cluster.bunShim(); + cluster.shim(); } // Shim cluster.isPrimary field diff --git a/src/utils/serverconsole.js b/src/utils/serverconsole.js index b5f776e..e89666d 100644 --- a/src/utils/serverconsole.js +++ b/src/utils/serverconsole.js @@ -3,7 +3,7 @@ const fs = require("fs"); let enableLoggingIntoFile = process.serverConfig.enableLogging; let logFile = undefined; let logSync = false; -let cluster = require("./clusterBunShim.js"); +let cluster = require("./clusterShim.js"); let reallyExiting = false; const timestamp = process.serverConfig.timestamp; diff --git a/tests/middleware/blocklist.test.js b/tests/middleware/blocklist.test.js index 072589f..8fa6eae 100644 --- a/tests/middleware/blocklist.test.js +++ b/tests/middleware/blocklist.test.js @@ -1,8 +1,8 @@ const middleware = require("../../src/utils/ipBlockList.js"); -const cluster = require("../../src/utils/clusterBunShim.js"); +const cluster = require("../../src/utils/clusterShim.js"); jest.mock("../../src/utils/ipBlockList.js"); -jest.mock("../../src/utils/clusterBunShim.js"); +jest.mock("../../src/utils/clusterShim.js"); const ipBlockListAdd = jest.fn(); const ipBlockListCheck = jest.fn(); diff --git a/tests/middleware/nonStandardCodesAndHttpAuthentication.test.js b/tests/middleware/nonStandardCodesAndHttpAuthentication.test.js index eb2ca2d..a42b128 100644 --- a/tests/middleware/nonStandardCodesAndHttpAuthentication.test.js +++ b/tests/middleware/nonStandardCodesAndHttpAuthentication.test.js @@ -2,13 +2,13 @@ const sha256 = require("../../src/utils/sha256.js"); const ipMatch = require("../../src/utils/ipMatch.js"); const matchHostname = require("../../src/utils/matchHostname.js"); const ipBlockList = require("../../src/utils/ipBlockList.js"); -const cluster = require("../../src/utils/clusterBunShim.js"); +const cluster = require("../../src/utils/clusterShim.js"); jest.mock("../../src/utils/sha256.js"); jest.mock("../../src/utils/ipMatch.js"); jest.mock("../../src/utils/matchHostname.js"); jest.mock("../../src/utils/ipBlockList.js"); -jest.mock("../../src/utils/clusterBunShim.js"); +jest.mock("../../src/utils/clusterShim.js"); let mockScryptHash = "mocked-scrypt-hash"; let mockPbkdf2Hash = "mocked-pbkdf2-hash";