Skip to content

feat: config update hook#9325

Merged
zkochan merged 18 commits intomainfrom
config-hook
Mar 31, 2025
Merged

feat: config update hook#9325
zkochan merged 18 commits intomainfrom
config-hook

Conversation

@zkochan
Copy link
Member

@zkochan zkochan commented Mar 24, 2025

Related comment https://github.com/orgs/pnpm/discussions/9037#discussioncomment-12389019

I am not describing this in the changeset yet as I want to test it more before spreading the word. The goal of this hook is too allow sharing settings via configurational dependencies.

@zkochan zkochan force-pushed the config-hook branch 2 times, most recently from 6010b2f to a3c5083 Compare March 28, 2025 06:34
@zkochan zkochan marked this pull request as ready for review March 28, 2025 07:19
@zkochan zkochan requested a review from a team March 28, 2025 09:07
@zkochan zkochan changed the title feat: config read hook feat: config update hook Mar 28, 2025
Copy link
Member

@gluxon gluxon left a comment

Choose a reason for hiding this comment

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

This is cool! 🚀

@@ -13,7 +16,7 @@ export async function getConfig (
ignoreNonAuthSettingsFromLocal?: boolean
}
): Promise<Config> {
Copy link
Member

Choose a reason for hiding this comment

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

Is the intention of this function to support async updateConfig hooks? At the moment users can provide async implementations. That mostly works because async functions can return promises, and that gets flattened automatically.

If the intention isn't to support async updateConfig, I would check the return type to make sure it's not a promise. If it is intentional, could we await the config.hooks.updateConfig call for correctness?

Copy link
Member Author

Choose a reason for hiding this comment

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

ok, added support for async updateConfig

Copy link
Member

Choose a reason for hiding this comment

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

Thanks!

}

if (opts.excludeReporter) {
delete config.reporter // This is a silly workaround because @pnpm/core expects a function as opts.reporter
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if it's intentional that config.hooks.updateConfig can be a promise returning function, but a heads up that this piece of code won't work as expected if config is a promise.

@zkochan zkochan merged commit 1413c25 into main Mar 31, 2025
15 of 16 checks passed
@zkochan zkochan deleted the config-hook branch March 31, 2025 06:08
@zkochan
Copy link
Member Author

zkochan commented Apr 7, 2025

The problem with this way of extending settings is that Renovate doesn't allow the execution of hooks. So, if updateConfig extends overrides, for instance, Renovate will ignore that. Long term, we probably need a static way of extending settings with config dependencies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants