hardhat icon indicating copy to clipboard operation
hardhat copied to clipboard

Files with compiler overrides should be specifiable using globs

Open theodale opened this issue 2 years ago • 1 comments

Describe the feature

Currently, it appears that you have to specify each file for which you want to override the compiler:

 overrides: {
      "contracts/my-protocol/my-contract.sol": {
          // override settings
    },
},

This option should accept globs to allow overriding batches of files at a time:

 overrides: {
      "contracts/**/*.sol": {
          // override settings
    },
},

This would help when overriding nested directories of contracts, e.g., cloned third-party projects when integrating.

Search terms

No response

theodale avatar Dec 15 '23 12:12 theodale

Thanks @theodale, I think this is a reasonable ask.

As a workaround, you can do this programmatically using the glob package. Something like this (tentative code, I haven't tried it):

const glob = require("glob");

const files = glob.sync("contracts/some-dir/**/*.sol");
const overriddenSolcConfig = { /* ... */ };

const overrides = Object.fromEntries(files.map(file => [file, overriddenSolcConfig]));

One problem with this is that it assumes that the cwd is the root of the project, but this is almost always the case. You can probably make it more robust by combining __dirname with path.relative.

fvictorio avatar Dec 27 '23 11:12 fvictorio