Feat: es modules (#139)

* All file imports change from commonjs to es-module

* Improved plex error responses back from api

* Converted viewHistory to es module

* Es-module requires file extension, updated all imports

* Fix esmodule not having __dirname defined in scope

* Replace dynamic-require with fs readFileSync

* Short message service module function is exported as default

* Resolved lint issues & ignore import/extension rule until typescript

* All tests file imports changed from commonjs to es-module

* Import json fixtures with new helper
This commit was merged in pull request #139.
This commit is contained in:
2022-08-25 17:19:23 +02:00
committed by GitHub
parent 628ed52012
commit 7168950dfe
119 changed files with 624 additions and 527 deletions

View File

@@ -1,13 +1,17 @@
const path = require("path");
const Field = require("./field");
import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";
import Field from "./field.js";
let instance = null;
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
class Config {
constructor() {
this.location = Config.determineLocation();
// eslint-disable-next-line import/no-dynamic-require, global-require
this.fields = require(`${this.location}`);
this.fields = Config.readFileContents(this.location);
}
static getInstance() {
@@ -21,6 +25,17 @@ class Config {
return path.join(__dirname, "..", "..", process.env.SEASONED_CONFIG);
}
static readFileContents(location) {
let content = {};
try {
content = JSON.parse(fs.readFileSync(location, { encoding: "utf-8" }));
} catch (err) {
console.error(`Error loading configuration file at path: ${location}`);
}
return content;
}
get(section, option) {
if (
this.fields[section] === undefined ||
@@ -45,4 +60,4 @@ class Config {
}
}
module.exports = Config;
export default Config;

View File

@@ -12,4 +12,4 @@ class EnvironmentVariables {
}
}
module.exports = EnvironmentVariables;
export default EnvironmentVariables;

View File

@@ -1,5 +1,5 @@
const Filters = require("./filters");
const EnvironmentVariables = require("./environmentVariables");
import Filters from "./filters.js";
import EnvironmentVariables from "./environmentVariables.js";
class Field {
constructor(rawValue, environmentVariables) {
@@ -50,4 +50,4 @@ class Field {
}
}
module.exports = Field;
export default Field;

View File

@@ -31,4 +31,4 @@ class Filters {
}
}
module.exports = Filters;
export default Filters;