Skip to content

Commit 3ca6732

Browse files
Add file in hh-core to handle hardhat configuration paths (#5498)
1 parent 29cef28 commit 3ca6732

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

pnpm-lock.yaml

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

v-next/core/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"exports": {
1616
".": "./dist/src/index.js",
1717
"./config": "./dist/src/config.js",
18+
"./global-dir": "./dist/src/global-dir.js",
1819
"./types/arguments": "./dist/src/types/arguments.js",
1920
"./types/cli": "./dist/src/types/cli.js",
2021
"./types/config": "./dist/src/types/config.js",
@@ -53,8 +54,8 @@
5354
],
5455
"devDependencies": {
5556
"@eslint-community/eslint-plugin-eslint-comments": "^4.3.0",
56-
"@microsoft/api-extractor": "^7.43.4",
5757
"@ignored/hardhat-vnext-node-test-reporter": "workspace:^3.0.0-next.2",
58+
"@microsoft/api-extractor": "^7.43.4",
5859
"@types/node": "^20.14.9",
5960
"@types/semver": "^7.5.8",
6061
"@typescript-eslint/eslint-plugin": "^7.7.1",
@@ -77,6 +78,7 @@
7778
"@ignored/hardhat-vnext-errors": "workspace:^3.0.0-next.2",
7879
"@ignored/hardhat-vnext-utils": "workspace:^3.0.0-next.2",
7980
"chalk": "^5.3.0",
81+
"env-paths": "^2.2.0",
8082
"semver": "^7.6.2"
8183
}
8284
}

v-next/core/src/global-dir.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { ensureDir } from "@ignored/hardhat-vnext-utils/fs";
2+
3+
/**
4+
* Returns the path to the hardhat configuration directory.
5+
*
6+
* @returns The path to the hardhat configuration directory.
7+
*/
8+
export async function getConfigDir(): Promise<string> {
9+
const { config } = await generatePaths();
10+
await ensureDir(config);
11+
return config;
12+
}
13+
14+
async function generatePaths(packageName = "hardhat") {
15+
const { default: envPaths } = await import("env-paths");
16+
return envPaths(packageName);
17+
}

v-next/core/test/global-dir.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import assert from "node:assert/strict";
2+
import { describe, it } from "node:test";
3+
4+
import { getConfigDir } from "../src/global-dir.js";
5+
6+
describe("global-dir", () => {
7+
describe("getGlobalDir", () => {
8+
it("should return the path to the configuration directory with default name 'hardhat'", async () => {
9+
const { default: envPaths } = await import("env-paths");
10+
const expectedPath = envPaths("hardhat").config;
11+
12+
assert.equal(await getConfigDir(), expectedPath);
13+
});
14+
});
15+
});

0 commit comments

Comments
 (0)