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

Add file in hh-utils to handle hardhat configuration paths #5491

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

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

2 changes: 2 additions & 0 deletions v-next/hardhat-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"./error": "./dist/src/error.js",
"./eth": "./dist/src/eth.js",
"./fs": "./dist/src/fs.js",
"./global-dir": "./dist/src/global-dir.js",
"./hex": "./dist/src/hex.js",
"./lang": "./dist/src/lang.js",
"./number": "./dist/src/number.js",
Expand Down Expand Up @@ -74,6 +75,7 @@
"typescript-eslint": "7.7.1"
},
"dependencies": {
"env-paths": "^2.2.0",
"fast-equals": "^5.0.1",
"keccak": "^3.0.4",
"rfdc": "^1.3.1",
Expand Down
17 changes: 17 additions & 0 deletions v-next/hardhat-utils/src/global-dir.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { ensureDir } from "./fs.js";

/**
* Returns the path to the hardhat configuration directory.
*
* @returns The path to the hardhat configuration directory.
*/
export async function getConfigDir(): Promise<string> {
const { config } = await generatePaths();
await ensureDir(config);
return config;
}

async function generatePaths(packageName = "hardhat") {
const { default: envPaths } = await import("env-paths");
return envPaths(packageName);
}
15 changes: 15 additions & 0 deletions v-next/hardhat-utils/test/global-dir.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import assert from "node:assert/strict";
import { describe, it } from "node:test";

import { getConfigDir } from "../src/global-dir.js";

describe("global-dir", () => {
describe("getGlobalDir", () => {
it("should return the path to the configuration directory with default name 'hardhat'", async () => {
const { default: envPaths } = await import("env-paths");
const expectedPath = envPaths("hardhat").config;

assert.equal(await getConfigDir(), expectedPath);
});
});
});