Skip to content

[Typechain] generate types only for contracts and not test files#6400

Merged
ChristopherDedominici merged 4 commits intov-nextfrom
typechain-do-not-build-test-files
Mar 18, 2025
Merged

[Typechain] generate types only for contracts and not test files#6400
ChristopherDedominici merged 4 commits intov-nextfrom
typechain-do-not-build-test-files

Conversation

@ChristopherDedominici
Copy link
Contributor

@changeset-bot
Copy link

changeset-bot bot commented Feb 24, 2025

🦋 Changeset detected

Latest commit: e5d48d1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@nomicfoundation/hardhat-typechain Patch
hardhat Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Feb 24, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
hardhat ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 4, 2025 3:41pm

getDuplicatedContractNamesDeclarationFile(duplicatedNames),
);

await this.#hooks.runHandlerChain(
Copy link
Contributor Author

@ChristopherDedominici ChristopherDedominici Feb 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pato mentioned that probably this is the best place to add a hook that can emit the artifacts paths.
His message:
I think that we should change the moment when we generate the typechain types. Its now on build, but i believe it should be in cleanArtifacts. That already generates some typescript types for the artifacts. Especially when there are clashes between names. This would mean removing the hook, creating a new one after cleanupArtifacts, and using that one instead.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would mean we generate types only when the entire project is compiled - see

// If we recompiled the entire project we cleanup the artifacts
- which, as far as I understand, is not necessarily what we want.

To be fair, I also find hooking types generation to the cleanup step a little confusing. It is not obvious to know what the type generation has to do with cleanup without deeply understanding the internals. I think there might be some potential for the refactor in the cleanup function, but that's definitely out of the scope of this PR.

However, as far as when the type generation should get triggered, maybe it should be when the artifacts are emitted after all. But maybe we could add some option to the build and consequently emitArtifacts to control whether artifact declaration files -

- are emitted. Then, we could either propagate that option via the hook system or check whether the declaration file exists for a given artifact on the typechain side. There definitely might be better options, just thinking out loud.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think your points are valid, but would require further exploration, @galargh . I'd say we merge this PR and revaluate this soon.

One reason that can make the generation require clenup to be run is that you can have name clashes.


export interface SolidityHooks {
/**
* Provide a handler for this hook to retrieve all artifacts created by a compilation job.
Copy link
Contributor Author

@ChristopherDedominici ChristopherDedominici Feb 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old hook can be removed in favor of the new one. See previous comment for more details

@@ -0,0 +1,6 @@
---
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need a double check on this changeset, is this format acceptable for the v-next?

@ChristopherDedominici ChristopherDedominici added this pull request to the merge queue Mar 18, 2025
Merged via the queue into v-next with commit 05ecb87 Mar 18, 2025
76 checks passed
@ChristopherDedominici ChristopherDedominici deleted the typechain-do-not-build-test-files branch March 18, 2025 13:22
@github-project-automation github-project-automation bot moved this from In Review to Done in Hardhat Mar 18, 2025
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 15, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

v-next A Hardhat v3 development task

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

[Typechain] generate types only for contracts and not test files

4 participants