-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Typechain] generate types only for contracts and not test files #6400
Open
ChristopherDedominici
wants to merge
4
commits into
v-next
Choose a base branch
from
typechain-do-not-build-test-files
base: v-next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
02f2980
remove old hook and add a new one
ChristopherDedominici 739f6b3
Create calm-clouds-work.md
ChristopherDedominici bf8df70
Merge branch 'v-next' into typechain-do-not-build-test-files
ChristopherDedominici e5d48d1
Merge branch 'v-next' into typechain-do-not-build-test-files
kanej File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
15 changes: 5 additions & 10 deletions
15
v-next/hardhat-typechain/src/internal/hook-handlers/solidity.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
* 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<CompilationJob, ReadonlyMap<string, string[]>>, | ||
artifactPaths: string[], | ||
next: ( | ||
nextContext: HookContext, | ||
artifacts: Map<CompilationJob, ReadonlyMap<string, string[]>>, | ||
artifactPaths: string[], | ||
) => Promise<void>, | ||
) => Promise<void>; | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
hardhat/v-next/hardhat/src/internal/builtin-plugins/solidity/tasks/compile.ts
Line 37 in 4554b50
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 consequentlyemitArtifacts
to control whether artifact declaration files -hardhat/v-next/hardhat/src/internal/builtin-plugins/solidity/build-system/build-system.ts
Line 527 in 4554b50