rhlsthrm / hardhat-typechain

TypeChain tasks for Buidler
MIT License
18 stars 13 forks source link

Make typechain auto-generation opt-in #12

Open shark0der opened 3 years ago

shark0der commented 3 years ago

The recently added zero-config feature that overrides the compile task to generate typechain should be opt-in. Although there is a flag to turn it off for the compile task when running it from the command-line, there's no way to stop it from running when running other tasks that automatically compile the contracts. Specifically, when running the test task - the typechain is generated and there's no way to stop this.

My current workflow triggers hardhat test to be run whenever a test is changed (watching file changes using nodemon) and typechain generation adds a few extra seconds to this loop thus slowing down the development.

My config:

  typechain: {
    outDir: 'types',
    target: 'truffle-v5',
    runOnCompile: false,
  },

Behavior:

$ hh test
Creating Typechain artifacts in directory types for target truffle-v5
Successfully generated Typechain artifacts!

  Contract
    ✓ test

$ hh test --no-typechain
Error HH305: Unrecognized param --no-typechain

For more info go to https://hardhat.org/HH305 or run Hardhat with --show-stack-traces

package.json:

{
  "name": "hardhat-project",
  "dependencies": {
    "@nomiclabs/hardhat-truffle5": "^2.0.0",
    "@nomiclabs/hardhat-web3": "^2.0.0",
    "@typechain/truffle-v5": "^2.0.2",
    "hardhat": "^2.0.3",
    "hardhat-typechain": "^0.3.3",
    "ts-generator": "^0.1.1",
    "typechain": "^3.0.0",
    "web3": "^1.3.0"
  },
  "devDependencies": {
    "chai": "^4.2.0",
    "mocha": "^8.2.1",
    "nodemon": "^2.0.6"
  },
  "scripts": {
    "compile": "hardhat compile",
    "dev": "nodemon --ext js,sol -x 'hardhat test --show-stack-traces'",
    "typechain": "hardhat typechain"
  }
}

Please make this feature opt-in!

alcuadrado commented 3 years ago

@shark0der would you be ok with it being opt out if it were only run when new contracts were actually compiled?

nmclrn commented 3 years ago

@alcuadrado I am not OP but I have the same problem. Personally I'd prefer it was opt-in, or at least that I can opt-out for all tasks and not just compile. Quite often contracts are changed in a way that does not affect types.

I'm all for sensible config defaults and perhaps enabling this by default is fine for most users, but making any step that takes noticeable elapsed time compulsory feels like it's going too far.

By the way - great plugin - thank you!

matthewlilley commented 3 years ago

@shark0der would you be ok with it being opt out if it were only run when new contracts were actually compiled?

Only running when contracts change. Yes! Also the option to opt-out globally via direct hardhat flag. Appears to not work when passing to hardhat directly, e.g. hardhat --no-typechain coverage results in "Unrecognized param --no-typechain"