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

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 (156) 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} +141 -55
  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 +94 -16
  51. package/esm/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js +3 -3
  52. package/esm/pipeline/loadPrecomputedCodeHighlighter/performanceLogger.d.ts +30 -0
  53. package/esm/pipeline/loadPrecomputedCodeHighlighter/performanceLogger.js +77 -0
  54. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/loadPrecomputedCodeHighlighterClient.js +24 -14
  55. package/esm/pipeline/loadPrecomputedSitemap/index.d.ts +2 -0
  56. package/esm/pipeline/loadPrecomputedSitemap/index.js +4 -0
  57. package/esm/pipeline/loadPrecomputedSitemap/loadPrecomputedSitemap.d.ts +10 -0
  58. package/esm/pipeline/loadPrecomputedSitemap/loadPrecomputedSitemap.js +220 -0
  59. package/esm/pipeline/loadServerCodeMeta/index.d.ts +2 -1
  60. package/esm/pipeline/loadServerCodeMeta/index.js +2 -1
  61. package/esm/pipeline/loadServerCodeMeta/loadServerCodeMeta.d.ts +1 -1
  62. package/esm/pipeline/loadServerCodeMeta/loadServerCodeMeta.js +7 -5
  63. package/esm/pipeline/{loaderUtils → loadServerCodeMeta}/resolveModulePathWithFs.d.ts +3 -3
  64. package/esm/pipeline/{loaderUtils → loadServerCodeMeta}/resolveModulePathWithFs.js +14 -8
  65. package/esm/pipeline/loadServerPageIndex/index.d.ts +2 -0
  66. package/esm/pipeline/loadServerPageIndex/index.js +1 -0
  67. package/esm/pipeline/loadServerPageIndex/loadServerPageIndex.d.ts +51 -0
  68. package/esm/pipeline/loadServerPageIndex/loadServerPageIndex.js +176 -0
  69. package/esm/pipeline/loadServerSitemap/index.d.ts +2 -0
  70. package/esm/pipeline/loadServerSitemap/index.js +1 -0
  71. package/esm/pipeline/loadServerSitemap/loadServerSitemap.d.ts +39 -0
  72. package/esm/pipeline/loadServerSitemap/loadServerSitemap.js +170 -0
  73. package/esm/pipeline/loadServerSource/loadServerSource.js +18 -15
  74. package/esm/pipeline/loaderUtils/externalsToPackages.js +1 -1
  75. package/esm/pipeline/loaderUtils/extractNameAndSlugFromUrl.d.ts +0 -9
  76. package/esm/pipeline/loaderUtils/extractNameAndSlugFromUrl.js +7 -7
  77. package/esm/pipeline/loaderUtils/fileUrlToPortablePath.d.ts +44 -0
  78. package/esm/pipeline/loaderUtils/fileUrlToPortablePath.js +80 -0
  79. package/esm/pipeline/loaderUtils/index.d.ts +2 -1
  80. package/esm/pipeline/loaderUtils/index.js +2 -1
  81. package/esm/pipeline/loaderUtils/parseImportsAndComments.d.ts +10 -6
  82. package/esm/pipeline/loaderUtils/parseImportsAndComments.js +17 -12
  83. package/esm/pipeline/loaderUtils/processRelativeImports.d.ts +1 -1
  84. package/esm/pipeline/loaderUtils/processRelativeImports.js +44 -27
  85. package/esm/pipeline/loaderUtils/resolveModulePath.d.ts +5 -5
  86. package/esm/pipeline/loaderUtils/resolveModulePath.js +40 -37
  87. package/esm/pipeline/loaderUtils/rewriteImports.d.ts +36 -0
  88. package/esm/pipeline/loaderUtils/rewriteImports.js +139 -8
  89. package/esm/pipeline/syncPageIndex/createMarkdownNodes.d.ts +76 -0
  90. package/esm/pipeline/syncPageIndex/createMarkdownNodes.js +305 -0
  91. package/esm/pipeline/syncPageIndex/index.d.ts +1 -0
  92. package/esm/pipeline/syncPageIndex/index.js +1 -0
  93. package/esm/pipeline/syncPageIndex/mergeMetadataMarkdown.d.ts +58 -0
  94. package/esm/pipeline/syncPageIndex/mergeMetadataMarkdown.js +214 -0
  95. package/esm/pipeline/syncPageIndex/metadataToMarkdown.d.ts +67 -0
  96. package/esm/pipeline/syncPageIndex/metadataToMarkdown.js +1486 -0
  97. package/esm/pipeline/syncPageIndex/syncPageIndex.d.ts +108 -0
  98. package/esm/pipeline/syncPageIndex/syncPageIndex.js +540 -0
  99. package/esm/pipeline/transformHtmlCodePrecomputed/transformHtmlCodePrecomputed.d.ts +2 -2
  100. package/esm/pipeline/transformHtmlCodePrecomputed/transformHtmlCodePrecomputed.js +5 -5
  101. package/esm/pipeline/transformMarkdownBlockquoteCallouts/index.d.ts +2 -0
  102. package/esm/pipeline/transformMarkdownBlockquoteCallouts/index.js +4 -0
  103. package/esm/pipeline/transformMarkdownBlockquoteCallouts/transformMarkdownBlockquoteCallouts.d.ts +16 -0
  104. package/esm/pipeline/transformMarkdownBlockquoteCallouts/transformMarkdownBlockquoteCallouts.js +58 -0
  105. package/esm/pipeline/transformMarkdownDemoLinks/index.d.ts +2 -0
  106. package/esm/pipeline/transformMarkdownDemoLinks/index.js +4 -0
  107. package/esm/pipeline/transformMarkdownDemoLinks/transformMarkdownDemoLinks.d.ts +26 -0
  108. package/esm/pipeline/transformMarkdownDemoLinks/transformMarkdownDemoLinks.js +107 -0
  109. package/esm/pipeline/transformMarkdownMetadata/index.d.ts +2 -0
  110. package/esm/pipeline/transformMarkdownMetadata/index.js +4 -0
  111. package/esm/pipeline/transformMarkdownMetadata/transformMarkdownMetadata.d.ts +3 -0
  112. package/esm/pipeline/transformMarkdownMetadata/transformMarkdownMetadata.js +1010 -0
  113. package/esm/pipeline/transformMarkdownMetadata/types.d.ts +110 -0
  114. package/esm/pipeline/transformMarkdownMetadata/types.js +1 -0
  115. package/esm/pipeline/transformMarkdownRelativePaths/index.d.ts +2 -0
  116. package/esm/pipeline/transformMarkdownRelativePaths/index.js +4 -0
  117. package/esm/pipeline/transformMarkdownRelativePaths/transformMarkdownRelativePaths.d.ts +15 -0
  118. package/esm/pipeline/transformMarkdownRelativePaths/transformMarkdownRelativePaths.js +43 -0
  119. package/esm/useCode/Pre.js +15 -2
  120. package/esm/useCode/useCode.d.ts +15 -2
  121. package/esm/useCode/useCode.js +15 -6
  122. package/esm/useCode/useCodeUtils.js +3 -3
  123. package/esm/useCode/useFileNavigation.d.ts +9 -3
  124. package/esm/useCode/useFileNavigation.js +124 -81
  125. package/esm/useCode/useUIState.d.ts +4 -1
  126. package/esm/useCode/useUIState.js +17 -2
  127. package/esm/useCode/useVariantSelection.d.ts +8 -3
  128. package/esm/useCode/useVariantSelection.js +144 -52
  129. package/esm/useCopier/index.js +5 -4
  130. package/esm/useDemo/createCodeSandbox.d.ts +1 -1
  131. package/esm/useDemo/createStackBlitz.d.ts +1 -1
  132. package/esm/useDemo/exportVariant.js +13 -11
  133. package/esm/useDemo/index.d.ts +1 -1
  134. package/esm/useDemo/index.js +1 -1
  135. package/esm/useDemo/useDemo.d.ts +5 -5
  136. package/esm/useDemo/useDemo.js +6 -6
  137. package/esm/useErrors/useErrors.d.ts +1 -1
  138. package/esm/useErrors/useErrors.js +6 -2
  139. package/esm/useSearch/index.d.ts +1 -0
  140. package/esm/useSearch/index.js +1 -0
  141. package/esm/useSearch/types.d.ts +165 -0
  142. package/esm/useSearch/types.js +1 -0
  143. package/esm/useSearch/useSearch.d.ts +56 -0
  144. package/esm/useSearch/useSearch.js +647 -0
  145. package/esm/withDocsInfra/withDeploymentConfig.js +4 -2
  146. package/esm/withDocsInfra/withDocsInfra.d.ts +39 -0
  147. package/esm/withDocsInfra/withDocsInfra.js +94 -14
  148. package/package.json +105 -5
  149. package/esm/CodeHighlighter/transformParsedSource.d.ts +0 -3
  150. /package/esm/{CodeHighlighter/addPathsToVariant.js → pipeline/loadCodeVariant/addCodeVariantPaths.js} +0 -0
  151. /package/esm/{CodeHighlighter → pipeline/loadCodeVariant}/calculateMainFilePath.d.ts +0 -0
  152. /package/esm/{CodeHighlighter/hasAllVariants.js → pipeline/loadCodeVariant/hasAllCodeVariants.js} +0 -0
  153. /package/esm/{CodeHighlighter → pipeline/loadCodeVariant}/parseCode.js +0 -0
  154. /package/esm/{CodeHighlighter → pipeline/loadCodeVariant}/pathUtils.d.ts +0 -0
  155. /package/esm/{CodeHighlighter → pipeline/loadCodeVariant}/pathUtils.js +0 -0
  156. /package/esm/{CodeHighlighter → pipeline/loadCodeVariant}/transformSource.js +0 -0
@@ -0,0 +1,220 @@
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
+ // webpack does not like node: imports
6
+ // eslint-disable-next-line n/prefer-node-protocol
7
+ import path from 'path';
8
+ // eslint-disable-next-line n/prefer-node-protocol
9
+ import { fileURLToPath, pathToFileURL } from 'url';
10
+ import { createPerformanceLogger, logPerformance, nameMark, performanceMeasure } from "../loadPrecomputedCodeHighlighter/performanceLogger.js";
11
+ import { parseCreateFactoryCall } from "../loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js";
12
+ import { replacePrecomputeValue } from "../loadPrecomputedCodeHighlighter/replacePrecomputeValue.js";
13
+ import { rewriteImportsToNull } from "../loaderUtils/rewriteImports.js";
14
+ import { createLoadServerPageIndex } from "../loadServerPageIndex/loadServerPageIndex.js";
15
+ import { createSitemapSchema } from "../loadServerSitemap/loadServerSitemap.js";
16
+ var functionName = 'Load Precomputed Sitemap';
17
+ export function loadPrecomputedSitemap(_x) {
18
+ return _loadPrecomputedSitemap.apply(this, arguments);
19
+ }
20
+ function _loadPrecomputedSitemap() {
21
+ _loadPrecomputedSitemap = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(source) {
22
+ var _options$performance$, _options$performance, _options$performance$2, _options$performance2, _options$performance3;
23
+ var callback, options, performanceNotableMs, performanceShowWrapperMeasures, relativePath, observer, currentMark, _observer, _observer2, resourceFileUrl, sitemapCall, variants, sitemapData, rootContext, loadPageIndex, entries, results, _iterator, _step, result, precomputeData, modifiedSource, relative, importPathsToRewrite, importResult, _i, _Object$entries, _Object$entries$_i, importPath, importData, _observer3, _observer4, _t2;
24
+ return _regenerator().w(function (_context2) {
25
+ while (1) switch (_context2.p = _context2.n) {
26
+ case 0:
27
+ callback = this.async();
28
+ this.cacheable();
29
+ options = this.getOptions();
30
+ performanceNotableMs = (_options$performance$ = (_options$performance = options.performance) == null ? void 0 : _options$performance.notableMs) != null ? _options$performance$ : 100;
31
+ performanceShowWrapperMeasures = (_options$performance$2 = (_options$performance2 = options.performance) == null ? void 0 : _options$performance2.showWrapperMeasures) != null ? _options$performance$2 : false; // const resourceName = extractNameAndSlugFromUrl(
32
+ // new URL('.', `file://${this.resourcePath}`).pathname,
33
+ // ).name;
34
+ relativePath = path.relative(this.rootContext || process.cwd(), this.resourcePath);
35
+ observer = undefined;
36
+ if ((_options$performance3 = options.performance) != null && _options$performance3.logging) {
37
+ observer = new PerformanceObserver(createPerformanceLogger(performanceNotableMs, performanceShowWrapperMeasures, relativePath));
38
+ observer.observe({
39
+ entryTypes: ['measure']
40
+ });
41
+ }
42
+ currentMark = nameMark(functionName, 'Start Loading', [relativePath]);
43
+ performance.mark(currentMark);
44
+ _context2.p = 1;
45
+ // Convert the filesystem path to a file:// URL for cross-platform compatibility
46
+ // pathToFileURL handles Windows drive letters correctly (e.g., C:\... → file:///C:/...)
47
+ resourceFileUrl = pathToFileURL(this.resourcePath).toString(); // Parse the source to find a single createSitemap call
48
+ _context2.n = 2;
49
+ return parseCreateFactoryCall(source, resourceFileUrl);
50
+ case 2:
51
+ sitemapCall = _context2.v;
52
+ currentMark = performanceMeasure(currentMark, {
53
+ mark: 'Parsed Factory',
54
+ measure: 'Factory Parsing'
55
+ }, [functionName, relativePath]);
56
+
57
+ // If no createSitemap call found, return the source unchanged
58
+ if (sitemapCall) {
59
+ _context2.n = 3;
60
+ break;
61
+ }
62
+ callback(null, source);
63
+ return _context2.a(2);
64
+ case 3:
65
+ if (!sitemapCall.options.skipPrecompute) {
66
+ _context2.n = 4;
67
+ break;
68
+ }
69
+ callback(null, source);
70
+ return _context2.a(2);
71
+ case 4:
72
+ // Extract the variants (imported markdown files)
73
+ variants = sitemapCall.variants;
74
+ if (!(!variants || Object.keys(variants).length === 0)) {
75
+ _context2.n = 5;
76
+ break;
77
+ }
78
+ callback(null, source);
79
+ return _context2.a(2);
80
+ case 5:
81
+ currentMark = performanceMeasure(currentMark, {
82
+ mark: 'Extracted Variants',
83
+ measure: 'Variant Extraction'
84
+ }, [functionName, relativePath]);
85
+
86
+ // Read and parse each markdown file
87
+ sitemapData = {}; // Create page index loader with root context
88
+ rootContext = this.rootContext || process.cwd();
89
+ loadPageIndex = createLoadServerPageIndex({
90
+ rootContext: rootContext
91
+ }); // Process all markdown files in parallel using shared logic
92
+ entries = Object.entries(variants);
93
+ _context2.n = 6;
94
+ return Promise.all(entries.map(/*#__PURE__*/function () {
95
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref) {
96
+ var _ref3, key, importPath, absolutePath, metadata, _t;
97
+ return _regenerator().w(function (_context) {
98
+ while (1) switch (_context.p = _context.n) {
99
+ case 0:
100
+ _ref3 = _slicedToArray(_ref, 2), key = _ref3[0], importPath = _ref3[1];
101
+ // Convert file:// URLs to proper file system paths for webpack's dependency tracking
102
+ // Using fileURLToPath handles Windows drive letters correctly (e.g., file:///C:/... → C:\...)
103
+ absolutePath = importPath.startsWith('file://') ? fileURLToPath(importPath) : importPath;
104
+ _context.p = 1;
105
+ _context.n = 2;
106
+ return loadPageIndex(importPath);
107
+ case 2:
108
+ metadata = _context.v;
109
+ return _context.a(2, {
110
+ key: key,
111
+ absolutePath: absolutePath,
112
+ metadata: metadata,
113
+ error: null
114
+ });
115
+ case 3:
116
+ _context.p = 3;
117
+ _t = _context.v;
118
+ return _context.a(2, {
119
+ key: key,
120
+ absolutePath: absolutePath,
121
+ metadata: null,
122
+ error: _t instanceof Error ? _t : new Error(String(_t))
123
+ });
124
+ }
125
+ }, _callee, null, [[1, 3]]);
126
+ }));
127
+ return function (_x2) {
128
+ return _ref2.apply(this, arguments);
129
+ };
130
+ }()));
131
+ case 6:
132
+ results = _context2.v;
133
+ currentMark = performanceMeasure(currentMark, {
134
+ mark: 'Processed All Files',
135
+ measure: 'Process Markdown Files'
136
+ }, [functionName, relativePath]);
137
+
138
+ // Collect results and dependencies
139
+ _iterator = _createForOfIteratorHelper(results);
140
+ try {
141
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
142
+ result = _step.value;
143
+ if (result.error) {
144
+ // Log error but continue processing other files
145
+ console.error("Failed to process ".concat(result.key, " at ").concat(result.absolutePath, ":"), result.error);
146
+ } else if (result.metadata) {
147
+ sitemapData[result.key] = result.metadata;
148
+ // Add to dependencies for webpack watching
149
+ this.addDependency(result.absolutePath);
150
+ }
151
+ }
152
+
153
+ // Create sitemap with Orama schema for search indexing
154
+ } catch (err) {
155
+ _iterator.e(err);
156
+ } finally {
157
+ _iterator.f();
158
+ }
159
+ precomputeData = {
160
+ schema: createSitemapSchema(),
161
+ data: sitemapData
162
+ }; // Replace the factory function call with the precomputed sitemap data
163
+ modifiedSource = replacePrecomputeValue(source, precomputeData, sitemapCall);
164
+ performanceMeasure(currentMark, {
165
+ mark: 'replaced precompute',
166
+ measure: 'precompute replacement'
167
+ }, [functionName, relativePath]);
168
+
169
+ // Rewrite MDX imports to const declarations since we've precomputed the data
170
+ if (sitemapCall.importsAndComments) {
171
+ relative = sitemapCall.importsAndComments.relative; // Build a set of MDX imports to rewrite
172
+ importPathsToRewrite = new Set();
173
+ importResult = {};
174
+ for (_i = 0, _Object$entries = Object.entries(relative); _i < _Object$entries.length; _i++) {
175
+ _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2), importPath = _Object$entries$_i[0], importData = _Object$entries$_i[1];
176
+ // Check if this is an MDX file
177
+ if (importPath.endsWith('.mdx')) {
178
+ // Add to the set of imports to rewrite
179
+ importPathsToRewrite.add(importPath);
180
+ importResult[importPath] = {
181
+ positions: importData.positions,
182
+ names: importData.names
183
+ };
184
+ }
185
+ }
186
+
187
+ // Rewrite the import statements to const declarations if there are any MDX imports
188
+ if (importPathsToRewrite.size > 0) {
189
+ modifiedSource = rewriteImportsToNull(modifiedSource, importPathsToRewrite, importResult);
190
+ currentMark = performanceMeasure(currentMark, {
191
+ mark: 'rewritten imports',
192
+ measure: 'import rewriting'
193
+ }, [functionName, relativePath]);
194
+ }
195
+ }
196
+
197
+ // log any pending performance entries before completing
198
+ (_observer = observer) == null || (_observer = _observer.takeRecords()) == null || _observer.forEach(function (entry) {
199
+ return logPerformance(entry, performanceNotableMs, performanceShowWrapperMeasures, relativePath);
200
+ });
201
+ (_observer2 = observer) == null || _observer2.disconnect();
202
+ callback(null, modifiedSource);
203
+ _context2.n = 8;
204
+ break;
205
+ case 7:
206
+ _context2.p = 7;
207
+ _t2 = _context2.v;
208
+ // log any pending performance entries before completing
209
+ (_observer3 = observer) == null || (_observer3 = _observer3.takeRecords()) == null || _observer3.forEach(function (entry) {
210
+ return logPerformance(entry, performanceNotableMs, performanceShowWrapperMeasures, relativePath);
211
+ });
212
+ (_observer4 = observer) == null || _observer4.disconnect();
213
+ callback(_t2 instanceof Error ? _t2 : new Error(String(_t2)));
214
+ case 8:
215
+ return _context2.a(2);
216
+ }
217
+ }, _callee2, this, [[1, 7]]);
218
+ }));
219
+ return _loadPrecomputedSitemap.apply(this, arguments);
220
+ }
@@ -1 +1,2 @@
1
- export * from "./loadServerCodeMeta.js";
1
+ export * from "./loadServerCodeMeta.js";
2
+ export * from "./resolveModulePathWithFs.js";
@@ -1 +1,2 @@
1
- export * from "./loadServerCodeMeta.js";
1
+ export * from "./loadServerCodeMeta.js";
2
+ export * from "./resolveModulePathWithFs.js";
@@ -16,7 +16,7 @@ export declare const loadServerCodeMeta: LoadCodeMeta;
16
16
  * 3. Returns a Code object mapping variant names to their resolved file URLs
17
17
  *
18
18
  * The actual loading, parsing, and transformation of the variants is handled
19
- * elsewhere by the CodeHighlighter component using loadVariant.
19
+ * elsewhere by the CodeHighlighter component using loadCodeVariant.
20
20
  *
21
21
  * @param options - Configuration options (currently unused)
22
22
  * @returns LoadCodeMeta function that takes a URL and returns Promise<Code>
@@ -2,7 +2,8 @@ import _regenerator from "@babel/runtime/helpers/esm/regenerator";
2
2
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
3
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
4
4
  import { readFile } from 'node:fs/promises';
5
- import { resolveVariantPathsWithFs } from "../loaderUtils/resolveModulePathWithFs.js";
5
+ import { fileURLToPath } from 'node:url';
6
+ import { resolveVariantPathsWithFs } from "./resolveModulePathWithFs.js";
6
7
  import { parseCreateFactoryCall } from "../loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js";
7
8
  import { getFileNameFromUrl } from "../loaderUtils/index.js";
8
9
  /**
@@ -22,7 +23,7 @@ export var loadServerCodeMeta = createLoadServerCodeMeta();
22
23
  * 3. Returns a Code object mapping variant names to their resolved file URLs
23
24
  *
24
25
  * The actual loading, parsing, and transformation of the variants is handled
25
- * elsewhere by the CodeHighlighter component using loadVariant.
26
+ * elsewhere by the CodeHighlighter component using loadCodeVariant.
26
27
  *
27
28
  * @param options - Configuration options (currently unused)
28
29
  * @returns LoadCodeMeta function that takes a URL and returns Promise<Code>
@@ -35,14 +36,15 @@ export function createLoadServerCodeMeta() {
35
36
  return _regenerator().w(function (_context) {
36
37
  while (1) switch (_context.n) {
37
38
  case 0:
38
- // Remove file:// prefix if present to get file path
39
- filePath = url.replace('file://', ''); // Read the source file to find createDemo calls
39
+ // Convert file:// URL to proper file system path for reading the file
40
+ // Using fileURLToPath handles Windows drive letters correctly (e.g., file:///C:/... C:\...)
41
+ filePath = url.startsWith('file://') ? fileURLToPath(url) : url; // Read the source file to find createDemo calls
40
42
  _context.n = 1;
41
43
  return readFile(filePath, 'utf-8');
42
44
  case 1:
43
45
  source = _context.v;
44
46
  _context.n = 2;
45
- return parseCreateFactoryCall(source, filePath);
47
+ return parseCreateFactoryCall(source, url);
46
48
  case 2:
47
49
  demoCall = _context.v;
48
50
  if (!(!demoCall || !demoCall.variants)) {
@@ -1,4 +1,4 @@
1
- import { type DirectoryEntry, type DirectoryReader, type ResolveModulePathOptions, type TypeAwareResolveResult } from "./resolveModulePath.js";
1
+ import { type DirectoryEntry, type DirectoryReader, type ResolveModulePathOptions, type TypeAwareResolveResult } from "../loaderUtils/resolveModulePath.js";
2
2
  /**
3
3
  * Resolves a module path using Node.js filesystem APIs.
4
4
  * This is a convenience wrapper around the generic resolveModulePath function.
@@ -18,7 +18,7 @@ export declare function resolveModulePathWithFs(modulePath: string, options: Res
18
18
  * @param options - Configuration options
19
19
  * @returns Promise<Map<string, string>> - Map from input path to resolved file path
20
20
  */
21
- export declare function resolveModulePathsWithFs(modulePaths: string[], options?: ResolveModulePathOptions): Promise<Map<string, string>>;
21
+ export declare function resolveModulePathsWithFs(moduleUrls: string[], options?: ResolveModulePathOptions): Promise<Map<string, string>>;
22
22
  /**
23
23
  * Resolves import result by separating JavaScript modules from static assets,
24
24
  * only resolving JavaScript modules and returning a combined map.
@@ -30,7 +30,7 @@ export declare function resolveModulePathsWithFs(modulePaths: string[], options?
30
30
  * @returns Promise<Map<string, string>> - Map from import path to resolved file path
31
31
  */
32
32
  export declare function resolveImportResultWithFs(importResult: Record<string, {
33
- path: string;
33
+ url: string;
34
34
  names: string[];
35
35
  includeTypeDefs?: true;
36
36
  positions?: Array<{
@@ -3,20 +3,26 @@ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
3
  // webpack does not like node: imports
4
4
  // eslint-disable-next-line n/prefer-node-protocol
5
5
  import { readdir } from 'fs/promises';
6
- import { resolveModulePath, resolveModulePaths, resolveImportResult, resolveVariantPaths } from "./resolveModulePath.js";
6
+ // eslint-disable-next-line n/prefer-node-protocol
7
+ import { fileURLToPath } from 'url';
8
+ import { resolveModulePath, resolveModulePaths, resolveImportResult, resolveVariantPaths } from "../loaderUtils/resolveModulePath.js";
7
9
 
8
10
  /**
9
11
  * Node.js filesystem-based directory reader that converts Dirent objects
10
12
  * to the DirectoryEntry interface expected by the resolver functions.
13
+ *
14
+ * The input is a file:// URL. We convert it to a filesystem path using fileURLToPath.
11
15
  */
12
16
  var nodeDirectoryReader = /*#__PURE__*/function () {
13
- var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(path) {
14
- var entries;
17
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(fileUrl) {
18
+ var fsPath, entries;
15
19
  return _regenerator().w(function (_context) {
16
20
  while (1) switch (_context.n) {
17
21
  case 0:
22
+ // Convert file:// URL to filesystem path for Node.js fs APIs
23
+ fsPath = fileURLToPath(fileUrl);
18
24
  _context.n = 1;
19
- return readdir(path, {
25
+ return readdir(fsPath, {
20
26
  withFileTypes: true
21
27
  });
22
28
  case 1:
@@ -59,7 +65,7 @@ export function resolveModulePathWithFs(_x2) {
59
65
  * @returns Promise<Map<string, string>> - Map from input path to resolved file path
60
66
  */
61
67
  function _resolveModulePathWithFs() {
62
- _resolveModulePathWithFs = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(modulePath) {
68
+ _resolveModulePathWithFs = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(moduleUrl) {
63
69
  var options,
64
70
  includeTypeDefs,
65
71
  _args2 = arguments;
@@ -68,7 +74,7 @@ function _resolveModulePathWithFs() {
68
74
  case 0:
69
75
  options = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : {};
70
76
  includeTypeDefs = _args2.length > 2 ? _args2[2] : undefined;
71
- return _context2.a(2, resolveModulePath(modulePath, nodeDirectoryReader, options, includeTypeDefs));
77
+ return _context2.a(2, resolveModulePath(moduleUrl, nodeDirectoryReader, options, includeTypeDefs));
72
78
  }
73
79
  }, _callee2);
74
80
  }));
@@ -89,14 +95,14 @@ export function resolveModulePathsWithFs(_x3) {
89
95
  * @returns Promise<Map<string, string>> - Map from import path to resolved file path
90
96
  */
91
97
  function _resolveModulePathsWithFs() {
92
- _resolveModulePathsWithFs = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(modulePaths) {
98
+ _resolveModulePathsWithFs = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(moduleUrls) {
93
99
  var options,
94
100
  _args3 = arguments;
95
101
  return _regenerator().w(function (_context3) {
96
102
  while (1) switch (_context3.n) {
97
103
  case 0:
98
104
  options = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : {};
99
- return _context3.a(2, resolveModulePaths(modulePaths, nodeDirectoryReader, options));
105
+ return _context3.a(2, resolveModulePaths(moduleUrls, nodeDirectoryReader, options));
100
106
  }
101
107
  }, _callee3);
102
108
  }));
@@ -0,0 +1,2 @@
1
+ export { loadServerPageIndex, createLoadServerPageIndex, extractPrefixAndTitle, pathSegmentToTitle, stripTitleMarkdown } from "./loadServerPageIndex.js";
2
+ export type { CreateLoadServerPageIndexOptions, LoadServerPageIndex } from "./loadServerPageIndex.js";
@@ -0,0 +1 @@
1
+ export { loadServerPageIndex, createLoadServerPageIndex, extractPrefixAndTitle, pathSegmentToTitle, stripTitleMarkdown } from "./loadServerPageIndex.js";
@@ -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,176 @@
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 { fileURLToPath } from 'node:url';
12
+ import { markdownToMetadata } from "../syncPageIndex/metadataToMarkdown.js";
13
+
14
+ /**
15
+ * Options for creating a loadServerPageIndex function
16
+ */
17
+
18
+ /**
19
+ * Function type for loading page index data from a markdown file
20
+ */
21
+
22
+ /**
23
+ * Converts a path segment to a title
24
+ * e.g., "docs-infra" -> "Docs Infra", "components" -> "Components"
25
+ */
26
+ export function pathSegmentToTitle(segment) {
27
+ return segment.split('-').map(function (word) {
28
+ return word.charAt(0).toUpperCase() + word.slice(1);
29
+ }).join(' ');
30
+ }
31
+
32
+ /**
33
+ * Recursively removes titleMarkdown fields from a heading hierarchy
34
+ */
35
+ export function stripTitleMarkdown(hierarchy) {
36
+ var result = {};
37
+ for (var _i = 0, _Object$entries = Object.entries(hierarchy); _i < _Object$entries.length; _i++) {
38
+ var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
39
+ key = _Object$entries$_i[0],
40
+ value = _Object$entries$_i[1];
41
+ if (_typeof(value) === 'object' && value !== null) {
42
+ var titleMarkdown = value.titleMarkdown,
43
+ children = value.children,
44
+ rest = _objectWithoutPropertiesLoose(value, _excluded);
45
+ var strippedChildren = children ? stripTitleMarkdown(children) : {};
46
+ result[key] = _extends(_extends({}, rest), {}, {
47
+ // Only include children if it has keys, otherwise set to undefined
48
+ children: Object.keys(strippedChildren).length > 0 ? strippedChildren : undefined
49
+ });
50
+ }
51
+ }
52
+ return result;
53
+ }
54
+
55
+ /**
56
+ * Extracts prefix and title from an import path
57
+ * e.g., "/path/to/app/docs-infra/components/page.mdx" -> { prefix: "/docs-infra/components/", title: "Docs Infra Components" }
58
+ */
59
+ export function extractPrefixAndTitle(absolutePath, rootContext) {
60
+ // Get the relative path from the root context
61
+ var relativePath = path.relative(rootContext, absolutePath);
62
+
63
+ // Extract the directory path (remove filename)
64
+ var dirPath = path.dirname(relativePath);
65
+
66
+ // Split into segments
67
+ var allSegments = dirPath.split(path.sep);
68
+
69
+ // Filter out segments:
70
+ // - Remove leading 'src' and 'app' directory markers (only if they're at the start)
71
+ // - Remove Next.js route groups (segments in parentheses like '(public)')
72
+ // - Remove current directory markers ('.' and empty strings)
73
+ var segments = allSegments.filter(function (seg, index) {
74
+ // Remove 'src' only if it's the first segment
75
+ if (seg === 'src' && index === 0) {
76
+ return false;
77
+ }
78
+ // Remove 'app' only if it's the first or second segment (after 'src')
79
+ if (seg === 'app' && (index === 0 || index === 1 && allSegments[0] === 'src')) {
80
+ return false;
81
+ }
82
+ // Filter out Next.js route groups (e.g., '(public)', '(content)')
83
+ if (seg.startsWith('(') && seg.endsWith(')')) {
84
+ return false;
85
+ }
86
+ // Filter out current directory markers
87
+ if (seg === '.' || seg === '') {
88
+ return false;
89
+ }
90
+ return true;
91
+ });
92
+
93
+ // Generate prefix with leading and trailing slashes
94
+ var prefix = segments.length > 0 ? "/".concat(segments.join('/'), "/") : '/';
95
+
96
+ // Generate title from path segments
97
+ var title = segments.map(pathSegmentToTitle).join(' ');
98
+ return {
99
+ prefix: prefix,
100
+ title: title
101
+ };
102
+ }
103
+
104
+ /**
105
+ * Default loadServerPageIndex function that loads page index data from a markdown file.
106
+ * This function uses process.cwd() as the root context for resolving relative paths.
107
+ */
108
+ export var loadServerPageIndex = createLoadServerPageIndex();
109
+
110
+ /**
111
+ * Creates a loadServerPageIndex function with custom options.
112
+ *
113
+ * This factory function creates a LoadServerPageIndex implementation that:
114
+ * 1. Reads the markdown file from the provided file path
115
+ * 2. Parses the markdown to extract metadata using markdownToMetadata
116
+ * 3. Enriches the metadata with prefix and title derived from the file path
117
+ * 4. Returns a SitemapSectionData object with page data
118
+ *
119
+ * @param options - Configuration options for the loader
120
+ * @returns LoadServerPageIndex function that takes a file path and returns Promise<SitemapSectionData | null>
121
+ */
122
+ export function createLoadServerPageIndex() {
123
+ var _options$rootContext;
124
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
125
+ var rootContext = (_options$rootContext = options.rootContext) != null ? _options$rootContext : process.cwd();
126
+ return /*#__PURE__*/function () {
127
+ var _loadPageIndex = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(filePath) {
128
+ var absolutePath, _extractPrefixAndTitl, prefix, generatedTitle, markdownContent, metadata, enrichedMetadata;
129
+ return _regenerator().w(function (_context) {
130
+ while (1) switch (_context.n) {
131
+ case 0:
132
+ // Convert file:// URLs to proper file system paths for reading the file
133
+ // Using fileURLToPath handles Windows drive letters correctly (e.g., file:///C:/... → C:\...)
134
+ absolutePath = filePath.startsWith('file://') ? fileURLToPath(filePath) : filePath; // Extract prefix and title from the import path
135
+ _extractPrefixAndTitl = extractPrefixAndTitle(absolutePath, rootContext), prefix = _extractPrefixAndTitl.prefix, generatedTitle = _extractPrefixAndTitl.title; // Read the markdown file
136
+ _context.n = 1;
137
+ return fs.readFile(absolutePath, 'utf-8');
138
+ case 1:
139
+ markdownContent = _context.v;
140
+ _context.n = 2;
141
+ return markdownToMetadata(markdownContent);
142
+ case 2:
143
+ metadata = _context.v;
144
+ if (metadata) {
145
+ _context.n = 3;
146
+ break;
147
+ }
148
+ return _context.a(2, null);
149
+ case 3:
150
+ // Add prefix and override title with the generated one from the path
151
+ // Strip descriptionMarkdown and titleMarkdown to reduce bundle size
152
+ enrichedMetadata = _extends(_extends({}, metadata), {}, {
153
+ prefix: prefix,
154
+ // Use the generated title from the path (override markdown's H1)
155
+ title: generatedTitle,
156
+ // Strip markdown AST fields from each page to reduce size
157
+ pages: metadata.pages.map(function (page) {
158
+ var descriptionMarkdown = page.descriptionMarkdown,
159
+ sections = page.sections,
160
+ pageWithoutMarkdown = _objectWithoutPropertiesLoose(page, _excluded2);
161
+ return _extends(_extends({}, pageWithoutMarkdown), {}, {
162
+ // Strip titleMarkdown from sections hierarchy
163
+ sections: sections ? stripTitleMarkdown(sections) : undefined
164
+ });
165
+ })
166
+ });
167
+ return _context.a(2, enrichedMetadata);
168
+ }
169
+ }, _callee);
170
+ }));
171
+ function loadPageIndex(_x) {
172
+ return _loadPageIndex.apply(this, arguments);
173
+ }
174
+ return loadPageIndex;
175
+ }();
176
+ }
@@ -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;