Skip to content

Suggest installing hardhat-foundry when appropriate#7919

Merged
alcuadrado merged 5 commits intohardhat-foundryfrom
suggest-hardhat-foundry
Feb 24, 2026
Merged

Suggest installing hardhat-foundry when appropriate#7919
alcuadrado merged 5 commits intohardhat-foundryfrom
suggest-hardhat-foundry

Conversation

@alcuadrado
Copy link
Copy Markdown
Member

@alcuadrado alcuadrado commented Jan 30, 2026

This PR detects when there's an import that can't be resolved in a package that has a foundry.toml and suggests reading the docs about it.

Docs PR: NomicFoundation/hardhat-website#215

@alcuadrado alcuadrado requested a review from Copilot January 30, 2026 18:02
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jan 30, 2026

🦋 Changeset detected

Latest commit: 421ab91

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

This PR includes changesets to release 1 package
Name Type
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

@alcuadrado alcuadrado force-pushed the suggest-hardhat-foundry branch from 21408d9 to 1f943fd Compare January 30, 2026 18:02
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds detection of Foundry projects and suggests installing the @nomicfoundation/hardhat-foundry plugin when users encounter uninstalled package errors in projects that use Foundry. The implementation tracks whether a project or npm dependency has a foundry.toml file and uses this information to provide more helpful error messages.

Changes:

  • Added fromHasFoundryToml field to error types for tracking Foundry project detection
  • Enhanced error messages to suggest installing hardhat-foundry plugin when appropriate
  • Added comprehensive test coverage for Foundry detection scenarios

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
v-next/hardhat/src/types/solidity/errors.ts Added optional fromHasFoundryToml field to uninstalled package error types
v-next/hardhat/src/internal/builtin-plugins/solidity/build-system/resolver/error-messages.ts Updated error messages to suggest hardhat-foundry plugin when Foundry is detected
v-next/hardhat/src/internal/builtin-plugins/solidity/build-system/resolver/dependency-resolver.ts Implemented foundry.toml detection logic and propagated the flag through error handling
v-next/hardhat/test/internal/builtin-plugins/solidity/build-system/resolver/dependency-resolver.ts Added test cases for Foundry detection in various scenarios

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread v-next/hardhat/src/types/solidity/errors.ts
@alcuadrado alcuadrado force-pushed the suggest-hardhat-foundry branch from a55f120 to c2a1ca9 Compare February 23, 2026 11:10
return `${baseMessage}

Your project has a foundry.toml, and you may need to install the "@nomicfoundation/hardhat-foundry" plugin.
Learn more about Hardhat's Foundry compatibility here: https://hardhat.org/foundry-compatibility`;
Copy link
Copy Markdown
Contributor

@marianfe marianfe Feb 23, 2026

Choose a reason for hiding this comment

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

this URL is currently a 404! UPDATE: just saw that it is sent as a next PR

* A boolean indicating if the Hardhat project has a foundry.toml file in its
* root.
*/
fromHasFoundryToml?: boolean;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i dont really follow the naming here (not sure what "from" means, maybe we mean the error originated from a project with foundry toml), would "projectHasFoundryToml" or simply "hasFoundryToml" be a clearer name?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good point. I renamed this one as projectHasFoundryToml

* A boolean indicating weather the import is from a source file whose package
* has a foundry.toml file in its root.
*/
fromHasFoundryToml?: boolean;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same here about the naming, see my other comment.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Renamed this as importerPackageHasFoundryToml. The name is more verbose than just packageHas.., but there are to packages in relation to this error, the importer and the imported.

@@ -57,7 +57,14 @@ Note that the npm module is being remapped by ${formatRemappingReference(error.u
}

case RootResolutionErrorType.NPM_ROOT_FILE_OF_UNINSTALLED_PACKAGE: {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

these errors message updates dont have a corresponding unit test to verify the behavior works with hasFoundryToml and without it. same for the one further below

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It has 100% coverage after d80c347, thanks!

Copy link
Copy Markdown
Contributor

@marianfe marianfe left a comment

Choose a reason for hiding this comment

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

LGTM with comments, please take a look, thanks!

@alcuadrado alcuadrado force-pushed the suggest-hardhat-foundry branch from d80c347 to 421ab91 Compare February 23, 2026 21:32
@alcuadrado alcuadrado merged commit 4ffff59 into hardhat-foundry Feb 24, 2026
207 of 209 checks passed
@alcuadrado alcuadrado deleted the suggest-hardhat-foundry branch February 24, 2026 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants