Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolveGlobalArguments implementation & testing #5414

Merged
merged 8 commits into from
Jun 25, 2024
Merged

Conversation

schaable
Copy link
Member

Part of #5379

This should be easier to review by reviewing each commit individually.

Merge this after #5399

@schaable schaable added the v-next A Hardhat v3 development task label Jun 19, 2024
@schaable schaable self-assigned this Jun 19, 2024
Copy link

vercel bot commented Jun 19, 2024

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 25, 2024 2:27pm

Copy link

changeset-bot bot commented Jun 19, 2024

⚠️ No Changeset found

Latest commit: 665a755

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

@github-actions github-actions bot added the status:ready This issue is ready to be worked on label Jun 19, 2024
Base automatically changed from build-global-param to v-next June 19, 2024 22:25
@zoeyTM
Copy link
Contributor

zoeyTM commented Jun 24, 2024

@schaable now that #5417 has been merged, this PR will need rebasing and will need to also follow the new name scheme. i.e. resolveGlobalArguments becomes resolveGlobalOptions, etc.

@schaable
Copy link
Member Author

@schaable now that #5417 has been merged, this PR will need rebasing and will need to also follow the new name scheme. i.e. resolveGlobalArguments becomes resolveGlobalOptions, etc.

done!


let parsedValue: ParameterValue;
if (value !== undefined) {
parsedValue = parseParameterValue(value, option.parameterType, name);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is trying to parse the userProvidedGlobalOptions's values.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if those are provided, they should already be parsed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 665a755

@@ -25,7 +29,7 @@ export interface GlobalOption<T extends ParameterType = ParameterType> {
* Runtime Environment.
*/
// eslint-disable-next-line @typescript-eslint/no-empty-interface -- To be used through module augmentation
export interface GlobalOptions {}
export interface GlobalOptions extends Record<string, ParameterValue> {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will be a bit annoying, as you can do globalOptions.thisDoesntExist and you wouldn't get a type error

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What motivated it? We may find an alternative

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I remember correctly, this was done to avoid an error when assigning the parsed value to the global options. As the interface is empty, this throws a TS error: globalOptions[name] = parsedValue;

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'GlobalOptions'.
No index signature with a parameter of type 'string' was found on type 'GlobalOptions'.ts(7053)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 22abbd5

@@ -0,0 +1,30 @@
import { afterEach } from "node:test";

export function createTestEnvManager() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is pretty nice


const globalOptions = resolveGlobalOptions(
{
param1: "false",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is an example of a param that should already be parsed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a good way to think about this is: first the cli parses the cli arguments, then the hre is initialized, using those arguments, which requires resolving like this.

/**
* Parses a parameter value from a string to the corresponding type.
*/
// TODO: this code is duplicated in v-next/hardhat/src/internal/cli/main.ts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think exposing these things from core makes sense. We already expose functions like this. e.g. resolvePluginList.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I'll do it on a separate PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue created: #5431

Copy link
Member

@alcuadrado alcuadrado left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few small-ish comments

@schaable schaable requested a review from alcuadrado June 25, 2024 14:30
@schaable schaable merged commit b62a981 into v-next Jun 25, 2024
50 checks passed
@schaable schaable deleted the resolve-global-args branch June 25, 2024 15:20
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status:ready This issue is ready to be worked on v-next A Hardhat v3 development task
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants