wighawag / hardhat-deploy

hardhat deployment plugin
MIT License
1.17k stars 283 forks source link

Add type annotation for hre object being passed to Javascript deployment scripts #507

Open daniel-mccloud opened 6 months ago

daniel-mccloud commented 6 months ago

Is your feature request related to a problem? Please describe. Vs code is able to read and apply type annotations so that interacting with the hre object becomes more fluid in Javascript language

Describe the solution you'd like I would like to have the same autocompletion and Intellisense functionality as shown in the picture: image

For example say you have a bunch of deployment scripts following the pattern:

module.exports = async ({ getNamedAccounts, deployments, network }) => {
  const args = []

  const { deploy } = deployments
  const { deployer } = await getNamedAccounts()
  await deploy('Alpha', {
    from: deployer,
    args,
    log: true
  })
}
module.exports.tags = ['Alpha']

Currently a developer would have to edit it to:

/**
 * @param {import('hardhat/types').HardhatRuntimeEnvironment} hre - Hardhat Runtime Environment
 */
module.exports = async ({ getNamedAccounts, deployments, network }) => {
  const args = []

  const { deploy } = deployments
  const { deployer } = await getNamedAccounts()
  await deploy('Alpha', {
    from: deployer,
    args,
    log: true
  })
}
module.exports.tags = ['Alpha']

But not all developers will be doing that because maybe they are not aware of this possibility or for any other reason will not do it. So ideally the type annotation should be applied on hardhat-deploy in a way there would be no need to add the type annotations here.

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

Additional context It would be also nice to have the ability to process .mjs and .cjs deployment scripts in deploy folder. Or to make the entire package modular with "type": "module" in package.json to process esm code in .js files within deploy folder just like node does.