-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
5fcc4ea
to
3b674d1
Compare
3b674d1
to
d33a223
Compare
|
||
let parsedValue: ParameterValue; | ||
if (value !== undefined) { | ||
parsedValue = parseParameterValue(value, option.parameterType, name); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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> {} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issue created: #5431
There was a problem hiding this 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
Part of #5379
This should be easier to review by reviewing each commit individually.
Merge this after #5399