feat: add --perf flag to skip md plugins

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

View file

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

View file

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

View file

@ -209,6 +209,7 @@ function buildManifest(
markdown: { markdown: {
...settings.config.markdown, ...settings.config.markdown,
contentDir: getContentPaths(settings.config).contentDir, contentDir: getContentPaths(settings.config).contentDir,
performanceRun: settings.performanceRun,
}, },
pageMap: null as any, pageMap: null as any,
propagation: Array.from(internals.propagation), 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 { 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 tsconfig = loadTSConfig(cwd);
const settings = createBaseSettings(config); const settings = createBaseSettings(config);
@ -39,6 +42,7 @@ export function createSettings(config: AstroConfig, cwd?: string): AstroSettings
settings.tsConfig = tsconfig?.config; settings.tsConfig = tsconfig?.config;
settings.tsConfigPath = tsconfig?.path; settings.tsConfigPath = tsconfig?.path;
settings.watchFiles = watchFiles; settings.watchFiles = watchFiles;
settings.performanceRun = performanceRun;
return settings; return settings;
} }

View file

@ -25,6 +25,7 @@ export function createDevelopmentEnvironment(
markdown: { markdown: {
...settings.config.markdown, ...settings.config.markdown,
contentDir: getContentPaths(settings.config).contentDir, contentDir: getContentPaths(settings.config).contentDir,
performanceRun: settings.performanceRun,
}, },
mode, mode,
// This will be overridden in the dev server // 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, ...settings.config.markdown,
fileURL: new URL(`file://${fileId}`), fileURL: new URL(`file://${fileId}`),
contentDir: getContentPaths(settings.config).contentDir, contentDir: getContentPaths(settings.config).contentDir,
performanceRun: settings.performanceRun,
frontmatter: raw.data, frontmatter: raw.data,
}); });

View file

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