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

[Investigation] Config overrides should be based on merging the user config, not the resolved #6490

Draft
wants to merge 4 commits into
base: v-next
Choose a base branch
from

Conversation

ChristopherDedominici
Copy link
Contributor

No description provided.

Copy link

changeset-bot bot commented Mar 20, 2025

⚠️ No Changeset found

Latest commit: 4b1b8d8

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

Copy link

vercel bot commented Mar 20, 2025

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 Mar 21, 2025 4:06pm

@@ -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;
Copy link
Contributor Author

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?)

Copy link
Contributor Author

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

Copy link
Member

@schaable schaable Mar 21, 2025

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?

Copy link
Contributor Author

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(
Copy link
Contributor Author

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

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 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 = {
Copy link
Contributor Author

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

Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no changeset needed This PR doesn't require a changeset
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

3 participants