From 11e72478693b990a5c347a0bd9f7329a91b2f8b6 Mon Sep 17 00:00:00 2001 From: Dorian Niemiec Date: Sat, 24 Aug 2024 19:29:12 +0200 Subject: [PATCH] Replace __dirname with process.dirname (declared as __dirname in index.js) --- src/index.js | 10 ++++++---- src/middleware/checkForbiddenPaths.js | 8 ++++---- src/utils/clusterBunShim.js | 16 ++++++++-------- src/utils/serverconsole.js | 4 ++-- 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/index.js b/src/index.js index 949ffd8..7060cec 100644 --- a/src/index.js +++ b/src/index.js @@ -15,10 +15,12 @@ try { // Don't use inspector } +process.dirname = __dirname; + // Create log, mods and temp directories, if they don't exist. -if (!fs.existsSync(__dirname + "/log")) fs.mkdirSync(__dirname + "/log"); -if (!fs.existsSync(__dirname + "/mods")) fs.mkdirSync(__dirname + "/mods"); -if (!fs.existsSync(__dirname + "/temp")) fs.mkdirSync(__dirname + "/temp"); +if (!fs.existsSync(process.dirname + "/log")) fs.mkdirSync(process.dirname + "/log"); +if (!fs.existsSync(process.dirname + "/mods")) fs.mkdirSync(process.dirname + "/mods"); +if (!fs.existsSync(process.dirname + "/temp")) fs.mkdirSync(process.dirname + "/temp"); // TODO: process.singleThreaded flag process.singleThreaded = true; @@ -102,7 +104,7 @@ if (!process.stdout.isTTY && !inspectorURL) { var wwwrootError = null; try { - if (cluster.isPrimary || cluster.isPrimary === undefined) process.chdir(process.serverConfig.wwwroot != undefined ? process.serverConfig.wwwroot : __dirname); + if (cluster.isPrimary || cluster.isPrimary === undefined) process.chdir(process.serverConfig.wwwroot != undefined ? process.serverConfig.wwwroot : process.dirname); } catch (err) { wwwrootError = err; } diff --git a/src/middleware/checkForbiddenPaths.js b/src/middleware/checkForbiddenPaths.js index afdc122..97d07ee 100644 --- a/src/middleware/checkForbiddenPaths.js +++ b/src/middleware/checkForbiddenPaths.js @@ -10,7 +10,7 @@ function getInitializePath(to) { } const absoluteTo = path.isAbsolute(to) ? to - : __dirname + (os.platform() == "win32" ? "\\" : "/") + to; + : process.dirname + (os.platform() == "win32" ? "\\" : "/") + to; if (os.platform() == "win32" && cwd[0] != absoluteTo[0]) return ""; const relative = path.relative(cwd, absoluteTo); if (os.platform() == "win32") { @@ -95,9 +95,9 @@ if (process.serverConfig.secure) { } forbiddenPaths.svrjs = getInitializePath( "./" + - (__dirname[__dirname.length - 1] != "/" - ? __filename.replace(__dirname + "/", "") - : __filename.replace(__dirname, "")), + (process.dirname[process.dirname.length - 1] != "/" + ? __filename.replace(process.dirname + "/", "") + : __filename.replace(process.dirname, "")), ); forbiddenPaths.serverSideScripts = []; if (process.serverConfig.useWebRootServerSideScript) { diff --git a/src/utils/clusterBunShim.js b/src/utils/clusterBunShim.js index c0254f2..2db690b 100644 --- a/src/utils/clusterBunShim.js +++ b/src/utils/clusterBunShim.js @@ -52,10 +52,10 @@ if (!process.singleThreaded) { os.platform() === "win32" ? path.join( "\\\\?\\pipe", - __dirname, + process.dirname, "temp/.W" + process.pid + ".ipc", ) - : __dirname + "/temp/.W" + process.pid + ".ipc", + : process.dirname + "/temp/.W" + process.pid + ".ipc", ); process.send = function (message) { @@ -64,10 +64,10 @@ if (!process.singleThreaded) { os.platform() === "win32" ? path.join( "\\\\?\\pipe", - __dirname, + process.dirname, "temp/.P" + process.pid + ".ipc", ) - : __dirname + "/temp/.P" + process.pid + ".ipc", + : process.dirname + "/temp/.P" + process.pid + ".ipc", function () { fakeIPCConnection.end(message); }, @@ -159,10 +159,10 @@ if (!process.singleThreaded) { os.platform() === "win32" ? path.join( "\\\\?\\pipe", - __dirname, + process.dirname, "temp/.P" + newWorker.process.pid + ".ipc", ) - : __dirname + "/temp/.P" + newWorker.process.pid + ".ipc", + : process.dirname + "/temp/.P" + newWorker.process.pid + ".ipc", ); // Cleanup when worker process exits @@ -186,10 +186,10 @@ if (!process.singleThreaded) { os.platform() === "win32" ? path.join( "\\\\?\\pipe", - __dirname, + process.dirname, "temp/.W" + newWorker.process.pid + ".ipc", ) - : __dirname + "/temp/.W" + newWorker.process.pid + ".ipc", + : process.dirname + "/temp/.W" + newWorker.process.pid + ".ipc", function () { fakeWorkerIPCConnection.end(message); }, diff --git a/src/utils/serverconsole.js b/src/utils/serverconsole.js index 2bd8f32..8378bd7 100644 --- a/src/utils/serverconsole.js +++ b/src/utils/serverconsole.js @@ -13,7 +13,7 @@ function LOG(s) { if (enableLoggingIntoFile) { if (logSync) { fs.appendFileSync( - __dirname + + process.dirname + "/log/" + (cluster.isPrimary ? "master" @@ -28,7 +28,7 @@ function LOG(s) { } else { if (!logFile) { logFile = fs.createWriteStream( - __dirname + + process.dirname + "/log/" + (cluster.isPrimary ? "master"