Skip to content

Commit 21d1e74

Browse files
refactor: simplify internal require() calls (#4056)
Remove unnecessary `__dirname` template-literal prefix from relative `require()` paths. Node.js resolves relative require() paths correctly without it. While this may look like nitpicking: `require("./server")` is transparent to static analysis tools - IDEs can resolve the path and support go-to-definition. Template literals with `__dirname` are opaque to them. It also removes another usage of `__dirname`, which has no native equivalent in ESM and would need to be replaced there anyway (when we switch to ESM anytime in the future). The import reordering is a side effect: `import-x/order` treats template-literal `require()` calls differently from plain strings, so the previous order was no longer valid.
1 parent 9fe7d1e commit 21d1e74

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

js/app.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ const Log = require("logger");
99
// global absolute root path
1010
global.root_path = path.resolve(`${__dirname}/../`);
1111

12-
const Server = require(`${__dirname}/server`);
13-
const Utils = require(`${__dirname}/utils`);
14-
1512
// used to control fetch timeout for node_helpers
1613
const { setGlobalDispatcher, Agent } = require("undici");
14+
15+
const Server = require("./server");
16+
const Utils = require("./utils");
17+
1718
const { getEnvVarsAsObj } = require("#server_functions");
1819
// common timeout value, provide environment override in case
1920
const fetch_timeout = process.env.mmFetchTimeout !== undefined ? process.env.mmFetchTimeout : 30000;

js/server.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ const express = require("express");
66
const helmet = require("helmet");
77
const socketio = require("socket.io");
88
const Log = require("logger");
9-
const { getHtml, getVersion, getEnvVars, cors } = require("#server_functions");
109

11-
const { ipAccessControl } = require(`${__dirname}/ip_access_control`);
10+
const { ipAccessControl } = require("./ip_access_control");
11+
12+
const vendor = require("./vendor");
1213

13-
const vendor = require(`${__dirname}/vendor`);
14+
const { getHtml, getVersion, getEnvVars, cors } = require("#server_functions");
1415

1516
/**
1617
* Server

js/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ const checkDeprecatedOptions = (userConfig) => {
9696
*/
9797
const loadConfig = () => {
9898
Log.log("Loading config ...");
99-
const defaults = require(`${__dirname}/defaults`);
99+
const defaults = require("./defaults");
100100
if (global.mmTestMode) {
101101
// if we are running in test mode
102102
defaults.address = "0.0.0.0";

0 commit comments

Comments
 (0)