@mui/internal-docs-infra 0.12.1-canary.25 → 0.12.1-canary.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/internal-docs-infra",
3
- "version": "0.12.1-canary.25",
3
+ "version": "0.12.1-canary.26",
4
4
  "author": "MUI Team",
5
5
  "description": "MUI Infra - internal documentation creation tools.",
6
6
  "license": "MIT",
@@ -804,5 +804,5 @@
804
804
  "bin": {
805
805
  "docs-infra": "./cli/index.mjs"
806
806
  },
807
- "gitSha": "cbb48ed31d032fb3e0f5b02d9eaf72fcd5828376"
807
+ "gitSha": "c0efb218192569943f75b79890cd21de4d80ee81"
808
808
  }
@@ -1134,10 +1134,26 @@ export function metadataToMarkdown(data, options = {}) {
1134
1134
  return `${lines.join('\n').trimEnd()}\n`;
1135
1135
  }
1136
1136
 
1137
+ // During a build every child page re-parses the same parent index markdown, so cache
1138
+ // the parsed metadata by content. Consumers only read the result.
1139
+ const markdownToMetadataCache = new Map();
1140
+ const MARKDOWN_TO_METADATA_CACHE_LIMIT = 50;
1141
+
1137
1142
  /**
1138
1143
  * Parses markdown content and extracts page metadata using unified
1139
1144
  */
1140
1145
  export async function markdownToMetadata(markdown) {
1146
+ let cached = markdownToMetadataCache.get(markdown);
1147
+ if (cached === undefined) {
1148
+ cached = await parseMarkdownToMetadata(markdown);
1149
+ if (markdownToMetadataCache.size >= MARKDOWN_TO_METADATA_CACHE_LIMIT) {
1150
+ markdownToMetadataCache.clear();
1151
+ }
1152
+ markdownToMetadataCache.set(markdown, cached);
1153
+ }
1154
+ return cached;
1155
+ }
1156
+ async function parseMarkdownToMetadata(markdown) {
1141
1157
  const tree = unified().use(remarkParse).parse(markdown);
1142
1158
  let title = null;
1143
1159
  let description;
@@ -282,56 +282,27 @@ export async function syncPageIndex(options) {
282
282
  }
283
283
  };
284
284
 
285
- // Step 3: Check if any of our metadata items need updating
286
- let needsUpdate = false;
287
- for (const metaItem of metadataArray) {
288
- const existingPageIndex = existingPages.findIndex(p => p.slug === metaItem.slug);
289
- if (existingPageIndex >= 0) {
290
- const existingPage = existingPages[existingPageIndex];
291
- // Compare metadata - if different, we need to update
292
- const existingPageJson = JSON.stringify(existingPage);
293
- const newPageJson = JSON.stringify(metaItem);
294
- if (existingPageJson !== newPageJson) {
295
- needsUpdate = true;
296
- break;
297
- }
298
- } else {
299
- // Page doesn't exist, we need to add it
300
- needsUpdate = true;
301
- break;
302
- }
303
- }
304
- if (!needsUpdate) {
285
+ // Step 3: Determine whether this update would change the rendered index. A field-level
286
+ // comparison of the raw metadata false-positives on every call (it carries volatile AST
287
+ // positions and fields that mergeMetadataPages fills in from the existing markdown), so
288
+ // render the exact markdown the writer would produce and compare it to what's on disk.
289
+ const relativeIndexPath = baseDir ? relative(resolve(baseDir), indexPath) : undefined;
290
+ const {
291
+ finalMarkdown: renderedMarkdown
292
+ } = await renderIndexPages(existingMarkdown, existingPages, metadataArray, {
293
+ indexTitle,
294
+ indexWrapperComponent,
295
+ preserveExistingTitleAndSlug,
296
+ relativeIndexPath
297
+ });
298
+ if (existingContent === renderedMarkdown) {
305
299
  await saveExistingIndexCache();
306
300
 
307
- // All pages are already up-to-date, no need to acquire lock or write the index.
301
+ // Index is already up-to-date, no need to acquire lock or write it.
308
302
  return;
309
303
  }
310
-
311
- // If errorIfOutOfDate is true, the writer would refuse to touch the file. The coarse
312
- // per-page comparison above compares the raw in-memory metadata, which contains fields
313
- // that never reach the persisted index (volatile AST node positions, or metadata that
314
- // mergeMetadataPages fills in from the existing markdown). Those produce false positives.
315
- // Determine whether the index is genuinely out of date by rendering the exact markdown
316
- // the writer would produce and comparing it to what is committed on disk. Only fail when
317
- // the rendered output actually differs. This is validation only - it never writes, so it
318
- // works from the pre-lock read (existingMarkdown/existingPages) rather than re-reading
319
- // under a lock like the writer does.
320
304
  if (errorIfOutOfDate) {
321
- const relativeIndexPath = baseDir ? relative(resolve(baseDir), indexPath) : undefined;
322
- const {
323
- finalMarkdown
324
- } = await renderIndexPages(existingMarkdown, existingPages, metadataArray, {
325
- indexTitle,
326
- indexWrapperComponent,
327
- preserveExistingTitleAndSlug,
328
- relativeIndexPath
329
- });
330
- if (existingContent !== finalMarkdown) {
331
- throw new Error(`Index file is out of date: ${relativeIndexPath ?? indexPath}\n` + `Please run the validation command (or next build) locally and commit the updated index files.`);
332
- }
333
- await saveExistingIndexCache();
334
- return;
305
+ throw new Error(`Index file is out of date: ${relativeIndexPath ?? indexPath}\n` + `Please run the validation command (or next build) locally and commit the updated index files.`);
335
306
  }
336
307
 
337
308
  // Step 4: Ensure the file exists before locking (proper-lockfile requires an existing file)
@@ -380,7 +351,6 @@ export async function syncPageIndex(options) {
380
351
  // Re-merge with the latest content re-read under the lock, passing the COMPLETE list
381
352
  // of pages. The returned normalized metadata is reused below to populate the cache
382
353
  // without re-parsing what we just wrote.
383
- const relativeIndexPath = baseDir ? relative(resolve(baseDir), indexPath) : undefined;
384
354
  const {
385
355
  allPages,
386
356
  merged,