-
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.
Merge pull request #5734 from NomicFoundation/feature/move-global-dir…
…-into-hh-utils Move the global-dir functions from hardhat to harhdat-utils
- Loading branch information
Showing
12 changed files
with
126 additions
and
52 deletions.
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,51 @@ | ||
import { generatePaths, HARDHAT_PACKAGE_NAME } from "./internal/global-dir.js"; | ||
|
||
import { ensureDir } from "@ignored/hardhat-vnext-utils/fs"; | ||
|
||
/** | ||
* Returns the configuration directory path for a given package (defaults to "hardhat"). | ||
* Ensures that the directory exists before returning the path. | ||
* | ||
* @param packageName The name of the package for which to generate paths. Defaults to "hardhat" if no package name is provided. | ||
* @returns The path to the hardhat configuration directory. | ||
* @throws FileSystemAccessError for any error. | ||
*/ | ||
export async function getConfigDir( | ||
packageName: string = HARDHAT_PACKAGE_NAME, | ||
): Promise<string> { | ||
const { config } = await generatePaths(packageName); | ||
await ensureDir(config); | ||
return config; | ||
} | ||
|
||
/** | ||
* Returns the cache directory path for a given package (defaults to "hardhat"). | ||
* Ensures that the directory exists before returning the path. | ||
* | ||
* @param packageName The name of the package for which to generate paths. Defaults to "hardhat" if no package name is provided. | ||
* @returns The path to the hardhat cache directory. | ||
* @throws FileSystemAccessError for any error. | ||
*/ | ||
export async function getCacheDir( | ||
packageName: string = HARDHAT_PACKAGE_NAME, | ||
): Promise<string> { | ||
const { cache } = await generatePaths(packageName); | ||
await ensureDir(cache); | ||
return cache; | ||
} | ||
|
||
/** | ||
* Returns the telemetry directory path for a given package (defaults to "hardhat"). | ||
* Ensures that the directory exists before returning the path. | ||
* | ||
* @param packageName The name of the package for which to generate paths. Defaults to "hardhat" if no package name is provided. | ||
* @returns A promise that resolves to the path of the telemetry directory. | ||
* @throws FileSystemAccessError for any error. | ||
*/ | ||
export async function getTelemetryDir( | ||
packageName: string = HARDHAT_PACKAGE_NAME, | ||
): Promise<string> { | ||
const { data } = await generatePaths(packageName); | ||
await ensureDir(data); | ||
return data; | ||
} |
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,10 @@ | ||
import type envPaths from "env-paths"; | ||
|
||
export const HARDHAT_PACKAGE_NAME = "hardhat"; | ||
|
||
export async function generatePaths( | ||
packageName: string, | ||
): Promise<envPaths.Paths> { | ||
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,54 @@ | ||
import assert from "node:assert/strict"; | ||
import { describe, it } from "node:test"; | ||
|
||
import { | ||
getCacheDir, | ||
getConfigDir, | ||
getTelemetryDir, | ||
} from "../src/global-dir.js"; | ||
|
||
async function getExpectedPath(packageName: string) { | ||
const { default: envPaths } = await import("env-paths"); | ||
return envPaths(packageName); | ||
} | ||
|
||
describe("global-dir", () => { | ||
const HARDHAT_PACKAGE_NAME = "hardhat"; | ||
const CUSTOM_PACKAGE_NAME = "custom-name"; | ||
|
||
describe("getConfigDir", () => { | ||
it("should return the path to the configuration directory with default name 'hardhat'", async () => { | ||
const path = await getConfigDir(); | ||
assert.equal(path, (await getExpectedPath(HARDHAT_PACKAGE_NAME)).config); | ||
}); | ||
|
||
it("should return the path to the configuration directory with custom name", async () => { | ||
const path = await getConfigDir(CUSTOM_PACKAGE_NAME); | ||
assert.equal(path, (await getExpectedPath(CUSTOM_PACKAGE_NAME)).config); | ||
}); | ||
}); | ||
|
||
describe("getCacheDir", () => { | ||
it("should return the path to the cache directory with default name 'hardhat'", async () => { | ||
const path = await getCacheDir(); | ||
assert.equal(path, (await getExpectedPath(HARDHAT_PACKAGE_NAME)).cache); | ||
}); | ||
|
||
it("should return the path to the cache directory with custom name", async () => { | ||
const path = await getCacheDir(CUSTOM_PACKAGE_NAME); | ||
assert.equal(path, (await getExpectedPath(CUSTOM_PACKAGE_NAME)).cache); | ||
}); | ||
}); | ||
|
||
describe("getTelemetryDir", () => { | ||
it("should return the path to the telemetry directory with default name 'hardhat'", async () => { | ||
const path = await getTelemetryDir(); | ||
assert.equal(path, (await getExpectedPath(HARDHAT_PACKAGE_NAME)).data); | ||
}); | ||
|
||
it("should return the path to the telemetry directory with custom name", async () => { | ||
const path = await getTelemetryDir(CUSTOM_PACKAGE_NAME); | ||
assert.equal(path, (await getExpectedPath(CUSTOM_PACKAGE_NAME)).data); | ||
}); | ||
}); | ||
}); |
3 changes: 1 addition & 2 deletions
3
v-next/hardhat/src/internal/builtin-plugins/clean/task-action.ts
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
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
This file was deleted.
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