Skip to content

Commit

Permalink
Add file in hh-core to handle hardhat configuration paths (#5498)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherDedominici authored Jul 9, 2024
1 parent 29cef28 commit 3ca6732
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
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.

4 changes: 3 additions & 1 deletion v-next/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"exports": {
".": "./dist/src/index.js",
"./config": "./dist/src/config.js",
"./global-dir": "./dist/src/global-dir.js",
"./types/arguments": "./dist/src/types/arguments.js",
"./types/cli": "./dist/src/types/cli.js",
"./types/config": "./dist/src/types/config.js",
Expand Down Expand Up @@ -53,8 +54,8 @@
],
"devDependencies": {
"@eslint-community/eslint-plugin-eslint-comments": "^4.3.0",
"@microsoft/api-extractor": "^7.43.4",
"@ignored/hardhat-vnext-node-test-reporter": "workspace:^3.0.0-next.2",
"@microsoft/api-extractor": "^7.43.4",
"@types/node": "^20.14.9",
"@types/semver": "^7.5.8",
"@typescript-eslint/eslint-plugin": "^7.7.1",
Expand All @@ -77,6 +78,7 @@
"@ignored/hardhat-vnext-errors": "workspace:^3.0.0-next.2",
"@ignored/hardhat-vnext-utils": "workspace:^3.0.0-next.2",
"chalk": "^5.3.0",
"env-paths": "^2.2.0",
"semver": "^7.6.2"
}
}
17 changes: 17 additions & 0 deletions v-next/core/src/global-dir.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { ensureDir } from "@ignored/hardhat-vnext-utils/fs";

/**
* 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/core/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);
});
});
});

0 comments on commit 3ca6732

Please sign in to comment.