diff --git a/src/build.ts b/src/build.ts index a4d0031..f8e2b6a 100644 --- a/src/build.ts +++ b/src/build.ts @@ -5,22 +5,10 @@ import chalk from 'chalk'; import Theme from './theme.js'; import { debug, log } from './logging.js'; import { getModuleConfigEntry } from './config-utils.js'; -import { getModuleFullPath } from './utils.js'; +import { getModuleNameForPath } from './utils.js'; export const cwd = nodeProcess.cwd(); -const moduleNameByPath: { [key: string]: string } = {}; - -function getModuleNameForPath(path: string): string { - if (!moduleNameByPath[path]) { - moduleNameByPath[path] = require(`${getModuleFullPath( - path - )}/package.json`).name; - } - - return moduleNameByPath[path]; -} - /** * get the command to call for the package */ diff --git a/src/config-utils.ts b/src/config-utils.ts index 44a918c..0c54cd4 100644 --- a/src/config-utils.ts +++ b/src/config-utils.ts @@ -61,7 +61,9 @@ function getGlobalConfig(): Config { try { // eslint-disable-next-line @typescript-eslint/no-var-requires - config = require(`${configPath}/${CONFIG_FILE_NAME}`); + config = JSON.parse( + fs.readFileSync(`${configPath}/${CONFIG_FILE_NAME}`, { encoding: 'utf8' }) + ); } catch (e) {} //eslint-disable-line no-empty globalConfigCache = config; diff --git a/src/utils.ts b/src/utils.ts index b6da507..129ad30 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,3 +1,4 @@ +import fs from 'fs-extra'; import nodeProcess from 'process'; export const cwd = nodeProcess.cwd(); @@ -10,9 +11,12 @@ export function getModuleFullPath(path: string): string { export function getModuleNameForPath(path: string): string { if (!moduleNameByPath[path]) { - moduleNameByPath[path] = require(`${getModuleFullPath( - path - )}/package.json`).name; + const fullPath = `${getModuleFullPath(path)}/package.json`; + const packageJsonContent = fs.readFileSync(fullPath, { + encoding: 'utf8', + }); + const packageJson = JSON.parse(packageJsonContent); + moduleNameByPath[path] = packageJson.name; } return moduleNameByPath[path]; diff --git a/tsconfig.json b/tsconfig.json index be19450..c340744 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,7 +8,7 @@ "esModuleInterop": true, "target": "es2020", "allowJs": true, - "resolveJsonModule": true + "resolveJsonModule": false }, "include": ["./src/"] }