Skip to content

Commit

Permalink
refactor: replace require-relative with built-in require.resolve (#4352)
Browse files Browse the repository at this point in the history
  • Loading branch information
dnalborczyk committed Jan 18, 2022
1 parent 7c2823e commit 055a7bf
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 26 deletions.
7 changes: 0 additions & 7 deletions LICENSE.md
Expand Up @@ -583,13 +583,6 @@ Repository: git://github.com/paulmillr/readdirp.git
---------------------------------------

## require-relative
License: MIT
By: Valerio Proietti
Repository: git://github.com/kamicane/require-relative.git

---------------------------------------

## signal-exit
License: ISC
By: Ben Coe
Expand Down
9 changes: 4 additions & 5 deletions cli/run/getConfigPath.ts
@@ -1,22 +1,21 @@
import { readdirSync } from 'fs';
import { resolve } from 'path';
import relative from 'require-relative';
import { cwd } from 'process';
import { handleError } from '../logging';

const DEFAULT_CONFIG_BASE = 'rollup.config';

export function getConfigPath(commandConfig: string | true): string {
const cwd = process.cwd();
if (commandConfig === true) {
return resolve(findConfigFileNameInCwd());
}
if (commandConfig.slice(0, 5) === 'node:') {
const pkgName = commandConfig.slice(5);
try {
return relative.resolve(`rollup-config-${pkgName}`, cwd);
return require.resolve(`rollup-config-${pkgName}`, { paths: [cwd()] });
} catch {
try {
return relative.resolve(pkgName, cwd);
return require.resolve(pkgName, { paths: [cwd()] });
} catch (err: any) {
if (err.code === 'MODULE_NOT_FOUND') {
handleError({
Expand All @@ -32,7 +31,7 @@ export function getConfigPath(commandConfig: string | true): string {
}

function findConfigFileNameInCwd(): string {
const filesInWorkingDir = new Set(readdirSync(process.cwd()));
const filesInWorkingDir = new Set(readdirSync(cwd()));
for (const extension of ['mjs', 'cjs', 'ts']) {
const fileName = `${DEFAULT_CONFIG_BASE}.${extension}`;
if (filesInWorkingDir.has(fileName)) return fileName;
Expand Down
12 changes: 0 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions package.json
Expand Up @@ -67,7 +67,6 @@
"@rollup/plugin-typescript": "^8.2.5",
"@rollup/pluginutils": "^4.1.2",
"@types/node": "^10.17.60",
"@types/require-relative": "^0.8.0",
"@types/signal-exit": "^3.0.1",
"@types/yargs-parser": "^20.2.1",
"@typescript-eslint/eslint-plugin": "^5.10.0",
Expand Down Expand Up @@ -100,7 +99,6 @@
"prettier": "^2.5.1",
"pretty-bytes": "^5.6.0",
"pretty-ms": "^7.0.1",
"require-relative": "^0.8.7",
"requirejs": "^2.3.6",
"rollup": "^2.64.0",
"rollup-plugin-license": "^2.6.1",
Expand Down

0 comments on commit 055a7bf

Please sign in to comment.