hardhat icon indicating copy to clipboard operation
hardhat copied to clipboard

Ability to specify contracts to ignore in hardhat.config

Open 0xpApaSmURf opened this issue 2 years ago • 18 comments

Update by @fvictorio: If you are here looking for a way to use Hardhat and Foundry together, please take a look at this guide.


It would be very useful to have an additional property in hardhat.config.js that allows us to specify a list of files/paths to ignore from compilation.

module.exports = {
  ...
  ignoreFiles: [
    "InvalidContract.sol",
    "./contracts/*"
  ]
};

Can be specified to ignore:

  • Files that match the name
  • Directories/folders
  • Artifact name (contract name)

It is useful for cases where there are multiple contracts in development where some will not succeed in compiling and will produce an error if attempted but should not prevent the compilation of other valid contracts.

0xpApaSmURf avatar Jan 27 '22 13:01 0xpApaSmURf

+1 need this, especially when using hardhat in combo with test contracts using forge for instance

FredCoen avatar Jan 31 '22 09:01 FredCoen

+1 @FredCoen Came looking exactly because of this.

anudit avatar Feb 07 '22 08:02 anudit

+1 also need this please

Anyone find a reasonable workaround?

devtooligan avatar Feb 14 '22 18:02 devtooligan

+1

tynes avatar Feb 14 '22 19:02 tynes

You can ignore files doing something like this in your config:

const {subtask} = require("hardhat/config");
const {TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS} = require("hardhat/builtin-tasks/task-names")

subtask(TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS)
  .setAction(async (_, __, runSuper) => {
    const paths = await runSuper();

    return paths.filter(p => !p.endsWith(".t.sol"));
  });

alcuadrado avatar Feb 14 '22 19:02 alcuadrado

UPDATE:
I think a lot of people are coming here using Foundry/DappTools with HH and HH compile is choking on test files. The problem appears to be with the same cache folder used by Foundry and HH. Updating HH cache path solved this for me.

{
  ...,
  paths: { cache: 'hh-cache' }
}

h/t @alcuadrado

devtooligan avatar Feb 14 '22 19:02 devtooligan

This issue was marked as stale because it didn't have any activity in the last 30 days. If you think it's still relevant, please leave a comment indicating so. Otherwise, it will be closed in 7 days.

github-actions[bot] avatar Jun 11 '22 14:06 github-actions[bot]

need this feature badly

nmsteve avatar Jun 20 '22 16:06 nmsteve

This issue was closed because it has been stalled for 7 days with no activity.

github-actions[bot] avatar Jul 14 '22 12:07 github-actions[bot]

Hi, sorry for the autoclose. This is still something that we might do.

In the meantime, I created an example showing how this can be done manually: https://github.com/fvictorio/hardhat-examples/tree/master/ignore-solidity-files Check it out and let me know if you have any questions.

fvictorio avatar Jul 14 '22 13:07 fvictorio

+1

thurendous avatar Aug 06 '22 02:08 thurendous

yeah looking for this

thedavidmeister avatar Oct 02 '22 11:10 thedavidmeister

In the meantime, you can rename the js file and it will be skipped image

gaultierlecaillon avatar Oct 14 '22 19:10 gaultierlecaillon

For anyone that wants a simple solution, for my Hardhat template that integrates Foundry as well, I have the following folder structure:

├─ contracts
     ├─ lib
     ├─ src
     ├─ test
  • lib => foundry submodules like forge-std
  • src => the main contracts of the project
  • test => forge test files

Now, you can make the following simple configuration in the hardhat.config.ts file:

paths: {
  sources: "./contracts/src",
},

This will tell Hardhat to compile only the contracts in the src/ directory and no potential errors are thrown due to submodule imports (make sure you configure your remappings properly).

To run the forge tests, use:

forge test -vvv --root . -c contracts --match-path contracts/test/* --out forge-artifacts

pcaversaccio avatar Nov 27 '22 17:11 pcaversaccio

In the meantime, I created an example showing how this can be done manually: https://github.com/fvictorio/hardhat-examples/tree/master/ignore-solidity-files Check it out and let me know if you have any questions.

This hack helped me a ton. 👍 Thanks!

HH definitely should implement a clean way to exclude files/directories from compilation. The "status:ready" tag is encouraging.

AllTradesz avatar Feb 11 '23 13:02 AllTradesz

wen ignore ser?

Rubilmax avatar Feb 14 '23 11:02 Rubilmax

UPDATE: If you are here looking for a way to use Hardhat and Foundry together, please take a look at this guide.

alcuadrado avatar Feb 14 '23 13:02 alcuadrado

wen ignore ?

anistark avatar Apr 13 '24 10:04 anistark