Skip to content

Commit 055a7bf

Browse files
authored
refactor: replace require-relative with built-in require.resolve (#4352)
1 parent 7c2823e commit 055a7bf

4 files changed

Lines changed: 4 additions & 26 deletions

File tree

LICENSE.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -583,13 +583,6 @@ Repository: git://github.com/paulmillr/readdirp.git
583583
584584
---------------------------------------
585585

586-
## require-relative
587-
License: MIT
588-
By: Valerio Proietti
589-
Repository: git://github.com/kamicane/require-relative.git
590-
591-
---------------------------------------
592-
593586
## signal-exit
594587
License: ISC
595588
By: Ben Coe

cli/run/getConfigPath.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
import { readdirSync } from 'fs';
22
import { resolve } from 'path';
3-
import relative from 'require-relative';
3+
import { cwd } from 'process';
44
import { handleError } from '../logging';
55

66
const DEFAULT_CONFIG_BASE = 'rollup.config';
77

88
export function getConfigPath(commandConfig: string | true): string {
9-
const cwd = process.cwd();
109
if (commandConfig === true) {
1110
return resolve(findConfigFileNameInCwd());
1211
}
1312
if (commandConfig.slice(0, 5) === 'node:') {
1413
const pkgName = commandConfig.slice(5);
1514
try {
16-
return relative.resolve(`rollup-config-${pkgName}`, cwd);
15+
return require.resolve(`rollup-config-${pkgName}`, { paths: [cwd()] });
1716
} catch {
1817
try {
19-
return relative.resolve(pkgName, cwd);
18+
return require.resolve(pkgName, { paths: [cwd()] });
2019
} catch (err: any) {
2120
if (err.code === 'MODULE_NOT_FOUND') {
2221
handleError({
@@ -32,7 +31,7 @@ export function getConfigPath(commandConfig: string | true): string {
3231
}
3332

3433
function findConfigFileNameInCwd(): string {
35-
const filesInWorkingDir = new Set(readdirSync(process.cwd()));
34+
const filesInWorkingDir = new Set(readdirSync(cwd()));
3635
for (const extension of ['mjs', 'cjs', 'ts']) {
3736
const fileName = `${DEFAULT_CONFIG_BASE}.${extension}`;
3837
if (filesInWorkingDir.has(fileName)) return fileName;

package-lock.json

Lines changed: 0 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767
"@rollup/plugin-typescript": "^8.2.5",
6868
"@rollup/pluginutils": "^4.1.2",
6969
"@types/node": "^10.17.60",
70-
"@types/require-relative": "^0.8.0",
7170
"@types/signal-exit": "^3.0.1",
7271
"@types/yargs-parser": "^20.2.1",
7372
"@typescript-eslint/eslint-plugin": "^5.10.0",
@@ -100,7 +99,6 @@
10099
"prettier": "^2.5.1",
101100
"pretty-bytes": "^5.6.0",
102101
"pretty-ms": "^7.0.1",
103-
"require-relative": "^0.8.7",
104102
"requirejs": "^2.3.6",
105103
"rollup": "^2.64.0",
106104
"rollup-plugin-license": "^2.6.1",

0 commit comments

Comments
 (0)