From 6e8f823cc9b433ad9c9d7ff0dc681d16f8614247 Mon Sep 17 00:00:00 2001 From: Michael Taylor Date: Fri, 20 May 2022 10:05:47 -0400 Subject: [PATCH] fix: dont dynamically import package.json --- src/config/config.cjs | 14 +------------- src/config/logger.cjs | 19 +------------------ src/utils/file-loader.js | 18 ------------------ src/utils/helpers.js | 3 +-- 4 files changed, 3 insertions(+), 51 deletions(-) delete mode 100644 src/utils/file-loader.js diff --git a/src/config/config.cjs b/src/config/config.cjs index 71bdfef9..5c20250f 100644 --- a/src/config/config.cjs +++ b/src/config/config.cjs @@ -6,29 +6,17 @@ const fs = require('fs'); const os = require('os'); const path = require('path'); const logger = require('./logger.cjs').logger; +const packageJson = require('../../package.json'); const homeDir = os.homedir(); const defaultConfig = require('../utils/defaultConfig.json'); const getDataModelVersion = () => { - const packageJson = fileLoader('package.json'); const version = packageJson.version; const majorVersion = version.split('.')[0]; return `v${majorVersion}`; }; -const fileLoader = _.memoize((filepath) => { - logger.debug(`Reading file at ${filepath}`); - - const file = path.resolve(filepath); - - try { - return yaml.load(fs.readFileSync(file, 'utf8')); - } catch (e) { - logger.error(`File not found at ${file}`, e); - } -}); - const persistanceFolder = `${homeDir}/.chia/climate-warehouse/${getDataModelVersion()}`; // Adding this duplicate function here because im having trouble diff --git a/src/config/logger.cjs b/src/config/logger.cjs index 664a1149..7c219a32 100644 --- a/src/config/logger.cjs +++ b/src/config/logger.cjs @@ -1,35 +1,18 @@ -const _ = require('lodash'); const winston = require('winston'); const { format, transports, createLogger } = winston; -const yaml = require('js-yaml'); const DailyRotateFile = require('winston-daily-rotate-file'); -const path = require('path'); const fs = require('fs'); const os = require('os'); const homeDir = os.homedir(); - -const fileLoader = _.memoize((filepath) => { - console.log(`Reading file at ${filepath}`); - - const file = path.resolve(filepath); - - try { - return yaml.load(fs.readFileSync(file, 'utf8')); - } catch (e) { - console.log(`File not found at ${file}`, e); - } -}); +const packageJson = require('../../package.json'); const getDataModelVersion = () => { - const packageJson = fileLoader('package.json'); const version = packageJson.version; const majorVersion = version.split('.')[0]; return `v${majorVersion}`; }; - - const logDir = `${homeDir}/.chia/climate-warehouse/${getDataModelVersion()}/logs`; if (!fs.existsSync(logDir)) { diff --git a/src/utils/file-loader.js b/src/utils/file-loader.js deleted file mode 100644 index 1f871e50..00000000 --- a/src/utils/file-loader.js +++ /dev/null @@ -1,18 +0,0 @@ -import _ from 'lodash'; -import yaml from 'js-yaml'; -import fs from 'fs'; -import path from 'path'; - -import { logger } from '../config/logger.cjs'; - -export const fileLoader = _.memoize((filepath) => { - logger.debug(`Reading file at ${filepath}`); - - const file = path.resolve(filepath); - - try { - return yaml.load(fs.readFileSync(file, 'utf8')); - } catch (e) { - logger.error(`File not found at ${file}`, e); - } -}); diff --git a/src/utils/helpers.js b/src/utils/helpers.js index d9f7e4c4..cbe17922 100644 --- a/src/utils/helpers.js +++ b/src/utils/helpers.js @@ -4,7 +4,7 @@ import _ from 'lodash'; import { isPluralized } from './string-utils.js'; import { formatModelAssociationName } from './model-utils.js'; -import { fileLoader } from './file-loader'; +import packageJson from '../../package.json'; export const paginationParams = (page, limit) => { if (page === undefined || limit === undefined) { @@ -78,7 +78,6 @@ export const columnsToInclude = (userColumns, foreignKeys) => { }; export const getDataModelVersion = () => { - const packageJson = fileLoader('package.json'); const version = packageJson.version; const majorVersion = version.split('.')[0]; return `v${majorVersion}`;