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,9 +65,11 @@ export async function renderMarkdown(
.use(toRemarkInitializeAstroData({ userFrontmatter }))
.use([]);
if (!performanceRun) {
if (gfm) {
parser.use(remarkGfm);
}
}
if (smartypants) {
parser.use(remarkSmartypants);
@ -79,6 +82,7 @@ export async function renderMarkdown(
parser.use([[plugin, pluginOpts]]);
});
if (!performanceRun) {
if (scopedClassName) {
parser.use([scopedStyles(scopedClassName)]);
}
@ -91,6 +95,7 @@ export async function renderMarkdown(
// 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 {