Skip to content

Commit d363318

Browse files
talentlessguyalcuadrado
authored andcommitted
replace find-up with empathic
1 parent 79acd9b commit d363318

File tree

7 files changed

+41
-89
lines changed

7 files changed

+41
-89
lines changed

packages/hardhat-core/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
"@types/chai-as-promised": "^7.1.3",
6767
"@types/ci-info": "^2.0.0",
6868
"@types/debug": "^4.1.4",
69-
"@types/find-up": "^2.1.1",
7069
"@types/fs-extra": "^5.1.0",
7170
"@types/keccak": "^3.0.1",
7271
"@types/lodash": "^4.14.123",
@@ -116,11 +115,11 @@
116115
"chokidar": "^4.0.0",
117116
"ci-info": "^2.0.0",
118117
"debug": "^4.1.1",
118+
"empathic": "^1.0.0",
119119
"enquirer": "^2.3.0",
120120
"env-paths": "^2.2.0",
121121
"ethereum-cryptography": "^1.0.3",
122122
"ethereumjs-abi": "^0.6.8",
123-
"find-up": "^2.1.0",
124123
"fp-ts": "1.19.3",
125124
"fs-extra": "^7.0.1",
126125
"immutable": "^4.0.0-rc.12",

packages/hardhat-core/src/internal/cli/autocomplete.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import findup from "find-up";
1+
import findup from "empathic/find.mjs";
22
import * as fs from "fs-extra";
33
import * as path from "path";
44

@@ -305,9 +305,9 @@ function getTaskFromTaskDefinition(taskDef: TaskDefinition): Task {
305305
}
306306

307307
function getProjectId(): string | undefined {
308-
const packageJsonPath = findup.sync("package.json");
308+
const packageJsonPath = findup.up("package.json");
309309

310-
if (packageJsonPath === null) {
310+
if (packageJsonPath === undefined) {
311311
return undefined;
312312
}
313313

packages/hardhat-core/src/internal/core/project-structure.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import findUp from "find-up";
1+
import findUp from "empathic/find.mjs";
22
import fsExtra from "fs-extra";
33
import path from "path";
44

@@ -14,31 +14,31 @@ const CTS_CONFIG_FILENAME = "hardhat.config.cts";
1414

1515
export function isCwdInsideProject() {
1616
return (
17-
findUp.sync(TS_CONFIG_FILENAME) !== null ||
18-
findUp.sync(CTS_CONFIG_FILENAME) !== null ||
19-
findUp.sync(CJS_CONFIG_FILENAME) !== null ||
20-
findUp.sync(JS_CONFIG_FILENAME) !== null
17+
findUp.up(TS_CONFIG_FILENAME) !== undefined ||
18+
findUp.up(CTS_CONFIG_FILENAME) !== undefined ||
19+
findUp.up(CJS_CONFIG_FILENAME) !== undefined ||
20+
findUp.up(JS_CONFIG_FILENAME) !== undefined
2121
);
2222
}
2323

2424
export function getUserConfigPath() {
25-
const tsConfigPath = findUp.sync(TS_CONFIG_FILENAME);
26-
if (tsConfigPath !== null) {
25+
const tsConfigPath = findUp.up(TS_CONFIG_FILENAME);
26+
if (tsConfigPath !== undefined) {
2727
return tsConfigPath;
2828
}
2929

30-
const ctsConfigPath = findUp.sync(CTS_CONFIG_FILENAME);
31-
if (ctsConfigPath !== null) {
30+
const ctsConfigPath = findUp.up(CTS_CONFIG_FILENAME);
31+
if (ctsConfigPath !== undefined) {
3232
return ctsConfigPath;
3333
}
3434

35-
const cjsConfigPath = findUp.sync(CJS_CONFIG_FILENAME);
36-
if (cjsConfigPath !== null) {
35+
const cjsConfigPath = findUp.up(CJS_CONFIG_FILENAME);
36+
if (cjsConfigPath !== undefined) {
3737
return cjsConfigPath;
3838
}
3939

40-
const pathToConfigFile = findUp.sync(JS_CONFIG_FILENAME);
41-
if (pathToConfigFile === null) {
40+
const pathToConfigFile = findUp.up(JS_CONFIG_FILENAME);
41+
if (pathToConfigFile === undefined) {
4242
throw new HardhatError(ERRORS.GENERAL.NOT_INSIDE_PROJECT);
4343
}
4444

packages/hardhat-core/src/internal/sentry/anonymizer.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Event, Exception, StackFrame, Stacktrace } from "@sentry/node";
2-
import findup from "find-up";
2+
import findup from "empathic/find.mjs";
33
import { either } from "fp-ts";
44
import * as path from "path";
55

@@ -59,7 +59,7 @@ export class Anonymizer {
5959
if (filename === this._configPath) {
6060
const packageJsonPath = this._getFilePackageJsonPath(filename);
6161

62-
if (packageJsonPath === null) {
62+
if (packageJsonPath === undefined) {
6363
// if we can't find a package.json, we just return the basename
6464
return {
6565
anonymizedFilename: path.basename(filename),
@@ -163,8 +163,8 @@ export class Anonymizer {
163163
return false;
164164
}
165165

166-
protected _getFilePackageJsonPath(filename: string): string | null {
167-
return findup.sync("package.json", {
166+
protected _getFilePackageJsonPath(filename: string): string | undefined {
167+
return findup.up("package.json", {
168168
cwd: path.dirname(filename),
169169
});
170170
}

packages/hardhat-core/src/internal/util/caller-package.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import findup from "find-up";
1+
import findup from "empathic/find.mjs";
22
import path from "path";
33

4-
function findClosestPackageJson(file: string): string | null {
5-
return findup.sync("package.json", { cwd: path.dirname(file) });
4+
function findClosestPackageJson(file: string): string | undefined {
5+
return findup.up("package.json", { cwd: path.dirname(file) });
66
}
77

88
/**
@@ -35,7 +35,7 @@ export function getClosestCallerPackage(): string | undefined {
3535
continue;
3636
}
3737

38-
if (callerPackage === null) {
38+
if (callerPackage === undefined) {
3939
return undefined;
4040
}
4141

packages/hardhat-core/src/internal/util/packageInfo.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import findup from "find-up";
1+
import findup from "empathic/find.mjs";
22
import fsExtra from "fs-extra";
33
import path from "path";
44

@@ -23,13 +23,13 @@ export interface PackageJson {
2323
};
2424
}
2525

26-
export function findClosestPackageJson(file: string): string | null {
27-
return findup.sync("package.json", { cwd: path.dirname(file) });
26+
export function findClosestPackageJson(file: string): string | undefined {
27+
return findup.up("package.json", { cwd: path.dirname(file) });
2828
}
2929

3030
export async function getPackageName(file: string): Promise<string> {
3131
const packageJsonPath = findClosestPackageJson(file);
32-
if (packageJsonPath !== null && packageJsonPath !== "") {
32+
if (packageJsonPath !== undefined && packageJsonPath !== "") {
3333
const packageJson: PackageJson = await fsExtra.readJSON(packageJsonPath);
3434
return packageJson.name;
3535
}
@@ -45,7 +45,7 @@ export function getHardhatVersion(): string {
4545
const packageJsonPath = findClosestPackageJson(__filename);
4646

4747
assertHardhatInvariant(
48-
packageJsonPath !== null,
48+
packageJsonPath !== undefined,
4949
"There should be a package.json in hardhat-core's root directory"
5050
);
5151

@@ -57,10 +57,10 @@ export function getHardhatVersion(): string {
5757
* Return the contents of the package.json in the user's project
5858
*/
5959
export function getProjectPackageJson(): Promise<any> {
60-
const packageJsonPath = findup.sync("package.json");
60+
const packageJsonPath = findup.up("package.json");
6161

6262
assertHardhatInvariant(
63-
packageJsonPath !== null,
63+
packageJsonPath !== undefined,
6464
"Expected a package.json file in the current directory or in an ancestor directory"
6565
);
6666

pnpm-lock.yaml

+9-56
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)