florian-lefebvre / astro-integration-kit

A package that contains utilities to help you build Astro integrations.
https://astro-integration-kit.netlify.app
MIT License
46 stars 8 forks source link

Support new "astro:db:setup" hook #79

Closed Adammatthiesen closed 3 months ago

Adammatthiesen commented 4 months ago

Since they added new support for Astro DB the hooks changed. would be nice to get a patch that

  1. Updates the already existing AIK Extended hooks to use the new Astro v4.5 Hooks 2. adds support to tie into @astrojs/db's new hooks
florian-lefebvre commented 4 months ago

That means AIK 0.7.0 will only support 4.5 and above I guess? That's a bit annoying 🤔 but maybe @Fryuni you know how to best deal with it? I mean is there a smart way with peer dependencies and stuff?

florian-lefebvre commented 4 months ago

https://docs.astro.build/en/guides/astro-db/#building-astro-db-integrations, it's not part of the integrations api reference just yet

Adammatthiesen commented 4 months ago

Oh I see! I saw both the cloudflare & ExpressiveCode repo's where having typing issues, kinda had the same issues locally with all my AIK integrations which made me think there might be a typing issue going on again... maybe its just pnpm being weird then...

on another note, maybe we need a AstroDB AIK plugin since its still external and not internal! which IMO is a good thing... I'd be willing to help with it! im just not to sure how how this advanced hooks work yet... still learning!

Adammatthiesen commented 4 months ago

Actually, this is currently popping up in my astro-gists playground when i look at the integrations list...

Type 'AstroIntegration' is not assignable to type 'false | AstroIntegration | (false | AstroIntegration | null | undefined)[] | null | undefined'.
  Type 'import("E:/git-repo/astro-gists/node_modules/.pnpm/astro@4.4.11/node_modules/astro/dist/@types/astro").AstroIntegration' is not assignable to type 'import("E:/git-repo/astro-gists/node_modules/.pnpm/astro@4.5.0_@types+node@20.11.25_typescript@5.4.2/node_modules/astro/dist/@types/astro").AstroIntegration'.
    The types of 'hooks['astro:config:setup']' are incompatible between these types.
      Type '((options: { config: import("E:/git-repo/astro-gists/node_modules/.pnpm/astro@4.4.11/node_modules/astro/dist/@types/astro").AstroConfig; command: "dev" | "build" | "preview"; ... 10 more ...; logger: import("E:/git-repo/astro-gists/node_modules/.pnpm/astro@4.4.11/node_modules/astro/dist/core/logger/core").AstroInteg...' is not assignable to type '((options: { config: import("E:/git-repo/astro-gists/node_modules/.pnpm/astro@4.5.0_@types+node@20.11.25_typescript@5.4.2/node_modules/astro/dist/@types/astro").AstroConfig; ... 11 more ...; logger: import("E:/git-repo/astro-gists/node_modules/.pnpm/astro@4.5.0_@types+node@20.11.25_typescript@5.4.2/node_modules/astr...'.
        Type '(options: { config: import("E:/git-repo/astro-gists/node_modules/.pnpm/astro@4.4.11/node_modules/astro/dist/@types/astro").AstroConfig; command: "dev" | "build" | "preview"; isRestart: boolean; ... 9 more ...; logger: import("E:/git-repo/astro-gists/node_modules/.pnpm/astro@4.4.11/node_modules/astro/dist/core/logger...' is not assignable to type '(options: { config: import("E:/git-repo/astro-gists/node_modules/.pnpm/astro@4.5.0_@types+node@20.11.25_typescript@5.4.2/node_modules/astro/dist/@types/astro").AstroConfig; ... 11 more ...; logger: import("E:/git-repo/astro-gists/node_modules/.pnpm/astro@4.5.0_@types+node@20.11.25_typescript@5.4.2/node_modules/astro...'.
          Types of parameters 'options' and 'options' are incompatible.
            Type '{ config: import("E:/git-repo/astro-gists/node_modules/.pnpm/astro@4.5.0_@types+node@20.11.25_typescript@5.4.2/node_modules/astro/dist/@types/astro").AstroConfig; command: "dev" | ... 1 more ... | "preview"; ... 10 more ...; logger: import("E:/git-repo/astro-gists/node_modules/.pnpm/astro@4.5.0_@types+node@20.11.25_...' is not assignable to type '{ config: import("E:/git-repo/astro-gists/node_modules/.pnpm/astro@4.4.11/node_modules/astro/dist/@types/astro").AstroConfig; command: "dev" | "build" | "preview"; isRestart: boolean; ... 9 more ...; logger: import("E:/git-repo/astro-gists/node_modules/.pnpm/astro@4.4.11/node_modules/astro/dist/core/logger/core").As...'.
              The types of 'config.integrations' are incompatible between these types.
                Type 'import("E:/git-repo/astro-gists/node_modules/.pnpm/astro@4.5.0_@types+node@20.11.25_typescript@5.4.2/node_modules/astro/dist/@types/astro").AstroIntegration[]' is not assignable to type 'import("E:/git-repo/astro-gists/node_modules/.pnpm/astro@4.4.11/node_modules/astro/dist/@types/astro").AstroIntegration[]'.
                  Type 'import("E:/git-repo/astro-gists/node_modules/.pnpm/astro@4.5.0_@types+node@20.11.25_typescript@5.4.2/node_modules/astro/dist/@types/astro").AstroIntegration' is not assignable to type 'import("E:/git-repo/astro-gists/node_modules/.pnpm/astro@4.4.11/node_modules/astro/dist/@types/astro").AstroIntegration'.
                    The types of 'hooks['astro:config:setup']' are incompatible between these types.
                      Type '((options: { config: import("E:/git-repo/astro-gists/node_modules/.pnpm/astro@4.5.0_@types+node@20.11.25_typescript@5.4.2/node_modules/astro/dist/@types/astro").AstroConfig; ... 11 more ...; logger: import("E:/git-repo/astro-gists/node_modules/.pnpm/astro@4.5.0_@types+node@20.11.25_typescript@5.4.2/node_modules/astr...' is not assignable to type '((options: { config: import("E:/git-repo/astro-gists/node_modules/.pnpm/astro@4.4.11/node_modules/astro/dist/@types/astro").AstroConfig; command: "dev" | "build" | "preview"; ... 10 more ...; logger: import("E:/git-repo/astro-gists/node_modules/.pnpm/astro@4.4.11/node_modules/astro/dist/core/logger/core").AstroInteg...'.
                        Type '(options: { config: import("E:/git-repo/astro-gists/node_modules/.pnpm/astro@4.5.0_@types+node@20.11.25_typescript@5.4.2/node_modules/astro/dist/@types/astro").AstroConfig; ... 11 more ...; logger: import("E:/git-repo/astro-gists/node_modules/.pnpm/astro@4.5.0_@types+node@20.11.25_typescript@5.4.2/node_modules/astro...' is not assignable to type '(options: { config: import("E:/git-repo/astro-gists/node_modules/.pnpm/astro@4.4.11/node_modules/astro/dist/@types/astro").AstroConfig; command: "dev" | "build" | "preview"; isRestart: boolean; ... 9 more ...; logger: import("E:/git-repo/astro-gists/node_modules/.pnpm/astro@4.4.11/node_modules/astro/dist/core/logger...'.
                          Types of parameters 'options' and 'options' are incompatible.
                            Type '{ config: import("E:/git-repo/astro-gists/node_modules/.pnpm/astro@4.4.11/node_modules/astro/dist/@types/astro").AstroConfig; command: "dev" | "build" | "preview"; isRestart: boolean; ... 9 more ...; logger: import("E:/git-repo/astro-gists/node_modules/.pnpm/astro@4.4.11/node_modules/astro/dist/core/logger/core").As...' is not assignable to type '{ config: import("E:/git-repo/astro-gists/node_modules/.pnpm/astro@4.5.0_@types+node@20.11.25_typescript@5.4.2/node_modules/astro/dist/@types/astro").AstroConfig; command: "dev" | ... 1 more ... | "preview"; ... 10 more ...; logger: import("E:/git-repo/astro-gists/node_modules/.pnpm/astro@4.5.0_@types+node@20.11.25_...'.
                              The types of 'config.markdown.shikiConfig' are incompatible between these types.
                                Property 'themes' is missing in type '{ langs: LanguageRegistration[]; theme: ("andromeeda" | "aurora-x" | "catppuccin-frappe" | "catppuccin-latte" | "catppuccin-macchiato" | "catppuccin-mocha" | ... 31 more ... | ThemeRegistrationRaw) & ("andromeeda" | ... 37 more ... | undefined); experimentalThemes: Record<...>; wrap: boolean | null; transformers: Sh...' but required in type '{ langs: LanguageRegistration[]; theme: ("andromeeda" | "aurora-x" | "ayu-dark" | "catppuccin-frappe" | "catppuccin-latte" | "catppuccin-macchiato" | "catppuccin-mocha" | ... 35 more ... | ThemeRegistrationRaw) & ("andromeeda" | ... 42 more ... | undefined); themes: Record<...>; wrap: boolean | null; transformers: S...'.ts(2322)

I will note, that it is still "working" just pops the error when i have a .mts saying this when hovered over.... so they are "close enough" to still work

florian-lefebvre commented 4 months ago

Yeah this error is expected because the AstroIntegration type is different in 4.5 than previous versions. Given our current plugin system, having a plugin to support the hook won't work. I think it's a matter of optional deps really but I'm not comfortable enough to tell you what the solution is exactly

Adammatthiesen commented 4 months ago

I have changed the main description to simply update to the new AstroIntegration type in that case, as IMO given what you mention about the plugin system option, It would probably just be simplier to use the DB's default hook option once the AstroIntegration type is updated...

florian-lefebvre commented 4 months ago

To be clear, the work required to make it work is really small but this is not my main concern! I'm more concerned about the fact that upgrading aik astro peer dep to 4.5 means any integration author using aik will also have their minimal astro version st to 4.5. Not ideal

Adammatthiesen commented 4 months ago

I understand, I kind of figured that would be the main concern. and I have no issue waiting! I'd be glad to! my only thing was to add the information here, for maybe a work-around by the Wizards who help maintain, or if the time comes a update to support the new hooks!

Things are still working so its not really a big deal.

Fryuni commented 4 months ago

I think there might be a way to add support without moving the peer requirement.

We just have to make the code work for subtypes and the types be derived from Astro (which I think they already are)

florian-lefebvre commented 4 months ago

Do you have an example?