Skip to content

Commit

Permalink
Fix mdx and markdoc integrations return type (#6552)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Mar 16, 2023
1 parent b0b5ba8 commit 392ba3e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 35 deletions.
6 changes: 6 additions & 0 deletions .changeset/small-pens-knock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@astrojs/markdoc': patch
'@astrojs/mdx': patch
---

Fix integration return type
21 changes: 8 additions & 13 deletions packages/integrations/markdoc/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,19 @@ import {
prependForwardSlash,
} from './utils.js';

type IntegrationWithPrivateHooks = {
name: string;
hooks: Omit<AstroIntegration['hooks'], 'astro:config:setup'> & {
'astro:config:setup': (
params: HookParameters<'astro:config:setup'> & {
// `contentEntryType` is not a public API
// Add type defs here
addContentEntryType: (contentEntryType: ContentEntryType) => void;
}
) => void | Promise<void>;
};
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 {
Expand Down
32 changes: 10 additions & 22 deletions packages/integrations/mdx/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,21 @@ export type MdxOptions = Omit<typeof markdownConfigDefaults, 'remarkPlugins' | '
remarkRehype: RemarkRehypeOptions;
};

type IntegrationWithPrivateHooks = {
name: string;
hooks: Omit<AstroIntegration['hooks'], 'astro:config:setup'> & {
'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<void>;
};
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<MdxOptions> = {}
): IntegrationWithPrivateHooks {
export default function mdx(partialMdxOptions: Partial<MdxOptions> = {}): 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'],
Expand Down

0 comments on commit 392ba3e

Please sign in to comment.