diff --git a/.changeset/calm-clouds-work.md b/.changeset/calm-clouds-work.md new file mode 100644 index 00000000000..b9217f3d6dd --- /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. 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 21c68be5364..065fdf284da 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 30fb56f6b89..13ea0cc8d03 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 @@ -217,13 +217,6 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem { ); }), ); - - await this.#hooks.runHandlerChain( - "solidity", - "onAllArtifactsEmitted", - [contractArtifactsGeneratedByCompilationJob], - async () => {}, - ); } const resultsMap: Map = new Map(); @@ -663,6 +656,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 9bfaf3a78c5..69c3e5a1da0 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; }