Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Thanks to: @dathbe.
- Improve test reliability and maintainability
- [tests] add alert module tests for different welcome_message configurations (#3867)
- [lint-staged] use `prettier --write --ignore-unknown` in `lint-staged` to avoid errors on unsupported files (#3888)
- [core] refactor: replace `module-alias` dependency with internal alias resolver (#3893)

### Updated

Expand Down
10 changes: 7 additions & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
const aliasMapper = {
logger: "<rootDir>/js/logger.js"
};

const config = {
verbose: true,
testTimeout: 20000,
Expand All @@ -6,21 +10,21 @@ const config = {
{
displayName: "unit",
globalSetup: "<rootDir>/tests/unit/helpers/global-setup.js",
moduleNameMapper: {
logger: "<rootDir>/js/logger.js"
},
moduleNameMapper: aliasMapper,
testMatch: ["**/tests/unit/**/*.[jt]s?(x)"],
testPathIgnorePatterns: ["<rootDir>/tests/unit/mocks", "<rootDir>/tests/unit/helpers"]
},
{
displayName: "electron",
testMatch: ["**/tests/electron/**/*.[jt]s?(x)"],
moduleNameMapper: aliasMapper,
testPathIgnorePatterns: ["<rootDir>/tests/electron/helpers"]
},
{
displayName: "e2e",
testMatch: ["**/tests/e2e/**/*.[jt]s?(x)"],
modulePaths: ["<rootDir>/js/"],
moduleNameMapper: aliasMapper,
testPathIgnorePatterns: ["<rootDir>/tests/e2e/helpers", "<rootDir>/tests/e2e/mocks"]
}
],
Expand Down
31 changes: 31 additions & 0 deletions js/alias-resolver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Internal alias mapping for default and 3rd party modules.
// Provides short require identifiers: "logger" and "node_helper".
// For a future ESM migration, replace this with a public export/import surface.

const path = require("node:path");
const Module = require("module");

const root = path.join(__dirname, "..");

// Keep this list minimal; do not add new aliases without architectural review.
const ALIASES = {
logger: "js/logger.js",
node_helper: "js/node_helper.js"
};

// Resolve to absolute paths now.
const resolved = Object.fromEntries(
Object.entries(ALIASES).map(([k, rel]) => [k, path.join(root, rel)])
);

// Prevent multiple patching if this file is required more than once.
if (!Module._mmAliasPatched) {
const origResolveFilename = Module._resolveFilename;
Module._resolveFilename = function (request, parent, isMain, options) {
if (Object.prototype.hasOwnProperty.call(resolved, request)) {
return resolved[request];
}
return origResolveFilename.call(this, request, parent, isMain, options);
};
Module._mmAliasPatched = true; // non-enumerable marker would be overkill here
}
4 changes: 2 additions & 2 deletions js/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Alias modules mentioned in package.js under _moduleAliases.
require("module-alias/register");
// Load lightweight internal alias resolver
require("./alias-resolver");

const fs = require("node:fs");
const path = require("node:path");
Expand Down
5 changes: 4 additions & 1 deletion js/check_config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
// Ensure internal require aliases (e.g., "logger") resolve when this file is run as a standalone script
require("./alias-resolver");

const path = require("node:path");
const fs = require("node:fs");
const { styleText } = require("node:util");
const Ajv = require("ajv");
const globals = require("globals");
const { Linter } = require("eslint");
const Log = require("logger");

const rootPath = path.resolve(`${__dirname}/../`);
const Log = require(`${rootPath}/js/logger.js`);
const Utils = require(`${rootPath}/js/utils.js`);

const linter = new Linter({ configType: "flat" });
Expand Down
5 changes: 1 addition & 4 deletions js/utils.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
const path = require("node:path");

const rootPath = path.resolve(`${__dirname}/../`);
const Log = require(`${rootPath}/js/logger.js`);
const os = require("node:os");
const fs = require("node:fs");
const si = require("systeminformation");
const Log = require("logger");

const modulePositions = []; // will get list from index.html
const regionRegEx = /"region ([^"]*)/i;
Expand Down
4 changes: 2 additions & 2 deletions modules/default/calendar/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* use this script with `node debug.js` to test the fetcher without the need
* of starting the MagicMirror² core. Adjust the values below to your desire.
*/
// Alias modules mentioned in package.js under _moduleAliases.
require("module-alias/register");
// Load internal alias resolver
require("../../../js/alias-resolver");
const Log = require("logger");

const CalendarFetcher = require("./calendarfetcher");
Expand Down
32 changes: 15 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@
"helmet": "^8.1.0",
"html-to-text": "^9.0.5",
"iconv-lite": "^0.7.0",
"module-alias": "^2.2.3",
"moment": "^2.30.1",
"moment-timezone": "^0.6.0",
"node-ical": "^0.21.0",
Expand Down Expand Up @@ -121,9 +120,5 @@
},
"engines": {
"node": ">=22.18.0"
},
"_moduleAliases": {
"node_helper": "js/node_helper.js",
"logger": "js/logger.js"
}
}
Loading