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-core to handle hardhat configuration paths #5498

Merged
merged 2 commits into from
Jul 9, 2024
Merged
Changes from 1 commit
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
Next Next commit
add method to get global path + test
ChristopherDedominici committed Jul 9, 2024
commit f65f63b6a2cd725b215cb35d4828190ea578ea2d
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.

3 changes: 2 additions & 1 deletion v-next/core/package.json
Original file line number Diff line number Diff line change
@@ -53,8 +53,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",
@@ -77,6 +77,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);
});
});
});