NomicFoundation / hardhat

Hardhat is a development environment to compile, deploy, test, and debug your Ethereum software.
https://hardhat.org
Other
7.22k stars 1.38k forks source link

Implement logic for the --version cli global argument #5384

Closed ChristopherDedominici closed 3 months ago

ChristopherDedominici commented 3 months ago

Task description

This PR should be merged first.

CHANGES:

vercel[bot] commented 3 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
hardhat ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 17, 2024 10:54pm
changeset-bot[bot] commented 3 months ago

⚠️ No Changeset found

Latest commit: fa7a2bf443d722f9fc47194b167a9675ac2eba00

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

ChristopherDedominici commented 3 months ago

@alcuadrado @schaable should we export the function "getHardhatVersion" outside of the hh-utils package so I can use it here too? Do you think that this function could be used in multiple places a part from here?

schaable commented 3 months ago

@alcuadrado @schaable should we export the function "getHardhatVersion" outside of the hh-utils package so I can use it here too? Do you think that this function could be used in multiple places a part from here?

I thought about this when I was working on the utils. It is also useful for the User-Agent header in the request module, but I didn't add it because the implementation was not trivial. Here, you can read the closest package.json relative to import.meta.url to get the version. However, if you run the same code within hardhat-utils, you'll get the version of that package. You'd need to navigate up the node_modules structure, find Hardhat, and return its version. Alternatively, you could accept the file URL relative to the package.json as a parameter, but at that point, it is not that different from what you have in this PR. We may want to add this as a utility within the Hardhat package itself.