Skip to content

Commit

Permalink
remove "require" and use "import" instead
Browse files Browse the repository at this point in the history
  • Loading branch information
jdeniau committed Oct 7, 2021
1 parent 8544e9b commit f67b004
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 18 deletions.
14 changes: 1 addition & 13 deletions src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
4 changes: 3 additions & 1 deletion src/config-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 7 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import fs from 'fs-extra';
import nodeProcess from 'process';

export const cwd = nodeProcess.cwd();
Expand All @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"esModuleInterop": true,
"target": "es2020",
"allowJs": true,
"resolveJsonModule": true
"resolveJsonModule": false
},
"include": ["./src/"]
}

0 comments on commit f67b004

Please sign in to comment.