Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace imports with new aliases #2934

Closed
Closed
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
5 changes: 1 addition & 4 deletions js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@
* MIT Licensed.
*/

// Alias modules mentioned in package.js under _moduleAliases.
require("module-alias/register");

const fs = require("fs");
const path = require("path");
const Log = require("logger");
const Log = require("#logger");
const Server = require(`${__dirname}/server`);
const Utils = require(`${__dirname}/utils`);
const defaultModules = require(`${__dirname}/../modules/default/defaultmodules`);
Expand Down
2 changes: 1 addition & 1 deletion js/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const electron = require("electron");
const core = require("./app.js");
const Log = require("logger");
const Log = require("#logger");

// Config
let config = process.env.config ? JSON.parse(process.env.config) : {};
Expand Down
2 changes: 1 addition & 1 deletion js/node_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* MIT Licensed.
*/
const Class = require("./class.js");
const Log = require("logger");
const Log = require("#logger");
const express = require("express");

const NodeHelper = Class.extend({
Expand Down
4 changes: 2 additions & 2 deletions js/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ const path = require("path");
const ipfilter = require("express-ipfilter").IpFilter;
const fs = require("fs");
const helmet = require("helmet");
const fetch = require("fetch");
const fetch = require("#fetch");

const Log = require("logger");
const Log = require("#logger");
const Utils = require("./utils.js");

/**
Expand Down
6 changes: 3 additions & 3 deletions modules/default/calendar/calendarfetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
* MIT Licensed.
*/
const CalendarUtils = require("./calendarutils");
const Log = require("logger");
const NodeHelper = require("node_helper");
const Log = require("#logger");
const NodeHelper = require("#node_helper");
const ical = require("node-ical");
const fetch = require("fetch");
const fetch = require("#fetch");
const digest = require("digest-fetch");
const https = require("https");

Expand Down
4 changes: 2 additions & 2 deletions modules/default/calendar/node_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* By Michael Teeuw https://michaelteeuw.nl
* MIT Licensed.
*/
const NodeHelper = require("node_helper");
const NodeHelper = require("#node_helper");
const CalendarFetcher = require("./calendarfetcher.js");
const Log = require("logger");
const Log = require("#logger");

module.exports = NodeHelper.create({
// Override start method.
Expand Down
6 changes: 3 additions & 3 deletions modules/default/newsfeed/newsfeedfetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
* By Michael Teeuw https://michaelteeuw.nl
* MIT Licensed.
*/
const Log = require("logger");
const Log = require("#logger");
const FeedMe = require("feedme");
const NodeHelper = require("node_helper");
const fetch = require("fetch");
const NodeHelper = require("#node_helper");
const fetch = require("#fetch");
const iconv = require("iconv-lite");
const stream = require("stream");

Expand Down
4 changes: 2 additions & 2 deletions modules/default/newsfeed/node_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
* MIT Licensed.
*/

const NodeHelper = require("node_helper");
const NodeHelper = require("#node_helper");
const NewsfeedFetcher = require("./newsfeedfetcher.js");
const Log = require("logger");
const Log = require("#logger");

module.exports = NodeHelper.create({
// Override start method.
Expand Down
2 changes: 1 addition & 1 deletion modules/default/updatenotification/git_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const util = require("util");
const exec = util.promisify(require("child_process").exec);
const fs = require("fs");
const path = require("path");
const Log = require("logger");
const Log = require("#logger");

const BASE_DIR = path.normalize(`${__dirname}/../../../`);

Expand Down
2 changes: 1 addition & 1 deletion modules/default/updatenotification/node_helper.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const GitHelper = require("./git_helper");
const defaultModules = require("../defaultmodules");
const NodeHelper = require("node_helper");
const NodeHelper = require("#node_helper");

const ONE_MINUTE = 60 * 1000;

Expand Down
11 changes: 0 additions & 11 deletions package-lock.json

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

15 changes: 10 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,21 @@
"helmet": "^6.0.0",
"iconv-lite": "^0.6.3",
"luxon": "^1.28.0",
"module-alias": "^2.2.2",
"moment": "^2.29.4",
"node-fetch": "^2.6.7",
"node-ical": "^0.15.1",
"socket.io": "^4.5.2"
},
"_moduleAliases": {
"node_helper": "js/node_helper.js",
"logger": "js/logger.js",
"fetch": "js/fetch.js"
"imports": {
"#logger": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it also work if we omit the #?

Copy link
Collaborator

@rejas rejas Oct 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to https://nodejs.org/api/packages.html#packages_imports the imports must start with a # :-(

Copy link
Author

@thesebas thesebas Oct 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think it is done to avoid conflicts with real npm modules. Using fetch and logger aliases while real modules already exist seems risky.

"default": "./js/logger.js"
},
"#node_helper": {
"default": "./js/node_helper.js"
},
"#fetch": {
"default": "./js/fetch.js"
}
},
"engines": {
"node": ">=14"
Expand Down
2 changes: 1 addition & 1 deletion serveronly/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const app = require("../js/app.js");
const Log = require("logger");
const Log = require("#logger");

app.start((config) => {
const bindAddress = config.address ? config.address : "localhost";
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/functions/updatenotification_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ describe("Updatenotification", () => {
const repos = await gitHelper.getRepos();
expect(repos.length).toBe(0);

const { error } = require("logger");
const { error } = require("#logger");
expect(error).toHaveBeenCalledWith(`Failed to retrieve repo info for ${moduleName}: Failed to retrieve status`);
});

Expand Down