From 02f2980d97a85b05d97cba61896a4beff8a52e72 Mon Sep 17 00:00:00 2001 From: ChrisD <18092467+ChristopherDedominici@users.noreply.github.com> Date: Mon, 24 Feb 2025 14:47:26 +0100 Subject: [PATCH 1/2] remove old hook and add a new one --- .../src/internal/hook-handlers/solidity.ts | 15 +++++---------- .../solidity/build-system/build-system.ts | 14 +++++++------- .../builtin-plugins/solidity/type-extensions.ts | 14 +++++++------- 3 files changed, 19 insertions(+), 24 deletions(-) diff --git a/v-next/hardhat-typechain/src/internal/hook-handlers/solidity.ts b/v-next/hardhat-typechain/src/internal/hook-handlers/solidity.ts index 21c68be536..065fdf284d 100644 --- a/v-next/hardhat-typechain/src/internal/hook-handlers/solidity.ts +++ b/v-next/hardhat-typechain/src/internal/hook-handlers/solidity.ts @@ -1,30 +1,25 @@ import type { HookContext, SolidityHooks } from "hardhat/types/hooks"; -import type { CompilationJob } from "hardhat/types/solidity"; import { generateTypes } from "../generate-types.js"; export default async (): Promise> => { const handlers: Partial = { - async onAllArtifactsEmitted( + async onCleanUpArtifacts( context: HookContext, - artifacts: Map>, + artifactPaths: string[], next: ( nextContext: HookContext, - artifacts: Map>, + artifactPaths: string[], ) => Promise, ) { - const artifactsPaths = Array.from(artifacts.values()).flatMap( - (innerMap) => Array.from(innerMap.values()).flat(), - ); - await generateTypes( context.config.paths.root, context.config.typechain, context.globalOptions.noTypechain, - artifactsPaths, + artifactPaths, ); - return next(context, artifacts); + return next(context, artifactPaths); }, }; diff --git a/v-next/hardhat/src/internal/builtin-plugins/solidity/build-system/build-system.ts b/v-next/hardhat/src/internal/builtin-plugins/solidity/build-system/build-system.ts index 5f4a20b21e..6cd9431730 100644 --- a/v-next/hardhat/src/internal/builtin-plugins/solidity/build-system/build-system.ts +++ b/v-next/hardhat/src/internal/builtin-plugins/solidity/build-system/build-system.ts @@ -211,13 +211,6 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem { ); }), ); - - await this.#hooks.runHandlerChain( - "solidity", - "onAllArtifactsEmitted", - [contractArtifactsGeneratedByCompilationJob], - async () => {}, - ); } const resultsMap: Map = new Map(); @@ -645,6 +638,13 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem { duplicatedContractNamesDeclarationFilePath, getDuplicatedContractNamesDeclarationFile(duplicatedNames), ); + + await this.#hooks.runHandlerChain( + "solidity", + "onCleanUpArtifacts", + [artifactPaths], + async () => {}, + ); } public async compileBuildInfo( diff --git a/v-next/hardhat/src/internal/builtin-plugins/solidity/type-extensions.ts b/v-next/hardhat/src/internal/builtin-plugins/solidity/type-extensions.ts index 9bfaf3a78c..69c3e5a1da 100644 --- a/v-next/hardhat/src/internal/builtin-plugins/solidity/type-extensions.ts +++ b/v-next/hardhat/src/internal/builtin-plugins/solidity/type-extensions.ts @@ -1,5 +1,4 @@ import type { SolidityBuildSystem } from "../../../types/solidity/build-system.js"; -import type { CompilationJob } from "../../../types/solidity.js"; import "../../../types/config.js"; declare module "../../../types/config.js" { @@ -99,19 +98,20 @@ declare module "../../../types/hooks.js" { export interface SolidityHooks { /** - * Provide a handler for this hook to retrieve all artifacts created by a compilation job. + * Hook triggered during the cleanup process of Solidity compilation artifacts. + * This hook runs after unused artifacts and build-info files have been removed. * * @param context The hook context. - * @param artifacts A map of the artifacts created by each compilation job. + * @param artifactPaths The file paths of artifacts that remain after cleanup. * @param next A function to call the next handler for this hook, or the - * default implementation if there are no more handlers. + * default implementation if no more handlers exist. */ - onAllArtifactsEmitted: ( + onCleanUpArtifacts: ( context: HookContext, - artifacts: Map>, + artifactPaths: string[], next: ( nextContext: HookContext, - artifacts: Map>, + artifactPaths: string[], ) => Promise, ) => Promise; } From 739f6b3d81c7d0c1e6aada56862db092a6bf25a3 Mon Sep 17 00:00:00 2001 From: Christopher Dedominici <18092467+ChristopherDedominici@users.noreply.github.com> Date: Mon, 24 Feb 2025 15:06:59 +0100 Subject: [PATCH 2/2] Create calm-clouds-work.md --- .changeset/calm-clouds-work.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/calm-clouds-work.md diff --git a/.changeset/calm-clouds-work.md b/.changeset/calm-clouds-work.md new file mode 100644 index 0000000000..b9217f3d6d --- /dev/null +++ b/.changeset/calm-clouds-work.md @@ -0,0 +1,6 @@ +--- +"@nomicfoundation/hardhat-typechain": patch +"hardhat": patch +--- + +Replaced the hook for emitting compiled artifacts and updated its usage in the `hardhat-typechain` plugin.