11/* eslint @typescript-eslint/no-non-null-assertion: ["off"] */
22
3- import { HardhatUserConfig } from "hardhat/config" ;
3+ import { HardhatUserConfig , subtask } from "hardhat/config" ;
44import type { MultiSolcUserConfig } from "hardhat/src/types/config" ;
5+ import { TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS } from "hardhat/builtin-tasks/task-names" ;
56/* Uncomment if support of TypeScript `paths` mappings is needed.
67 * Make sure to run `pnpm add -D "tsconfig-paths@4.2.0"` in this case.
78 */
@@ -22,6 +23,22 @@ dotenv.config();
2223
2324import "./scripts/tasks/generate-account" ;
2425
26+ /* Sets the action for the `TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS` task.
27+ *
28+ * The approach to ignore Solidity files in `test` directories for Hardhat speeds up its compilation process
29+ * significantly. This is especially true in large projects with a lot of Foundry tests.
30+ * It can be also extended for deployment scripts as well.
31+ * See for more details:
32+ * `https://kennysliding.medium.com/how-to-ignore-solidity-files-in-hardhat-compilation-6162963f8c84`
33+ */
34+ subtask ( TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS ) . setAction ( async ( _ , __ , runSuper ) => {
35+ /* Get the list of source paths that would normally be passed to the Solidity compiler, then
36+ * apply a filter function to exclude paths that contain the string "test".
37+ */
38+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
39+ return ( await runSuper ( ) ) . filter ( ( p : any ) => ! p . includes ( "test" ) ) ;
40+ } ) ;
41+
2542const envs = process . env ;
2643
2744// Private keys can be set in `.env` file.
0 commit comments