diff --git a/src/index.js b/src/index.js index 0cd7102..efcfafb 100644 --- a/src/index.js +++ b/src/index.js @@ -1,4 +1,4 @@ -const cluster = require("./utils/clusterBunShim.js"); // Cluster shim for Bun +const cluster = require("./utils/clusterShim.js"); // Cluster shim for Bun and Deno const { add } = require("./utils/helper.js"); // Require the addition module const modInfo = require("../modInfo.json"); // SVR.JS mod information diff --git a/src/utils/clusterBunShim.js b/src/utils/clusterShim.js similarity index 91% rename from src/utils/clusterBunShim.js rename to src/utils/clusterShim.js index 5c7ced8..a9b75c4 100644 --- a/src/utils/clusterBunShim.js +++ b/src/utils/clusterShim.js @@ -13,9 +13,9 @@ if (!process.singleThreaded) { // Clustering is not supported! } - // Cluster & IPC shim for Bun + // 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; @@ -29,7 +29,7 @@ if (!process.singleThreaded) { isDead: () => false, send: (message, ...params) => { process.send(message, ...params); - }, + } }; if (!process.send) { @@ -52,9 +52,9 @@ if (!process.singleThreaded) { ? path.join( "\\\\?\\pipe", process.dirname, - "temp/.W" + process.pid + ".ipc", + "temp/.W" + process.pid + ".ipc" ) - : process.dirname + "/temp/.W" + process.pid + ".ipc", + : process.dirname + "/temp/.W" + process.pid + ".ipc" ); process.send = (message) => { @@ -64,12 +64,12 @@ if (!process.singleThreaded) { ? path.join( "\\\\?\\pipe", process.dirname, - "temp/.P" + process.pid + ".ipc", + "temp/.P" + process.pid + ".ipc" ) : process.dirname + "/temp/.P" + process.pid + ".ipc", () => { fakeIPCConnection.end(message); - }, + } ); }; @@ -92,7 +92,7 @@ if (!process.singleThreaded) { let command = newArguments.shift(); let newWorker = child_process.spawn(command, newArguments, { env: newEnvironment, - stdio: ["inherit", "inherit", "inherit", "ipc"], + stdio: ["inherit", "inherit", "inherit", "ipc"] }); newWorker.process = newWorker; @@ -126,7 +126,7 @@ if (!process.singleThreaded) { }; try { - worker.send(undefined); + if (process.isBun) worker.send(undefined); } catch (err) { if (err.message === "NOT IMPLEMENTED") { sendImplemented = false; @@ -158,9 +158,9 @@ if (!process.singleThreaded) { ? path.join( "\\\\?\\pipe", process.dirname, - "temp/.P" + newWorker.process.pid + ".ipc", + "temp/.P" + newWorker.process.pid + ".ipc" ) - : process.dirname + "/temp/.P" + newWorker.process.pid + ".ipc", + : process.dirname + "/temp/.P" + newWorker.process.pid + ".ipc" ); // Cleanup when worker process exits @@ -174,7 +174,7 @@ if (!process.singleThreaded) { fakeParam2, fakeParam3, fakeParam4, - tries, + tries ) { if (!tries) tries = 0; @@ -185,12 +185,12 @@ if (!process.singleThreaded) { ? path.join( "\\\\?\\pipe", process.dirname, - "temp/.W" + newWorker.process.pid + ".ipc", + "temp/.W" + newWorker.process.pid + ".ipc" ) : process.dirname + "/temp/.W" + newWorker.process.pid + ".ipc", () => { fakeWorkerIPCConnection.end(message); - }, + } ); } catch (err) { if (tries > 50) throw err; @@ -199,7 +199,7 @@ if (!process.singleThreaded) { fakeParam2, fakeParam3, fakeParam4, - tries + 1, + tries + 1 ); } }; @@ -216,11 +216,11 @@ if (!process.singleThreaded) { }; if ( - process.isBun && + (process.isBun || (process.versions && process.versions.deno)) && (cluster.isMaster === undefined || (cluster.isMaster && process.env.NODE_UNIQUE_ID)) ) { - cluster.bunShim(); + cluster.shim(); } // Shim cluster.isPrimary field