0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-06 22:10:10 -05:00

Fix mdx and markdoc integrations return type (#6552)

This commit is contained in:
Bjorn Lu 2023-03-16 23:02:37 +08:00 committed by GitHub
parent b0b5ba84a9
commit 392ba3e4d5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 35 deletions

View file

@ -0,0 +1,6 @@
---
'@astrojs/markdoc': patch
'@astrojs/mdx': patch
---
Fix integration return type

View file

@ -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 {

View file

@ -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'],