A new defineIntegration
helper
#886
Replies: 7 comments 33 replies
-
+1 😄 I like the |
Beta Was this translation helpful? Give feedback.
-
Love the idea of an official helper! Big +1! Should this live in Astro though? If I'm designing an integration as an external package, then Astro isn't usually a dependency of my package (I don't think). As an integration author I'd actually prefer it to be an external dependency of my package, and then I could manage major versions myself vs. having to build for the I'd expect this use-case of a |
Beta Was this translation helpful? Give feedback.
-
Thanks for kicking this off @florian-lefebvre! My feedback at this stage is that the goals are a little vague and could use being more specific. A breakdown of what I mean:
|
Beta Was this translation helpful? Give feedback.
-
I updated the RFC, please have another look! |
Beta Was this translation helpful? Give feedback.
-
I still don't think we should do schemas as part of this API. Having the type param as shown in the updated example I think is what we should recommend. I would rather schemas be something that stays inside of a 3rd party library like integration kit. At least for now, we can add layer. Keeping this API small and focused on providing types for the shape of the integration hooks (as shown in the example) is the way to go, imo. |
Beta Was this translation helpful? Give feedback.
-
TLDR: -1 for me, but I'll explain below 😄 About
|
Beta Was this translation helpful? Give feedback.
-
I want to get back to this RFC now that I'm mostly done with |
Beta Was this translation helpful? Give feedback.
-
Body
Summary
Adds a new
defineIntegration
helper to Astro to help integrations authors define integrations in a convenient/robust way.Background & Motivation
We've been working on the Astro Integration Kit since January with other fellow maintainers and Astro community members. The goal is to improve the DX of integrations authors and make their lives easier, allowing more people to start writing integrations as well.
It's a set of utilities we plan to contribute back to Astro and we're starting today with
defineIntegration
!Defining an integration but the DX could be improved using a function helper rather than just having the
AstroIntegration
type. Also, handling correctly options (so that it's both type and runtime safe) is overlooked by many people. We took inspiration from Starlight and experimented with it for a few months before feeling we have it right, but we need your feedback!Goals
defineConfig
Example
defineIntegration
, the vanilla waydefineIntegration
would not be a simple type helper likedefineConfig
that returnsAstroUserConfig
, but pretty close. Instead, it would return(options: Options) => AstroIntegration
.defineIntegration
is already available for usage in AIK, read docs. View source code here.defineIntegration
, the zod wayMatthew had concerns about only providing a zod compatible utility so I introduced the above alternative. However, people wanting to use zod could use a
defineIntergation.withZod
utility that would behave exactly the same as the AIK version. See docs and source.Backward compatibility
defineIntegration
returnsAstroIntegration
so it's compatible. We talked about a potential@astrojs/kit
package to have backward compatible utilities, but after some discussions with Erika I think it's better not to have it. If integrations authors want to benefit from new hooks params, they should update their peer deps. That should encourage more users to upgrade to more recent versions of Astro, and the process is painless anyway. Note that this meansdefineIntegration
will only be available from the minor it's part of.Beta Was this translation helpful? Give feedback.
All reactions