Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace require-relative with built-in require.resolve #4352

Merged
merged 2 commits into from Jan 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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