@mui/internal-docs-infra 0.2.3-canary.9 → 0.3.1-canary.0

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.
Files changed (144) hide show
  1. package/README.md +3 -2
  2. package/esm/CodeHighlighter/CodeHighlighter.js +16 -16
  3. package/esm/CodeHighlighter/CodeHighlighterClient.js +33 -33
  4. package/esm/CodeHighlighter/errors.js +3 -3
  5. package/esm/CodeHighlighter/types.d.ts +1 -1
  6. package/esm/CodeProvider/CodeContext.d.ts +4 -4
  7. package/esm/CodeProvider/CodeProvider.js +7 -7
  8. package/esm/cli/index.d.ts +1 -0
  9. package/esm/cli/index.js +6 -0
  10. package/esm/cli/runValidate.d.ts +8 -0
  11. package/esm/cli/runValidate.js +297 -0
  12. package/esm/createSitemap/createSitemap.d.ts +23 -0
  13. package/esm/createSitemap/createSitemap.js +45 -0
  14. package/esm/createSitemap/index.d.ts +1 -0
  15. package/esm/createSitemap/index.js +1 -0
  16. package/esm/createSitemap/types.d.ts +68 -0
  17. package/esm/createSitemap/types.js +1 -0
  18. package/esm/pipeline/getFileConventions/fileConventions.d.ts +4 -0
  19. package/esm/pipeline/getFileConventions/fileConventions.js +4 -0
  20. package/esm/pipeline/getFileConventions/getFileConventions.d.ts +4 -0
  21. package/esm/pipeline/getFileConventions/getFileConventions.js +17 -0
  22. package/esm/pipeline/getFileConventions/index.d.ts +1 -0
  23. package/esm/pipeline/getFileConventions/index.js +1 -0
  24. package/esm/{CodeHighlighter/addPathsToVariant.d.ts → pipeline/loadCodeVariant/addCodeVariantPaths.d.ts} +1 -1
  25. package/esm/{CodeHighlighter/applyTransform.d.ts → pipeline/loadCodeVariant/applyCodeTransform.d.ts} +3 -3
  26. package/esm/{CodeHighlighter/applyTransform.js → pipeline/loadCodeVariant/applyCodeTransform.js} +4 -4
  27. package/esm/{CodeHighlighter → pipeline/loadCodeVariant}/calculateMainFilePath.js +1 -1
  28. package/esm/{CodeHighlighter/transformCode.d.ts → pipeline/loadCodeVariant/computeHastDeltas.d.ts} +9 -5
  29. package/esm/{CodeHighlighter/transformCode.js → pipeline/loadCodeVariant/computeHastDeltas.js} +20 -16
  30. package/esm/pipeline/loadCodeVariant/diffHast.d.ts +3 -0
  31. package/esm/{CodeHighlighter/transformParsedSource.js → pipeline/loadCodeVariant/diffHast.js} +5 -5
  32. package/esm/{CodeHighlighter/examineVariant.d.ts → pipeline/loadCodeVariant/examineCodeVariant.d.ts} +2 -2
  33. package/esm/{CodeHighlighter/examineVariant.js → pipeline/loadCodeVariant/examineCodeVariant.js} +1 -1
  34. package/esm/{useDemo/flattenVariant.d.ts → pipeline/loadCodeVariant/flattenCodeVariant.d.ts} +2 -2
  35. package/esm/{useDemo/flattenVariant.js → pipeline/loadCodeVariant/flattenCodeVariant.js} +3 -3
  36. package/esm/{CodeHighlighter/hasAllVariants.d.ts → pipeline/loadCodeVariant/hasAllCodeVariants.d.ts} +1 -1
  37. package/esm/pipeline/loadCodeVariant/index.d.ts +10 -0
  38. package/esm/pipeline/loadCodeVariant/index.js +17 -0
  39. package/esm/{CodeHighlighter/loadFallbackCode.d.ts → pipeline/loadCodeVariant/loadCodeFallback.d.ts} +2 -2
  40. package/esm/{CodeHighlighter/loadFallbackCode.js → pipeline/loadCodeVariant/loadCodeFallback.js} +180 -106
  41. package/esm/{CodeHighlighter/loadVariant.d.ts → pipeline/loadCodeVariant/loadCodeVariant.d.ts} +2 -2
  42. package/esm/{CodeHighlighter/loadVariant.js → pipeline/loadCodeVariant/loadCodeVariant.js} +122 -49
  43. package/esm/{CodeHighlighter/maybeInitialData.d.ts → pipeline/loadCodeVariant/maybeCodeInitialData.d.ts} +6 -6
  44. package/esm/{CodeHighlighter/maybeInitialData.js → pipeline/loadCodeVariant/maybeCodeInitialData.js} +6 -6
  45. package/esm/{CodeHighlighter/mergeMetadata.d.ts → pipeline/loadCodeVariant/mergeCodeMetadata.d.ts} +3 -3
  46. package/esm/{CodeHighlighter/mergeMetadata.js → pipeline/loadCodeVariant/mergeCodeMetadata.js} +3 -3
  47. package/esm/{CodeHighlighter → pipeline/loadCodeVariant}/parseCode.d.ts +1 -1
  48. package/esm/{CodeHighlighter → pipeline/loadCodeVariant}/transformSource.d.ts +1 -1
  49. package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.d.ts +5 -0
  50. package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.js +86 -13
  51. package/esm/pipeline/loadPrecomputedCodeHighlighter/performanceLogger.d.ts +30 -0
  52. package/esm/pipeline/loadPrecomputedCodeHighlighter/performanceLogger.js +77 -0
  53. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/loadPrecomputedCodeHighlighterClient.js +7 -7
  54. package/esm/pipeline/loadPrecomputedSitemap/index.d.ts +2 -0
  55. package/esm/pipeline/loadPrecomputedSitemap/index.js +4 -0
  56. package/esm/pipeline/loadPrecomputedSitemap/loadPrecomputedSitemap.d.ts +10 -0
  57. package/esm/pipeline/loadPrecomputedSitemap/loadPrecomputedSitemap.js +213 -0
  58. package/esm/pipeline/loadServerCodeMeta/index.d.ts +2 -1
  59. package/esm/pipeline/loadServerCodeMeta/index.js +2 -1
  60. package/esm/pipeline/loadServerCodeMeta/loadServerCodeMeta.d.ts +1 -1
  61. package/esm/pipeline/loadServerCodeMeta/loadServerCodeMeta.js +2 -2
  62. package/esm/pipeline/{loaderUtils → loadServerCodeMeta}/resolveModulePathWithFs.d.ts +1 -1
  63. package/esm/pipeline/{loaderUtils → loadServerCodeMeta}/resolveModulePathWithFs.js +1 -1
  64. package/esm/pipeline/loadServerPageIndex/index.d.ts +2 -0
  65. package/esm/pipeline/loadServerPageIndex/index.js +1 -0
  66. package/esm/pipeline/loadServerPageIndex/loadServerPageIndex.d.ts +51 -0
  67. package/esm/pipeline/loadServerPageIndex/loadServerPageIndex.js +174 -0
  68. package/esm/pipeline/loadServerSitemap/index.d.ts +2 -0
  69. package/esm/pipeline/loadServerSitemap/index.js +1 -0
  70. package/esm/pipeline/loadServerSitemap/loadServerSitemap.d.ts +39 -0
  71. package/esm/pipeline/loadServerSitemap/loadServerSitemap.js +168 -0
  72. package/esm/pipeline/loadServerSource/loadServerSource.js +1 -1
  73. package/esm/pipeline/loaderUtils/externalsToPackages.js +1 -1
  74. package/esm/pipeline/loaderUtils/processRelativeImports.js +16 -3
  75. package/esm/pipeline/loaderUtils/rewriteImports.d.ts +36 -0
  76. package/esm/pipeline/loaderUtils/rewriteImports.js +139 -8
  77. package/esm/pipeline/syncPageIndex/createMarkdownNodes.d.ts +76 -0
  78. package/esm/pipeline/syncPageIndex/createMarkdownNodes.js +305 -0
  79. package/esm/pipeline/syncPageIndex/index.d.ts +1 -0
  80. package/esm/pipeline/syncPageIndex/index.js +1 -0
  81. package/esm/pipeline/syncPageIndex/mergeMetadataMarkdown.d.ts +58 -0
  82. package/esm/pipeline/syncPageIndex/mergeMetadataMarkdown.js +214 -0
  83. package/esm/pipeline/syncPageIndex/metadataToMarkdown.d.ts +67 -0
  84. package/esm/pipeline/syncPageIndex/metadataToMarkdown.js +1486 -0
  85. package/esm/pipeline/syncPageIndex/syncPageIndex.d.ts +108 -0
  86. package/esm/pipeline/syncPageIndex/syncPageIndex.js +540 -0
  87. package/esm/pipeline/transformHtmlCodePrecomputed/transformHtmlCodePrecomputed.d.ts +2 -2
  88. package/esm/pipeline/transformHtmlCodePrecomputed/transformHtmlCodePrecomputed.js +5 -5
  89. package/esm/pipeline/transformMarkdownBlockquoteCallouts/index.d.ts +2 -0
  90. package/esm/pipeline/transformMarkdownBlockquoteCallouts/index.js +4 -0
  91. package/esm/pipeline/transformMarkdownBlockquoteCallouts/transformMarkdownBlockquoteCallouts.d.ts +16 -0
  92. package/esm/pipeline/transformMarkdownBlockquoteCallouts/transformMarkdownBlockquoteCallouts.js +58 -0
  93. package/esm/pipeline/transformMarkdownDemoLinks/index.d.ts +2 -0
  94. package/esm/pipeline/transformMarkdownDemoLinks/index.js +4 -0
  95. package/esm/pipeline/transformMarkdownDemoLinks/transformMarkdownDemoLinks.d.ts +26 -0
  96. package/esm/pipeline/transformMarkdownDemoLinks/transformMarkdownDemoLinks.js +107 -0
  97. package/esm/pipeline/transformMarkdownMetadata/index.d.ts +2 -0
  98. package/esm/pipeline/transformMarkdownMetadata/index.js +4 -0
  99. package/esm/pipeline/transformMarkdownMetadata/transformMarkdownMetadata.d.ts +3 -0
  100. package/esm/pipeline/transformMarkdownMetadata/transformMarkdownMetadata.js +1010 -0
  101. package/esm/pipeline/transformMarkdownMetadata/types.d.ts +110 -0
  102. package/esm/pipeline/transformMarkdownMetadata/types.js +1 -0
  103. package/esm/pipeline/transformMarkdownRelativePaths/index.d.ts +2 -0
  104. package/esm/pipeline/transformMarkdownRelativePaths/index.js +4 -0
  105. package/esm/pipeline/transformMarkdownRelativePaths/transformMarkdownRelativePaths.d.ts +15 -0
  106. package/esm/pipeline/transformMarkdownRelativePaths/transformMarkdownRelativePaths.js +40 -0
  107. package/esm/useCode/Pre.js +15 -2
  108. package/esm/useCode/useCode.d.ts +15 -2
  109. package/esm/useCode/useCode.js +15 -6
  110. package/esm/useCode/useCodeUtils.js +3 -3
  111. package/esm/useCode/useFileNavigation.d.ts +9 -3
  112. package/esm/useCode/useFileNavigation.js +124 -81
  113. package/esm/useCode/useUIState.d.ts +4 -1
  114. package/esm/useCode/useUIState.js +17 -2
  115. package/esm/useCode/useVariantSelection.d.ts +8 -3
  116. package/esm/useCode/useVariantSelection.js +144 -52
  117. package/esm/useCopier/index.js +5 -4
  118. package/esm/useDemo/createCodeSandbox.d.ts +1 -1
  119. package/esm/useDemo/createStackBlitz.d.ts +1 -1
  120. package/esm/useDemo/exportVariant.js +13 -11
  121. package/esm/useDemo/index.d.ts +1 -1
  122. package/esm/useDemo/index.js +1 -1
  123. package/esm/useDemo/useDemo.d.ts +5 -5
  124. package/esm/useDemo/useDemo.js +6 -6
  125. package/esm/useErrors/useErrors.d.ts +1 -1
  126. package/esm/useErrors/useErrors.js +6 -2
  127. package/esm/useSearch/index.d.ts +1 -0
  128. package/esm/useSearch/index.js +1 -0
  129. package/esm/useSearch/types.d.ts +165 -0
  130. package/esm/useSearch/types.js +1 -0
  131. package/esm/useSearch/useSearch.d.ts +56 -0
  132. package/esm/useSearch/useSearch.js +647 -0
  133. package/esm/withDocsInfra/withDeploymentConfig.js +4 -2
  134. package/esm/withDocsInfra/withDocsInfra.d.ts +39 -0
  135. package/esm/withDocsInfra/withDocsInfra.js +79 -7
  136. package/package.json +105 -5
  137. package/esm/CodeHighlighter/transformParsedSource.d.ts +0 -3
  138. /package/esm/{CodeHighlighter/addPathsToVariant.js → pipeline/loadCodeVariant/addCodeVariantPaths.js} +0 -0
  139. /package/esm/{CodeHighlighter → pipeline/loadCodeVariant}/calculateMainFilePath.d.ts +0 -0
  140. /package/esm/{CodeHighlighter/hasAllVariants.js → pipeline/loadCodeVariant/hasAllCodeVariants.js} +0 -0
  141. /package/esm/{CodeHighlighter → pipeline/loadCodeVariant}/parseCode.js +0 -0
  142. /package/esm/{CodeHighlighter → pipeline/loadCodeVariant}/pathUtils.d.ts +0 -0
  143. /package/esm/{CodeHighlighter → pipeline/loadCodeVariant}/pathUtils.js +0 -0
  144. /package/esm/{CodeHighlighter → pipeline/loadCodeVariant}/transformSource.js +0 -0
@@ -0,0 +1,51 @@
1
+ import type { HeadingHierarchy } from "../transformMarkdownMetadata/types.js";
2
+ import type { SitemapSection, SitemapSectionData } from "../../createSitemap/types.js";
3
+ /**
4
+ * Options for creating a loadServerPageIndex function
5
+ */
6
+ export interface CreateLoadServerPageIndexOptions {
7
+ /**
8
+ * The root context directory for resolving relative paths.
9
+ * Defaults to process.cwd().
10
+ */
11
+ rootContext?: string;
12
+ }
13
+ /**
14
+ * Function type for loading page index data from a markdown file
15
+ */
16
+ export type LoadServerPageIndex = (filePath: string) => Promise<SitemapSectionData | null>;
17
+ /**
18
+ * Converts a path segment to a title
19
+ * e.g., "docs-infra" -> "Docs Infra", "components" -> "Components"
20
+ */
21
+ export declare function pathSegmentToTitle(segment: string): string;
22
+ /**
23
+ * Recursively removes titleMarkdown fields from a heading hierarchy
24
+ */
25
+ export declare function stripTitleMarkdown(hierarchy: HeadingHierarchy): Record<string, SitemapSection>;
26
+ /**
27
+ * Extracts prefix and title from an import path
28
+ * e.g., "/path/to/app/docs-infra/components/page.mdx" -> { prefix: "/docs-infra/components/", title: "Docs Infra Components" }
29
+ */
30
+ export declare function extractPrefixAndTitle(absolutePath: string, rootContext: string): {
31
+ prefix: string;
32
+ title: string;
33
+ };
34
+ /**
35
+ * Default loadServerPageIndex function that loads page index data from a markdown file.
36
+ * This function uses process.cwd() as the root context for resolving relative paths.
37
+ */
38
+ export declare const loadServerPageIndex: LoadServerPageIndex;
39
+ /**
40
+ * Creates a loadServerPageIndex function with custom options.
41
+ *
42
+ * This factory function creates a LoadServerPageIndex implementation that:
43
+ * 1. Reads the markdown file from the provided file path
44
+ * 2. Parses the markdown to extract metadata using markdownToMetadata
45
+ * 3. Enriches the metadata with prefix and title derived from the file path
46
+ * 4. Returns a SitemapSectionData object with page data
47
+ *
48
+ * @param options - Configuration options for the loader
49
+ * @returns LoadServerPageIndex function that takes a file path and returns Promise<SitemapSectionData | null>
50
+ */
51
+ export declare function createLoadServerPageIndex(options?: CreateLoadServerPageIndexOptions): LoadServerPageIndex;
@@ -0,0 +1,174 @@
1
+ import _regenerator from "@babel/runtime/helpers/esm/regenerator";
2
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
+ import _extends from "@babel/runtime/helpers/esm/extends";
4
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
5
+ import _typeof from "@babel/runtime/helpers/esm/typeof";
6
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
7
+ var _excluded = ["titleMarkdown", "children"],
8
+ _excluded2 = ["descriptionMarkdown", "sections"];
9
+ import fs from 'node:fs/promises';
10
+ import path from 'node:path';
11
+ import { markdownToMetadata } from "../syncPageIndex/metadataToMarkdown.js";
12
+
13
+ /**
14
+ * Options for creating a loadServerPageIndex function
15
+ */
16
+
17
+ /**
18
+ * Function type for loading page index data from a markdown file
19
+ */
20
+
21
+ /**
22
+ * Converts a path segment to a title
23
+ * e.g., "docs-infra" -> "Docs Infra", "components" -> "Components"
24
+ */
25
+ export function pathSegmentToTitle(segment) {
26
+ return segment.split('-').map(function (word) {
27
+ return word.charAt(0).toUpperCase() + word.slice(1);
28
+ }).join(' ');
29
+ }
30
+
31
+ /**
32
+ * Recursively removes titleMarkdown fields from a heading hierarchy
33
+ */
34
+ export function stripTitleMarkdown(hierarchy) {
35
+ var result = {};
36
+ for (var _i = 0, _Object$entries = Object.entries(hierarchy); _i < _Object$entries.length; _i++) {
37
+ var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
38
+ key = _Object$entries$_i[0],
39
+ value = _Object$entries$_i[1];
40
+ if (_typeof(value) === 'object' && value !== null) {
41
+ var titleMarkdown = value.titleMarkdown,
42
+ children = value.children,
43
+ rest = _objectWithoutPropertiesLoose(value, _excluded);
44
+ var strippedChildren = children ? stripTitleMarkdown(children) : {};
45
+ result[key] = _extends(_extends({}, rest), {}, {
46
+ // Only include children if it has keys, otherwise set to undefined
47
+ children: Object.keys(strippedChildren).length > 0 ? strippedChildren : undefined
48
+ });
49
+ }
50
+ }
51
+ return result;
52
+ }
53
+
54
+ /**
55
+ * Extracts prefix and title from an import path
56
+ * e.g., "/path/to/app/docs-infra/components/page.mdx" -> { prefix: "/docs-infra/components/", title: "Docs Infra Components" }
57
+ */
58
+ export function extractPrefixAndTitle(absolutePath, rootContext) {
59
+ // Get the relative path from the root context
60
+ var relativePath = path.relative(rootContext, absolutePath);
61
+
62
+ // Extract the directory path (remove filename)
63
+ var dirPath = path.dirname(relativePath);
64
+
65
+ // Split into segments
66
+ var allSegments = dirPath.split(path.sep);
67
+
68
+ // Filter out segments:
69
+ // - Remove leading 'src' and 'app' directory markers (only if they're at the start)
70
+ // - Remove Next.js route groups (segments in parentheses like '(public)')
71
+ // - Remove current directory markers ('.' and empty strings)
72
+ var segments = allSegments.filter(function (seg, index) {
73
+ // Remove 'src' only if it's the first segment
74
+ if (seg === 'src' && index === 0) {
75
+ return false;
76
+ }
77
+ // Remove 'app' only if it's the first or second segment (after 'src')
78
+ if (seg === 'app' && (index === 0 || index === 1 && allSegments[0] === 'src')) {
79
+ return false;
80
+ }
81
+ // Filter out Next.js route groups (e.g., '(public)', '(content)')
82
+ if (seg.startsWith('(') && seg.endsWith(')')) {
83
+ return false;
84
+ }
85
+ // Filter out current directory markers
86
+ if (seg === '.' || seg === '') {
87
+ return false;
88
+ }
89
+ return true;
90
+ });
91
+
92
+ // Generate prefix with leading and trailing slashes
93
+ var prefix = segments.length > 0 ? "/".concat(segments.join('/'), "/") : '/';
94
+
95
+ // Generate title from path segments
96
+ var title = segments.map(pathSegmentToTitle).join(' ');
97
+ return {
98
+ prefix: prefix,
99
+ title: title
100
+ };
101
+ }
102
+
103
+ /**
104
+ * Default loadServerPageIndex function that loads page index data from a markdown file.
105
+ * This function uses process.cwd() as the root context for resolving relative paths.
106
+ */
107
+ export var loadServerPageIndex = createLoadServerPageIndex();
108
+
109
+ /**
110
+ * Creates a loadServerPageIndex function with custom options.
111
+ *
112
+ * This factory function creates a LoadServerPageIndex implementation that:
113
+ * 1. Reads the markdown file from the provided file path
114
+ * 2. Parses the markdown to extract metadata using markdownToMetadata
115
+ * 3. Enriches the metadata with prefix and title derived from the file path
116
+ * 4. Returns a SitemapSectionData object with page data
117
+ *
118
+ * @param options - Configuration options for the loader
119
+ * @returns LoadServerPageIndex function that takes a file path and returns Promise<SitemapSectionData | null>
120
+ */
121
+ export function createLoadServerPageIndex() {
122
+ var _options$rootContext;
123
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
124
+ var rootContext = (_options$rootContext = options.rootContext) != null ? _options$rootContext : process.cwd();
125
+ return /*#__PURE__*/function () {
126
+ var _loadPageIndex = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(filePath) {
127
+ var absolutePath, _extractPrefixAndTitl, prefix, generatedTitle, markdownContent, metadata, enrichedMetadata;
128
+ return _regenerator().w(function (_context) {
129
+ while (1) switch (_context.n) {
130
+ case 0:
131
+ // Resolve the absolute path to the markdown file
132
+ absolutePath = filePath.startsWith('file://') ? filePath.slice(7) : filePath; // Extract prefix and title from the import path
133
+ _extractPrefixAndTitl = extractPrefixAndTitle(absolutePath, rootContext), prefix = _extractPrefixAndTitl.prefix, generatedTitle = _extractPrefixAndTitl.title; // Read the markdown file
134
+ _context.n = 1;
135
+ return fs.readFile(absolutePath, 'utf-8');
136
+ case 1:
137
+ markdownContent = _context.v;
138
+ _context.n = 2;
139
+ return markdownToMetadata(markdownContent);
140
+ case 2:
141
+ metadata = _context.v;
142
+ if (metadata) {
143
+ _context.n = 3;
144
+ break;
145
+ }
146
+ return _context.a(2, null);
147
+ case 3:
148
+ // Add prefix and override title with the generated one from the path
149
+ // Strip descriptionMarkdown and titleMarkdown to reduce bundle size
150
+ enrichedMetadata = _extends(_extends({}, metadata), {}, {
151
+ prefix: prefix,
152
+ // Use the generated title from the path (override markdown's H1)
153
+ title: generatedTitle,
154
+ // Strip markdown AST fields from each page to reduce size
155
+ pages: metadata.pages.map(function (page) {
156
+ var descriptionMarkdown = page.descriptionMarkdown,
157
+ sections = page.sections,
158
+ pageWithoutMarkdown = _objectWithoutPropertiesLoose(page, _excluded2);
159
+ return _extends(_extends({}, pageWithoutMarkdown), {}, {
160
+ // Strip titleMarkdown from sections hierarchy
161
+ sections: sections ? stripTitleMarkdown(sections) : undefined
162
+ });
163
+ })
164
+ });
165
+ return _context.a(2, enrichedMetadata);
166
+ }
167
+ }, _callee);
168
+ }));
169
+ function loadPageIndex(_x) {
170
+ return _loadPageIndex.apply(this, arguments);
171
+ }
172
+ return loadPageIndex;
173
+ }();
174
+ }
@@ -0,0 +1,2 @@
1
+ export { loadServerSitemap, createLoadServerSitemap, createSitemapSchema } from "./loadServerSitemap.js";
2
+ export type { CreateLoadServerSitemapOptions, LoadServerSitemap } from "./loadServerSitemap.js";
@@ -0,0 +1 @@
1
+ export { loadServerSitemap, createLoadServerSitemap, createSitemapSchema } from "./loadServerSitemap.js";
@@ -0,0 +1,39 @@
1
+ import type { Sitemap } from "../../createSitemap/types.js";
2
+ /**
3
+ * Options for creating a loadServerSitemap function
4
+ */
5
+ export interface CreateLoadServerSitemapOptions {
6
+ /**
7
+ * The root context directory for resolving relative paths.
8
+ * Defaults to the directory containing the sitemap index file.
9
+ */
10
+ rootContext?: string;
11
+ }
12
+ /**
13
+ * Function type for loading sitemap data from a sitemap index file URL
14
+ */
15
+ export type LoadServerSitemap = (url: string) => Promise<Sitemap>;
16
+ /**
17
+ * Creates the default Orama schema for search indexing.
18
+ * See: https://docs.orama.com/docs/orama-js/usage/create#schema-properties-and-types
19
+ */
20
+ export declare function createSitemapSchema(): Sitemap['schema'];
21
+ /**
22
+ * Default loadServerSitemap function that loads sitemap data from a sitemap index file.
23
+ * This function parses the sitemap index file to find createSitemap calls and resolves
24
+ * the page index paths from the imports.
25
+ */
26
+ export declare const loadServerSitemap: LoadServerSitemap;
27
+ /**
28
+ * Creates a loadServerSitemap function with custom options.
29
+ *
30
+ * This factory function creates a LoadServerSitemap implementation that:
31
+ * 1. Parses the sitemap index file to find createSitemap calls with page imports
32
+ * 2. Resolves all page index paths from the imports
33
+ * 3. Loads each page index using loadServerPageIndex
34
+ * 4. Returns a Sitemap object with schema and page data
35
+ *
36
+ * @param options - Configuration options for the loader
37
+ * @returns LoadServerSitemap function that takes a file URL and returns Promise<Sitemap>
38
+ */
39
+ export declare function createLoadServerSitemap(options?: CreateLoadServerSitemapOptions): LoadServerSitemap;
@@ -0,0 +1,168 @@
1
+ import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
2
+ import _regenerator from "@babel/runtime/helpers/esm/regenerator";
3
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
5
+ import { readFile } from 'node:fs/promises';
6
+ import path from 'node:path';
7
+ import { createLoadServerPageIndex } from "../loadServerPageIndex/loadServerPageIndex.js";
8
+ import { parseCreateFactoryCall } from "../loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js";
9
+
10
+ /**
11
+ * Options for creating a loadServerSitemap function
12
+ */
13
+
14
+ /**
15
+ * Function type for loading sitemap data from a sitemap index file URL
16
+ */
17
+
18
+ /**
19
+ * Creates the default Orama schema for search indexing.
20
+ * See: https://docs.orama.com/docs/orama-js/usage/create#schema-properties-and-types
21
+ */
22
+ export function createSitemapSchema() {
23
+ return {
24
+ slug: 'string',
25
+ path: 'string',
26
+ title: 'string',
27
+ description: 'string',
28
+ sections: 'string[]',
29
+ subsections: 'string[]',
30
+ keywords: 'string[]'
31
+ };
32
+ }
33
+
34
+ /**
35
+ * Default loadServerSitemap function that loads sitemap data from a sitemap index file.
36
+ * This function parses the sitemap index file to find createSitemap calls and resolves
37
+ * the page index paths from the imports.
38
+ */
39
+ export var loadServerSitemap = createLoadServerSitemap();
40
+
41
+ /**
42
+ * Creates a loadServerSitemap function with custom options.
43
+ *
44
+ * This factory function creates a LoadServerSitemap implementation that:
45
+ * 1. Parses the sitemap index file to find createSitemap calls with page imports
46
+ * 2. Resolves all page index paths from the imports
47
+ * 3. Loads each page index using loadServerPageIndex
48
+ * 4. Returns a Sitemap object with schema and page data
49
+ *
50
+ * @param options - Configuration options for the loader
51
+ * @returns LoadServerSitemap function that takes a file URL and returns Promise<Sitemap>
52
+ */
53
+ export function createLoadServerSitemap() {
54
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
55
+ return /*#__PURE__*/function () {
56
+ var _loadSitemap = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(url) {
57
+ var _options$rootContext;
58
+ var filePath, rootContext, loadPageIndex, source, sitemapCall, entries, results, sitemapData, errors, _iterator, _step, result, errorMessages;
59
+ return _regenerator().w(function (_context2) {
60
+ while (1) switch (_context2.n) {
61
+ case 0:
62
+ // Remove file:// prefix if present to get file path
63
+ filePath = url.startsWith('file://') ? url.slice(7) : url; // Determine root context from file path if not provided
64
+ rootContext = (_options$rootContext = options.rootContext) != null ? _options$rootContext : path.dirname(filePath); // Create page index loader with root context
65
+ loadPageIndex = createLoadServerPageIndex({
66
+ rootContext: rootContext
67
+ }); // Read the source file to find createSitemap calls
68
+ _context2.n = 1;
69
+ return readFile(filePath, 'utf-8');
70
+ case 1:
71
+ source = _context2.v;
72
+ _context2.n = 2;
73
+ return parseCreateFactoryCall(source, filePath);
74
+ case 2:
75
+ sitemapCall = _context2.v;
76
+ if (!(!sitemapCall || !sitemapCall.variants)) {
77
+ _context2.n = 3;
78
+ break;
79
+ }
80
+ return _context2.a(2, {
81
+ schema: createSitemapSchema(),
82
+ data: {}
83
+ });
84
+ case 3:
85
+ // Process all page index files in parallel
86
+ entries = Object.entries(sitemapCall.variants);
87
+ _context2.n = 4;
88
+ return Promise.all(entries.map(/*#__PURE__*/function () {
89
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref) {
90
+ var _ref3, key, importPath, metadata, _t;
91
+ return _regenerator().w(function (_context) {
92
+ while (1) switch (_context.p = _context.n) {
93
+ case 0:
94
+ _ref3 = _slicedToArray(_ref, 2), key = _ref3[0], importPath = _ref3[1];
95
+ _context.p = 1;
96
+ _context.n = 2;
97
+ return loadPageIndex(importPath);
98
+ case 2:
99
+ metadata = _context.v;
100
+ return _context.a(2, {
101
+ key: key,
102
+ metadata: metadata,
103
+ error: null
104
+ });
105
+ case 3:
106
+ _context.p = 3;
107
+ _t = _context.v;
108
+ return _context.a(2, {
109
+ key: key,
110
+ metadata: null,
111
+ error: _t instanceof Error ? _t : new Error(String(_t))
112
+ });
113
+ }
114
+ }, _callee, null, [[1, 3]]);
115
+ }));
116
+ return function (_x2) {
117
+ return _ref2.apply(this, arguments);
118
+ };
119
+ }()));
120
+ case 4:
121
+ results = _context2.v;
122
+ // Collect results and errors
123
+ sitemapData = {};
124
+ errors = [];
125
+ _iterator = _createForOfIteratorHelper(results);
126
+ try {
127
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
128
+ result = _step.value;
129
+ if (result.error) {
130
+ errors.push({
131
+ key: result.key,
132
+ error: result.error
133
+ });
134
+ } else if (result.metadata) {
135
+ sitemapData[result.key] = result.metadata;
136
+ }
137
+ }
138
+
139
+ // Throw if any pages failed to load
140
+ } catch (err) {
141
+ _iterator.e(err);
142
+ } finally {
143
+ _iterator.f();
144
+ }
145
+ if (!(errors.length > 0)) {
146
+ _context2.n = 5;
147
+ break;
148
+ }
149
+ errorMessages = errors.map(function (_ref4) {
150
+ var key = _ref4.key,
151
+ error = _ref4.error;
152
+ return " ".concat(key, ": ").concat(error.message);
153
+ }).join('\n');
154
+ throw new Error("Failed to load ".concat(errors.length, " page index(es):\n").concat(errorMessages));
155
+ case 5:
156
+ return _context2.a(2, {
157
+ schema: createSitemapSchema(),
158
+ data: sitemapData
159
+ });
160
+ }
161
+ }, _callee2);
162
+ }));
163
+ function loadSitemap(_x) {
164
+ return _loadSitemap.apply(this, arguments);
165
+ }
166
+ return loadSitemap;
167
+ }();
168
+ }
@@ -6,7 +6,7 @@ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
6
6
  // eslint-disable-next-line n/prefer-node-protocol
7
7
  import { readFile } from 'fs/promises';
8
8
  import { parseImportsAndComments } from "../loaderUtils/index.js";
9
- import { resolveImportResultWithFs } from "../loaderUtils/resolveModulePathWithFs.js";
9
+ import { resolveImportResultWithFs } from "../loadServerCodeMeta/resolveModulePathWithFs.js";
10
10
  import { processRelativeImports } from "../loaderUtils/processRelativeImports.js";
11
11
  import { isJavaScriptModule } from "../loaderUtils/resolveModulePath.js";
12
12
  /**
@@ -21,7 +21,7 @@ export function externalsToPackages(externals) {
21
21
  * - 'react' -> 'react'
22
22
  * - 'react-dom' -> 'react-dom'
23
23
  * - '@mui/internal-docs-infra/CodeHighlighter' -> '@mui/internal-docs-infra'
24
- * - '@mui/internal-docs-infra/parseSource' -> '@mui/internal-docs-infra'
24
+ * - '@mui/internal-docs-infra/pipeline/parseSource' -> '@mui/internal-docs-infra'
25
25
  * - 'lodash/get' -> 'lodash'
26
26
  * - 'some-package/submodule/deep' -> 'some-package'
27
27
  */
@@ -36,8 +36,13 @@ function processFlatMode(importResult, resolvedPathsMap) {
36
36
  var file = _fileMapping[_i];
37
37
  var fileName = file.segments[file.segments.length - 1];
38
38
  var isIndexFile = fileName.startsWith('index.');
39
+ var isUnderscoreIndexFile = fileName.startsWith('_index.');
39
40
  var candidateName = void 0;
40
- if (isIndexFile) {
41
+ if (isUnderscoreIndexFile) {
42
+ // Files starting with "_index." should be treated as direct index imports
43
+ // e.g., "../../dir/_index.module.css" -> "index.module.css"
44
+ candidateName = "index".concat(file.extension);
45
+ } else if (isIndexFile) {
41
46
  // Check if the original import was a direct index file (e.g., "./index.ext")
42
47
  var originalImportParts = file.originalImportPath.split('/');
43
48
  var isDirectIndexImport = originalImportParts.length === 2 && originalImportParts[0] === '.' && originalImportParts[1].startsWith('index.');
@@ -131,9 +136,13 @@ function processFlatMode(importResult, resolvedPathsMap) {
131
136
  var _file = _step.value;
132
137
  var _fileName = _file.segments[_file.segments.length - 1];
133
138
  var _isIndexFile = _fileName.startsWith('index.');
139
+ var _isUnderscoreIndexFile = _fileName.startsWith('_index.');
134
140
  var distinguishingSegment = _file.segments[_distinguishingIndex];
135
141
  var finalName = void 0;
136
- if (_isIndexFile) {
142
+ if (_isUnderscoreIndexFile) {
143
+ // Files starting with "_index." should always use "index" as the base name
144
+ finalName = "".concat(distinguishingSegment, "/index").concat(_file.extension);
145
+ } else if (_isIndexFile) {
137
146
  // Check if this was a direct index import
138
147
  var _originalImportParts = _file.originalImportPath.split('/');
139
148
  var _isDirectIndexImport = _originalImportParts.length === 2 && _originalImportParts[0] === '.' && _originalImportParts[1].startsWith('index.');
@@ -202,9 +211,13 @@ function processFlatMode(importResult, resolvedPathsMap) {
202
211
  var _file2 = _step3.value;
203
212
  var _fileName2 = _file2.segments[_file2.segments.length - 1];
204
213
  var _isIndexFile2 = _fileName2.startsWith('index.');
214
+ var _isUnderscoreIndexFile2 = _fileName2.startsWith('_index.');
205
215
  var _distinguishingSegment = _file2.segments[distinguishingIndex];
206
216
  var _finalName = void 0;
207
- if (_isIndexFile2) {
217
+ if (_isUnderscoreIndexFile2) {
218
+ // Files starting with "_index." should always use "index" as the base name
219
+ _finalName = "".concat(_distinguishingSegment, "/index").concat(_file2.extension);
220
+ } else if (_isIndexFile2) {
208
221
  // Check if this was a direct index import
209
222
  var _originalImportParts2 = _file2.originalImportPath.split('/');
210
223
  var _isDirectIndexImport2 = _originalImportParts2.length === 2 && _originalImportParts2[0] === '.' && _originalImportParts2[1].startsWith('index.');
@@ -1,3 +1,39 @@
1
+ /**
2
+ * Converts import statements to const declarations set to null.
3
+ * This preserves variable names while removing the actual imports.
4
+ * Useful when precomputing data that makes the imports unnecessary.
5
+ *
6
+ * @param source - The source code to process
7
+ * @param importPathsToRewrite - Set of import paths whose import statements should be rewritten
8
+ * @param importResult - Import result with position and name data
9
+ * @returns The source code with import statements rewritten to const declarations
10
+ */
11
+ export declare function rewriteImportsToNull(source: string, importPathsToRewrite: Set<string>, importResult: Record<string, {
12
+ positions: Array<{
13
+ start: number;
14
+ end: number;
15
+ }>;
16
+ names: Array<{
17
+ name: string;
18
+ alias?: string;
19
+ type: string;
20
+ }>;
21
+ }>): string;
22
+ /**
23
+ * Removes entire import statements for the specified import paths.
24
+ * This removes the full import line, not just the path.
25
+ *
26
+ * @param source - The source code to process
27
+ * @param importPathsToRemove - Set of import paths whose entire import statements should be removed
28
+ * @param importResult - Import result with position data
29
+ * @returns The source code with import statements removed
30
+ */
31
+ export declare function removeImports(source: string, importPathsToRemove: Set<string>, importResult: Record<string, {
32
+ positions: Array<{
33
+ start: number;
34
+ end: number;
35
+ }>;
36
+ }>): string;
1
37
  /**
2
38
  * Efficiently rewrites import paths using position data.
3
39
  * This avoids regex parsing and uses precise position information for replacement.