feat: add --perf flag to skip md plugins

This commit is contained in:
bholmesdev 2023-02-16 14:03:54 -05:00
parent f7dbbbe3bc
commit 6c2482560d
7 changed files with 31 additions and 13 deletions

View file

@ -1010,6 +1010,7 @@ export interface AstroSettings {
watchFiles: string[];
forceDisableTelemetry: boolean;
timer: AstroTimer;
performanceRun?: boolean;
}
export type AsyncRendererComponentFn<U> = (

View file

@ -350,6 +350,7 @@ async function generatePath(
markdown: {
...settings.config.markdown,
contentDir: getContentPaths(settings.config).contentDir,
performanceRun: settings.performanceRun,
},
mode: opts.mode,
renderers,

View file

@ -209,6 +209,7 @@ function buildManifest(
markdown: {
...settings.config.markdown,
contentDir: getContentPaths(settings.config).contentDir,
performanceRun: settings.performanceRun,
},
pageMap: null as any,
propagation: Array.from(internals.propagation),

View file

@ -27,6 +27,9 @@ export function createBaseSettings(config: AstroConfig): AstroSettings {
}
export function createSettings(config: AstroConfig, cwd?: string): AstroSettings {
// TODO: hoisted to flags handler
const performanceRun = process.argv.some((arg) => arg === '--perf');
const tsconfig = loadTSConfig(cwd);
const settings = createBaseSettings(config);
@ -39,6 +42,7 @@ export function createSettings(config: AstroConfig, cwd?: string): AstroSettings
settings.tsConfig = tsconfig?.config;
settings.tsConfigPath = tsconfig?.path;
settings.watchFiles = watchFiles;
settings.performanceRun = performanceRun;
return settings;
}

View file

@ -25,6 +25,7 @@ export function createDevelopmentEnvironment(
markdown: {
...settings.config.markdown,
contentDir: getContentPaths(settings.config).contentDir,
performanceRun: settings.performanceRun,
},
mode,
// This will be overridden in the dev server

View file

@ -72,6 +72,7 @@ export default function markdown({ settings, logging }: AstroPluginOptions): Plu
...settings.config.markdown,
fileURL: new URL(`file://${fileId}`),
contentDir: getContentPaths(settings.config).contentDir,
performanceRun: settings.performanceRun,
frontmatter: raw.data,
});

View file

@ -55,6 +55,7 @@ export async function renderMarkdown(
smartypants = markdownConfigDefaults.smartypants,
contentDir,
frontmatter: userFrontmatter = {},
performanceRun = false,
} = opts;
const input = new VFile({ value: content, path: fileURL });
const scopedClassName = opts.$?.scopedClassName;
@ -64,8 +65,10 @@ export async function renderMarkdown(
.use(toRemarkInitializeAstroData({ userFrontmatter }))
.use([]);
if (gfm) {
parser.use(remarkGfm);
if (!performanceRun) {
if (gfm) {
parser.use(remarkGfm);
}
}
if (smartypants) {
@ -79,18 +82,20 @@ export async function renderMarkdown(
parser.use([[plugin, pluginOpts]]);
});
if (scopedClassName) {
parser.use([scopedStyles(scopedClassName)]);
}
if (!performanceRun) {
if (scopedClassName) {
parser.use([scopedStyles(scopedClassName)]);
}
if (syntaxHighlight === 'shiki') {
parser.use([await remarkShiki(shikiConfig, scopedClassName)]);
} else if (syntaxHighlight === 'prism') {
parser.use([remarkPrism(scopedClassName)]);
}
if (syntaxHighlight === 'shiki') {
parser.use([await remarkShiki(shikiConfig, scopedClassName)]);
} else if (syntaxHighlight === 'prism') {
parser.use([remarkPrism(scopedClassName)]);
}
// Apply later in case user plugins resolve relative image paths
parser.use([toRemarkContentRelImageError({ contentDir })]);
// Apply later in case user plugins resolve relative image paths
parser.use([toRemarkContentRelImageError({ contentDir })]);
}
parser.use([
[
@ -107,7 +112,11 @@ export async function renderMarkdown(
parser.use([[plugin, pluginOpts]]);
});
parser.use([rehypeHeadingIds, rehypeRaw]).use(rehypeStringify, { allowDangerousHtml: true });
if (!performanceRun) {
parser.use([rehypeHeadingIds]);
}
parser.use([rehypeRaw]).use(rehypeStringify, { allowDangerousHtml: true });
let vfile: MarkdownVFile;
try {