From 392ba3e4d55f73ce9194bd94a2243f1aa62af079 Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Thu, 16 Mar 2023 23:02:37 +0800 Subject: [PATCH] Fix mdx and markdoc integrations return type (#6552) --- .changeset/small-pens-knock.md | 6 ++++ packages/integrations/markdoc/src/index.ts | 21 ++++++-------- packages/integrations/mdx/src/index.ts | 32 +++++++--------------- 3 files changed, 24 insertions(+), 35 deletions(-) create mode 100644 .changeset/small-pens-knock.md diff --git a/.changeset/small-pens-knock.md b/.changeset/small-pens-knock.md new file mode 100644 index 000000000000..dde86fc0cced --- /dev/null +++ b/.changeset/small-pens-knock.md @@ -0,0 +1,6 @@ +--- +'@astrojs/markdoc': patch +'@astrojs/mdx': patch +--- + +Fix integration return type diff --git a/packages/integrations/markdoc/src/index.ts b/packages/integrations/markdoc/src/index.ts index 8543cf260593..71e117de4829 100644 --- a/packages/integrations/markdoc/src/index.ts +++ b/packages/integrations/markdoc/src/index.ts @@ -11,24 +11,19 @@ import { prependForwardSlash, } from './utils.js'; -type IntegrationWithPrivateHooks = { - name: string; - hooks: Omit & { - 'astro:config:setup': ( - params: HookParameters<'astro:config:setup'> & { - // `contentEntryType` is not a public API - // Add type defs here - addContentEntryType: (contentEntryType: ContentEntryType) => void; - } - ) => void | Promise; - }; +type SetupHookParams = HookParameters<'astro:config:setup'> & { + // `contentEntryType` is not a public API + // Add type defs here + addContentEntryType: (contentEntryType: ContentEntryType) => void; }; -export default function markdoc(markdocConfig: Config = {}): IntegrationWithPrivateHooks { +export default function markdoc(markdocConfig: Config = {}): AstroIntegration { return { name: '@astrojs/markdoc', hooks: { - 'astro:config:setup': async ({ updateConfig, config, addContentEntryType }) => { + 'astro:config:setup': async (params) => { + const { updateConfig, config, addContentEntryType } = params as SetupHookParams; + function getEntryInfo({ fileUrl, contents }: { fileUrl: URL; contents: string }) { const parsed = parseFrontmatter(contents, fileURLToPath(fileUrl)); return { diff --git a/packages/integrations/mdx/src/index.ts b/packages/integrations/mdx/src/index.ts index 1e64f5afa44b..bcbb0a47d63d 100644 --- a/packages/integrations/mdx/src/index.ts +++ b/packages/integrations/mdx/src/index.ts @@ -23,33 +23,21 @@ export type MdxOptions = Omit & { - 'astro:config:setup': ( - params: HookParameters<'astro:config:setup'> & { - // `addPageExtension` and `contentEntryType` are not a public APIs - // Add type defs here - addPageExtension: (extension: string) => void; - addContentEntryType: (contentEntryType: ContentEntryType) => void; - } - ) => void | Promise; - }; +type SetupHookParams = HookParameters<'astro:config:setup'> & { + // `addPageExtension` and `contentEntryType` are not a public APIs + // Add type defs here + addPageExtension: (extension: string) => void; + addContentEntryType: (contentEntryType: ContentEntryType) => void; }; -export default function mdx( - partialMdxOptions: Partial = {} -): IntegrationWithPrivateHooks { +export default function mdx(partialMdxOptions: Partial = {}): AstroIntegration { return { name: '@astrojs/mdx', hooks: { - 'astro:config:setup': async ({ - updateConfig, - config, - addPageExtension, - addContentEntryType, - command, - }) => { + 'astro:config:setup': async (params) => { + const { updateConfig, config, addPageExtension, addContentEntryType, command } = + params as SetupHookParams; + addPageExtension('.mdx'); addContentEntryType({ extensions: ['.mdx'],