-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
[Investigation] Config overrides should be based on merging the user config, not the resolved #6490
base: v-next
Are you sure you want to change the base?
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@@ -5,6 +5,10 @@ export default async (): Promise<Partial<HardhatRuntimeEnvironmentHooks>> => ({ | |||
created: async (context, hre) => { | |||
let networkManager: NetworkManager | undefined; | |||
|
|||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- TMP | |||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- TMP | |||
const userConfigNetworks = (hre as any).userConfig.networks; |
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.
hre
already have userConfig.networks
but it does not currenlty exist in the type definition (I wonder why?)
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 configuration is NOT resolved yet
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.
wait, you're saying that we're already setting hre.userConfig
somewhere in the code?
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.
yes exactly, it is already available. Here I'm casting to any just to avoid compilation error during my investigation. I can console.log the userConnfig
@@ -149,6 +149,28 @@ export function resolveNetworkConfigOverride( | |||
); | |||
} | |||
|
|||
export function resolveNetworkConfig( |
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.
an helper method to resolve the configuration based on the type
property. I didn't fin an already existing one
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 fine, but you could improve it further by also using it in the hook handler
this.#networkConfigs[resolvedNetworkName], | ||
); | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/consistent-type-assertions -- tmp | ||
const newConfig: NetworkUserConfig = { |
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.
since the configurations are NOT resolved, a merge between object using ...
is possible
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.
the problem is that spread only does a shallow merge:
a = { b: { c: 1 } }
a1 = { b: { d: 1 }, e: 3 }
console.log({ ...a, ...a1 }) // { b: { d: 1 }, e: 3 }
If you want to override just mining.interval, you’d ideally only pass { mining: { interval: 123 } } as an override to the connect call. Using a spread forces you to pass all the mining properties, even if you only want to change one.
No description provided.