hardhat
hardhat copied to clipboard
Ability to specify contracts to ignore in hardhat.config
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.
+1 need this, especially when using hardhat in combo with test contracts using forge for instance
+1 @FredCoen Came looking exactly because of this.
+1 also need this please
Anyone find a reasonable workaround?
+1
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"));
});
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
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.
need this feature badly
This issue was closed because it has been stalled for 7 days with no activity.
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.
+1
yeah looking for this
In the meantime, you can rename the js file and it will be skipped
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 likeforge-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
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.
wen ignore ser?
UPDATE: If you are here looking for a way to use Hardhat and Foundry together, please take a look at this guide.
wen ignore ?