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

(feat) return updated config in integration hooks #9013

Merged
merged 11 commits into from
Nov 30, 2023
Merged

(feat) return updated config in integration hooks #9013

merged 11 commits into from
Nov 30, 2023

Conversation

nerdoza
Copy link
Contributor

@nerdoza nerdoza commented Nov 6, 2023

Changes

Summary of change in this discussion thread: withastro/roadmap#762

  • In the astro:config:setup hook for integrations, calls to updateConfig now return a destructured instance of the updated configuration.
  • Changes updateConfig property to be strongly typed deep partial of the AstroConfig type.

Testing

  • Unit test was added to astro/test/units/integrations/api.test.js.
  • Tested bundle against another package using AstroAdapter in a local environment.

Docs

Copy link

changeset-bot bot commented Nov 6, 2023

🦋 Changeset detected

Latest commit: 60fea6e

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added pkg: astro Related to the core `astro` package (scope) pr: docs A PR that includes documentation for review labels Nov 6, 2023
@florian-lefebvre
Copy link
Member

florian-lefebvre commented Nov 7, 2023

Really cool! I know this is not the initial goal of this PR but it would great to type the newConfig argument (Partial<AstroConfig>?)

@github-actions github-actions bot added pkg: solid Related to Solid (scope) pkg: integration Related to any renderer integration (scope) labels Nov 7, 2023
@nerdoza
Copy link
Contributor Author

nerdoza commented Nov 7, 2023

@florian-lefebvre, good point. Added.

@nerdoza nerdoza changed the title [DNM] (feat) return updated config in integration hooks (feat) return updated config in integration hooks Nov 7, 2023
@@ -374,6 +375,7 @@ export async function runHookBuildSetup({
target,
updateConfig: (newConfig) => {
updatedConfig = mergeConfig(updatedConfig, newConfig);
return { ...updatedConfig };
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this a spread? Does it need to be cloned?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's spread in the original declaration for updatedConfig, so I'm just maintaining consistency. The object is pretty deep so this feels like it should either be a true clone or a read-only object, but those both seem a bit outside the scope of this issue.

Ref:

let updatedConfig: AstroConfig = { ...settings.config };
let updatedSettings: AstroSettings = { ...settings, config: updatedConfig };
let addedClientDirectives = new Map<string, Promise<string>>();
let astroJSXRenderer: AstroRenderer | null = null;

@matthewp
Copy link
Contributor

We're going to do a final patch for Astro 3.x, then once that is done this will be merged in and be part of Astro 4.0.

@@ -2311,7 +2311,7 @@ export interface AstroIntegration {
config: AstroConfig;
command: 'dev' | 'build' | 'preview';
isRestart: boolean;
updateConfig: (newConfig: Record<string, any>) => void;
updateConfig: (newConfig: DeepPartial<AstroConfig>) => AstroConfig;
Copy link
Contributor

Choose a reason for hiding this comment

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

This certainly is a lot better than before, but it could maybe give a false sense of safety. {} is technically Partial<URL>, for example.

Copy link
Contributor

Choose a reason for hiding this comment

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

It would be an edge case admittedly, and the runtime logic might actually handle it too. I'll take a closer look when I can, but I'm not blocking a merge.

Copy link
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

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

Will be merging this for Astro 4 soon.

@bluwy bluwy merged commit ff8eadb into withastro:main Nov 30, 2023
14 checks passed
This was referenced Nov 30, 2023
@nerdoza nerdoza deleted the feat/update-config-response branch November 30, 2023 16:13
This was referenced Nov 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope) pkg: integration Related to any renderer integration (scope) pkg: solid Related to Solid (scope) pr: docs A PR that includes documentation for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants