refactor: replace non-prop interface with type; allow plugin lifecycles to have sync type (#7080)

* refactor: replace non-prop interface with type; allow plugin lifecycles to have sync type

* fix
This commit is contained in:
Joshua Chen 2022-03-31 19:16:07 +08:00 committed by GitHub
parent ce2b631455
commit 24c205a835
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
38 changed files with 145 additions and 138 deletions

View file

@ -10,13 +10,13 @@ declare module '@mdx-js/mdx' {
import type {Processor} from 'unified';
import type {RemarkOrRehypePlugin} from '@docusaurus/mdx-loader';
export interface Options {
export type Options = {
filepath?: string;
skipExport?: boolean;
wrapExport?: string;
remarkPlugins?: RemarkOrRehypePlugin[];
rehypePlugins?: RemarkOrRehypePlugin[];
}
};
export function sync(content: string, options?: Options): string;
export function createMdxAstCompiler(options?: Options): Processor;

View file

@ -182,9 +182,9 @@ export default async function mdxLoader(
// Partial are not expected to have associated metadata files or front matter
const isMDXPartial = options.isMDXPartial?.(filePath);
if (isMDXPartial && hasFrontMatter) {
const errorMessage = `Docusaurus MDX partial files should not contain FrontMatter.
const errorMessage = `Docusaurus MDX partial files should not contain front matter.
Those partial files use the _ prefix as a convention by default, but this is configurable.
File at ${filePath} contains FrontMatter that will be ignored:
File at ${filePath} contains front matter that will be ignored:
${JSON.stringify(frontMatter, null, 2)}`;
if (!options.isMDXPartialFrontMatterWarningDisabled) {

View file

@ -9,9 +9,8 @@
import {parseMarkdownHeadingId, createSlugger} from '@docusaurus/utils';
import visit from 'unist-util-visit';
import toString from 'mdast-util-to-string';
import mdastToString from 'mdast-util-to-string';
import type {Transformer} from 'unified';
import type {Parent} from 'unist';
import type {Heading, Text} from 'mdast';
export default function plugin(): Transformer {
@ -30,10 +29,8 @@ export default function plugin(): Transformer {
const headingTextNodes = headingNode.children.filter(
({type}) => !['html', 'jsx'].includes(type),
);
const heading = toString(
headingTextNodes.length > 0
? ({children: headingTextNodes} as Parent)
: headingNode,
const heading = mdastToString(
headingTextNodes.length > 0 ? headingTextNodes : headingNode,
);
// Support explicit heading IDs

View file

@ -27,9 +27,9 @@ const isImport = (child: Node): child is Literal => child.type === 'import';
const hasImports = (index: number) => index > -1;
const isExport = (child: Node): child is Literal => child.type === 'export';
interface PluginOptions {
type PluginOptions = {
name?: string;
}
};
const isTarget = (child: Literal, name: string) => {
let found = false;