From f0135576af6713778caf61baf3b00a052b3f4552 Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Mon, 27 Feb 2023 13:59:20 -0500 Subject: [PATCH] feat: add perf benchmark check to mdx --- packages/integrations/mdx/src/plugins.ts | 37 ++++++++++++++---------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/packages/integrations/mdx/src/plugins.ts b/packages/integrations/mdx/src/plugins.ts index cf30566c4..e31de1207 100644 --- a/packages/integrations/mdx/src/plugins.ts +++ b/packages/integrations/mdx/src/plugins.ts @@ -24,6 +24,9 @@ import remarkPrism from './remark-prism.js'; import remarkShiki from './remark-shiki.js'; import { isRelativePath, jsToTreeNode } from './utils.js'; +// Skip nonessential plugins during performance benchmark runs +const isPerformanceBenchmark = Boolean(process.env.ASTRO_CI_PERFORMANCE_RUN); + export function recmaInjectImportMetaEnvPlugin({ importMetaEnv, }: { @@ -130,25 +133,28 @@ export async function getRemarkPlugins( ): Promise { let remarkPlugins: PluggableList = []; - if (mdxOptions.gfm) { - remarkPlugins.push(remarkGfm); - } - if (mdxOptions.smartypants) { - remarkPlugins.push(remarkSmartypants); + if (!isPerformanceBenchmark) { + if (mdxOptions.gfm) { + remarkPlugins.push(remarkGfm); + } + if (mdxOptions.smartypants) { + remarkPlugins.push(remarkSmartypants); + } } remarkPlugins = [...remarkPlugins, ...ignoreStringPlugins(mdxOptions.remarkPlugins)]; - // Apply syntax highlighters after user plugins to match `markdown/remark` behavior - if (mdxOptions.syntaxHighlight === 'shiki') { - remarkPlugins.push([await remarkShiki(mdxOptions.shikiConfig)]); + if (!isPerformanceBenchmark) { + // Apply syntax highlighters after user plugins to match `markdown/remark` behavior + if (mdxOptions.syntaxHighlight === 'shiki') { + remarkPlugins.push([await remarkShiki(mdxOptions.shikiConfig)]); + } + if (mdxOptions.syntaxHighlight === 'prism') { + remarkPlugins.push(remarkPrism); + } + // Apply last in case user plugins resolve relative image paths + remarkPlugins.push(toRemarkContentRelImageError(config)); } - if (mdxOptions.syntaxHighlight === 'prism') { - remarkPlugins.push(remarkPrism); - } - - // Apply last in case user plugins resolve relative image paths - remarkPlugins.push(toRemarkContentRelImageError(config)); return remarkPlugins; } @@ -166,8 +172,7 @@ export function getRehypePlugins(mdxOptions: MdxOptions): MdxRollupPluginOptions ...ignoreStringPlugins(mdxOptions.rehypePlugins), // getHeadings() is guaranteed by TS, so this must be included. // We run `rehypeHeadingIds` _last_ to respect any custom IDs set by user plugins. - rehypeHeadingIds, - rehypeInjectHeadingsExport, + ...(isPerformanceBenchmark ? [] : [rehypeHeadingIds, rehypeInjectHeadingsExport]), // computed from `astro.data.frontmatter` in VFile data rehypeApplyFrontmatterExport, ];