Skip to content

Commit

Permalink
Use node prefix for build-in modules
Browse files Browse the repository at this point in the history
It is basically a cosmetic thing, but has the following advantages:

1. Consistency with the official node documentation. The prefix is also used there.
2. It is easier to recognize what build-in modules are.

Unfortunately, I have not found an ESLint rule for this.
  • Loading branch information
KristjanESPERANTO committed Jan 8, 2024
1 parent 407072d commit d8aab33
Show file tree
Hide file tree
Showing 24 changed files with 44 additions and 42 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ _This release is scheduled to be released on 2024-04-01._

### Updated

- Use node prefix for build-in modules

### Fixed

- Skip changelog requirement when running tests for dependency updates (#3320)
Expand Down
4 changes: 2 additions & 2 deletions clientonly/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
// Return new pending promise
return new Promise((resolve, reject) => {
// Select http or https module, depending on requested url
const lib = url.startsWith("https") ? require("https") : require("http");
const lib = url.startsWith("https") ? require("node:https") : require("node:http");
const request = lib.get(url, (response) => {
let configData = "";

Expand Down Expand Up @@ -94,7 +94,7 @@

// Spawn electron application
const electron = require("electron");
const child = require("child_process").spawn(electron, ["js/electron.js"], options);
const child = require("node:child_process").spawn(electron, ["js/electron.js"], options);

// Pipe all child process output to current stdout
child.stdout.on("data", function (buf) {
Expand Down
4 changes: 2 additions & 2 deletions js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
// Alias modules mentioned in package.js under _moduleAliases.
require("module-alias/register");

const fs = require("fs");
const path = require("path");
const fs = require("node:fs");
const path = require("node:path");
const envsub = require("envsub");
const Log = require("logger");

Expand Down
4 changes: 2 additions & 2 deletions js/check_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* By Rodrigo Ramírez Norambuena https://rodrigoramirez.com
* MIT Licensed.
*/
const path = require("path");
const fs = require("fs");
const path = require("node:path");
const fs = require("node:fs");
const { Linter } = require("eslint");

const linter = new Linter();
Expand Down
8 changes: 4 additions & 4 deletions js/server.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 fs = require("fs");
const http = require("http");
const https = require("https");
const path = require("path");
const fs = require("node:fs");
const http = require("node:http");
const https = require("node:https");
const path = require("node:path");
const express = require("express");
const ipfilter = require("express-ipfilter").IpFilter;
const helmet = require("helmet");
Expand Down
4 changes: 2 additions & 2 deletions js/server_functions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const fs = require("fs");
const path = require("path");
const fs = require("node:fs");
const path = require("node:path");
const Log = require("logger");

const startUp = new Date();
Expand Down
2 changes: 1 addition & 1 deletion js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* By Rodrigo Ramírez Norambuena https://rodrigoramirez.com
* MIT Licensed.
*/
const execSync = require("child_process").execSync;
const execSync = require("node:child_process").execSync;
const colors = require("colors/safe");
const Log = require("logger");
const si = require("systeminformation");
Expand Down
2 changes: 1 addition & 1 deletion modules/default/calendar/calendarfetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* MIT Licensed.
*/

const https = require("https");
const https = require("node:https");
const ical = require("node-ical");
const Log = require("logger");
const NodeHelper = require("node_helper");
Expand Down
2 changes: 1 addition & 1 deletion modules/default/calendar/calendarfetcherutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* @external Moment
*/
const path = require("path");
const path = require("node:path");
const moment = require("moment");

const zoneTable = require(path.join(__dirname, "windowsZones.json"));
Expand Down
2 changes: 1 addition & 1 deletion modules/default/newsfeed/newsfeedfetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* MIT Licensed.
*/

const stream = require("stream");
const stream = require("node:stream");
const FeedMe = require("feedme");
const iconv = require("iconv-lite");
const { htmlToText } = require("html-to-text");
Expand Down
8 changes: 4 additions & 4 deletions modules/default/updatenotification/git_helper.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const util = require("util");
const exec = util.promisify(require("child_process").exec);
const fs = require("fs");
const path = require("path");
const util = require("node:util");
const exec = util.promisify(require("node:child_process").exec);
const fs = require("node:fs");
const path = require("node:path");
const Log = require("logger");

const BASE_DIR = path.normalize(`${__dirname}/../../../`);
Expand Down
4 changes: 2 additions & 2 deletions modules/default/updatenotification/update_helper.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const Exec = require("child_process").exec;
const Spawn = require("child_process").spawn;
const Exec = require("node:child_process").exec;
const Spawn = require("node:child_process").spawn;
const commandExists = require("command-exists");
const Log = require("logger");

Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/fonts_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const helpers = require("./helpers/global-setup");
describe("All font files from roboto.css should be downloadable", () => {
const fontFiles = [];
// Statements below filters out all 'url' lines in the CSS file
const fileContent = require("fs").readFileSync(`${__dirname}/../../fonts/roboto.css`, "utf8");
const fileContent = require("node:fs").readFileSync(`${__dirname}/../../fonts/roboto.css`, "utf8");
const regex = /\burl\(['"]([^'"]+)['"]\)/g;
let match = regex.exec(fileContent);
while (match !== null) {
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/helpers/basic-auth.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const path = require("path");
const path = require("node:path");
const auth = require("express-basic-auth");
const express = require("express");

Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/serveronly_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe("App environment", () => {
let serverProcess;
beforeAll(async () => {
process.env.MM_CONFIG_FILE = "tests/configs/default.js";
serverProcess = await require("child_process").spawn("npm", ["run", "server"], { env: process.env, detached: true });
serverProcess = await require("node:child_process").spawn("npm", ["run", "server"], { env: process.env, detached: true });
// we have to wait until the server is startet
await delay(2000);
});
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/template_spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const fs = require("fs");
const fs = require("node:fs");
const helpers = require("./helpers/global-setup");

describe("templated config with port variable", () => {
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/translations_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const fs = require("fs");
const path = require("path");
const fs = require("node:fs");
const path = require("node:path");
const helmet = require("helmet");
const { JSDOM } = require("jsdom");
const express = require("express");
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/classes/class_spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const path = require("path");
const path = require("node:path");
const { JSDOM } = require("jsdom");

describe("File js/class", () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/classes/translator_spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const path = require("path");
const path = require("node:path");
const helmet = require("helmet");
const { JSDOM } = require("jsdom");
const express = require("express");
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/functions/cmp_versions_spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const path = require("path");
const path = require("node:path");
const { JSDOM } = require("jsdom");

describe("Test function cmpVersions in js/module.js", () => {
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/functions/updatenotification_spec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
jest.mock("util", () => ({
jest.mock("node:util", () => ({
...jest.requireActual("util"),
promisify: jest.fn()
}));

jest.mock("fs", () => ({
jest.mock("node:fs", () => ({
...jest.requireActual("fs"),
statSync: jest.fn()
}));
Expand All @@ -29,7 +29,7 @@ describe("Updatenotification", () => {
let gitTagListOut;

beforeAll(async () => {
const { promisify } = require("util");
const { promisify } = require("node:util");
promisify.mockReturnValue(execMock);

const GitHelper = require("../../../modules/default/updatenotification/git_helper");
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/global_vars/defaults_modules_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const fs = require("fs");
const path = require("path");
const fs = require("node:fs");
const path = require("node:path");

const root_path = path.join(__dirname, "../../..");

Expand Down
4 changes: 2 additions & 2 deletions tests/unit/global_vars/root_path_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const fs = require("fs");
const path = require("path");
const fs = require("node:fs");
const path = require("node:path");

const root_path = path.join(__dirname, "../../..");
const version = require(`${__dirname}/../../../package.json`).version;
Expand Down
8 changes: 4 additions & 4 deletions tests/utils/weather_mocker.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const fs = require("fs");
const path = require("path");
const util = require("util");
const exec = util.promisify(require("child_process").exec);
const fs = require("node:fs");
const path = require("node:path");
const util = require("node:util");
const exec = util.promisify(require("node:child_process").exec);
const _ = require("lodash");

/**
Expand Down

0 comments on commit d8aab33

Please sign in to comment.