-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add file in hh-core to handle hardhat configuration paths (#5498)
- Loading branch information
1 parent
29cef28
commit 3ca6732
Showing
4 changed files
with
38 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
}); |