Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MDX] Remove verbose migration logs #5667

Merged
merged 2 commits into from
Dec 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fluffy-cougars-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/mdx': patch
---

Chore: remove verbose "Now interiting Markdown plugins..." logs
33 changes: 5 additions & 28 deletions packages/integrations/mdx/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
recmaInjectImportMetaEnvPlugin,
rehypeApplyFrontmatterExport,
} from './plugins.js';
import { getFileInfo, handleExtendsNotSupported, parseFrontmatter } from './utils.js';
import { getFileInfo, parseFrontmatter } from './utils.js';

const RAW_CONTENT_ERROR =
'MDX does not support rawContent()! If you need to read the Markdown contents to calculate values (ex. reading time), we suggest injecting frontmatter via remark plugins. Learn more on our docs: https://docs.astro.build/en/guides/integrations-guide/mdx/#inject-frontmatter-via-remark-or-rehype-plugins';
Expand Down Expand Up @@ -45,33 +45,10 @@ export default function mdx(mdxOptions: MdxOptions = {}): AstroIntegration {
addPageExtension('.mdx');
mdxOptions.extendPlugins ??= 'markdown';

handleExtendsNotSupported(mdxOptions.remarkPlugins);
handleExtendsNotSupported(mdxOptions.rehypePlugins);

// TODO: remove for 1.0. Shipping to ease migration to new minor
if (
mdxOptions.extendPlugins === 'markdown' &&
(config.markdown.rehypePlugins?.length || config.markdown.remarkPlugins?.length)
) {
console.info(
blue(`[MDX] Now inheriting remark and rehype plugins from "markdown" config.`)
);
console.info(
`If you applied a plugin to both your Markdown and MDX configs, we suggest ${bold(
'removing the duplicate MDX entry.'
)}`
);
console.info(`See "extendPlugins" option to configure this behavior.`);
}

let remarkRehypeOptions = mdxOptions.remarkRehype;

if (mdxOptions.extendPlugins === 'markdown') {
remarkRehypeOptions = {
...config.markdown.remarkRehype,
...remarkRehypeOptions,
};
}
const remarkRehypeOptions = {
...(mdxOptions.extendPlugins === 'markdown' ? config.markdown.remarkRehype : {}),
...mdxOptions.remarkRehype,
};

const mdxPluginOpts: MdxRollupPluginOptions = {
remarkPlugins: await getRemarkPlugins(mdxOptions, config),
Expand Down
14 changes: 0 additions & 14 deletions packages/integrations/mdx/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,7 @@ export function jsToTreeNode(
};
}

// TODO: remove for 1.0
export function handleExtendsNotSupported(pluginConfig: any) {
if (
typeof pluginConfig === 'object' &&
pluginConfig !== null &&
(pluginConfig as any).hasOwnProperty('extends')
) {
throw new Error(
`[MDX] The "extends" plugin option is no longer supported! Astro now extends your project's \`markdown\` plugin configuration by default. To customize this behavior, see the \`extendPlugins\` option instead: https://docs.astro.build/en/guides/integrations-guide/mdx/#extendplugins`
);
}
}

// Following utils taken from `packages/astro/src/core/path.ts`:

export function isRelativePath(path: string) {
return startsWithDotDotSlash(path) || startsWithDotSlash(path);
}
Expand Down