Skip to content

Commit

Permalink
[MDX] Remove verbose migration logs (withastro#5667)
Browse files Browse the repository at this point in the history
* chore: remove markdown extends warnings

* chore: changeset
  • Loading branch information
bholmesdev authored Dec 22, 2022
1 parent 813576b commit a5ba4af
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 42 deletions.
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

0 comments on commit a5ba4af

Please sign in to comment.