@mui/internal-docs-infra 0.3.1-canary.3 → 0.3.1-canary.5

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 (102) hide show
  1. package/esm/CodeControllerContext/CodeControllerContext.js +2 -2
  2. package/esm/CodeExternalsContext/CodeExternalsContext.js +1 -1
  3. package/esm/CodeHighlighter/CodeHighlighter.js +247 -329
  4. package/esm/CodeHighlighter/CodeHighlighterClient.js +447 -653
  5. package/esm/CodeHighlighter/CodeHighlighterContext.js +2 -2
  6. package/esm/CodeHighlighter/CodeHighlighterFallbackContext.js +2 -2
  7. package/esm/CodeHighlighter/codeToFallbackProps.js +21 -37
  8. package/esm/CodeHighlighter/errors.js +248 -400
  9. package/esm/CodeHighlighter/parseControlledCode.js +12 -20
  10. package/esm/CodeProvider/CodeContext.js +3 -3
  11. package/esm/CodeProvider/CodeProvider.js +31 -40
  12. package/esm/abstractCreateDemo/abstractCreateDemo.js +13 -17
  13. package/esm/abstractCreateDemoClient/abstractCreateDemoClient.js +12 -12
  14. package/esm/cli/index.js +1 -1
  15. package/esm/cli/runValidate.js +160 -264
  16. package/esm/createDemoData/createDemoData.js +11 -12
  17. package/esm/createSitemap/createSitemap.js +2 -2
  18. package/esm/pipeline/getFileConventions/fileConventions.js +1 -1
  19. package/esm/pipeline/getFileConventions/getFileConventions.js +2 -15
  20. package/esm/pipeline/hastUtils/hastUtils.js +16 -17
  21. package/esm/pipeline/loadCodeVariant/addCodeVariantPaths.js +24 -24
  22. package/esm/pipeline/loadCodeVariant/applyCodeTransform.js +12 -22
  23. package/esm/pipeline/loadCodeVariant/calculateMainFilePath.js +30 -37
  24. package/esm/pipeline/loadCodeVariant/computeHastDeltas.js +107 -185
  25. package/esm/pipeline/loadCodeVariant/diffHast.js +18 -53
  26. package/esm/pipeline/loadCodeVariant/examineCodeVariant.js +24 -27
  27. package/esm/pipeline/loadCodeVariant/flattenCodeVariant.js +9 -10
  28. package/esm/pipeline/loadCodeVariant/hasAllCodeVariants.js +5 -5
  29. package/esm/pipeline/loadCodeVariant/loadCodeFallback.js +516 -731
  30. package/esm/pipeline/loadCodeVariant/loadCodeVariant.js +679 -1079
  31. package/esm/pipeline/loadCodeVariant/maybeCodeInitialData.js +14 -20
  32. package/esm/pipeline/loadCodeVariant/mergeCodeMetadata.js +53 -63
  33. package/esm/pipeline/loadCodeVariant/parseCode.js +40 -48
  34. package/esm/pipeline/loadCodeVariant/pathUtils.js +43 -64
  35. package/esm/pipeline/loadCodeVariant/transformSource.js +55 -125
  36. package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.js +160 -221
  37. package/esm/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js +377 -479
  38. package/esm/pipeline/loadPrecomputedCodeHighlighter/parseFunctionArguments.js +171 -173
  39. package/esm/pipeline/loadPrecomputedCodeHighlighter/performanceLogger.js +14 -30
  40. package/esm/pipeline/loadPrecomputedCodeHighlighter/replacePrecomputeValue.js +19 -21
  41. package/esm/pipeline/loadPrecomputedCodeHighlighter/serializeFunctionArguments.js +37 -71
  42. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/filterRuntimeExternals.js +3 -9
  43. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateImportStatements.js +54 -80
  44. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateResolvedExternals.js +71 -98
  45. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/injectImportsIntoSource.js +5 -5
  46. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/loadPrecomputedCodeHighlighterClient.js +161 -211
  47. package/esm/pipeline/loadPrecomputedSitemap/loadPrecomputedSitemap.js +159 -207
  48. package/esm/pipeline/loadServerCodeMeta/loadServerCodeMeta.js +42 -64
  49. package/esm/pipeline/loadServerCodeMeta/resolveModulePathWithFs.js +20 -96
  50. package/esm/pipeline/loadServerPageIndex/loadServerPageIndex.js +66 -85
  51. package/esm/pipeline/loadServerSitemap/loadServerSitemap.js +71 -118
  52. package/esm/pipeline/loadServerSource/loadServerSource.js +121 -148
  53. package/esm/pipeline/loaderUtils/externalsToPackages.js +7 -7
  54. package/esm/pipeline/loaderUtils/extractNameAndSlugFromUrl.js +8 -12
  55. package/esm/pipeline/loaderUtils/fileUrlToPortablePath.js +5 -5
  56. package/esm/pipeline/loaderUtils/getFileNameFromUrl.js +19 -29
  57. package/esm/pipeline/loaderUtils/getLanguageFromExtension.js +3 -4
  58. package/esm/pipeline/loaderUtils/mergeExternals.js +15 -35
  59. package/esm/pipeline/loaderUtils/parseImportsAndComments.js +413 -433
  60. package/esm/pipeline/loaderUtils/processRelativeImports.js +153 -239
  61. package/esm/pipeline/loaderUtils/resolveModulePath.js +544 -1303
  62. package/esm/pipeline/loaderUtils/rewriteImports.js +73 -111
  63. package/esm/pipeline/parseSource/addLineGutters.js +33 -45
  64. package/esm/pipeline/parseSource/grammars.js +3 -3
  65. package/esm/pipeline/parseSource/parseSource.js +13 -31
  66. package/esm/pipeline/syncPageIndex/createMarkdownNodes.js +32 -55
  67. package/esm/pipeline/syncPageIndex/mergeMetadataMarkdown.js +107 -160
  68. package/esm/pipeline/syncPageIndex/metadataToMarkdown.js +846 -1033
  69. package/esm/pipeline/syncPageIndex/syncPageIndex.js +291 -438
  70. package/esm/pipeline/transformHtmlCodePrecomputed/transformHtmlCodePrecomputed.js +213 -311
  71. package/esm/pipeline/transformMarkdownBlockquoteCallouts/transformMarkdownBlockquoteCallouts.js +10 -10
  72. package/esm/pipeline/transformMarkdownCode/transformMarkdownCode.js +133 -193
  73. package/esm/pipeline/transformMarkdownDemoLinks/transformMarkdownDemoLinks.js +25 -27
  74. package/esm/pipeline/transformMarkdownMetadata/transformMarkdownMetadata.js +572 -717
  75. package/esm/pipeline/transformMarkdownRelativePaths/transformMarkdownRelativePaths.js +8 -8
  76. package/esm/pipeline/transformTypescriptToJavascript/removeTypes.js +84 -113
  77. package/esm/pipeline/transformTypescriptToJavascript/transformTypescriptToJavascript.js +10 -26
  78. package/esm/useCode/Pre.js +58 -62
  79. package/esm/useCode/useCode.js +59 -61
  80. package/esm/useCode/useCodeUtils.js +54 -63
  81. package/esm/useCode/useCopyFunctionality.js +10 -9
  82. package/esm/useCode/useFileNavigation.js +150 -212
  83. package/esm/useCode/useSourceEditing.js +17 -14
  84. package/esm/useCode/useTransformManagement.js +23 -26
  85. package/esm/useCode/useUIState.js +12 -20
  86. package/esm/useCode/useVariantSelection.js +62 -79
  87. package/esm/useCopier/index.js +29 -56
  88. package/esm/useDemo/createCodeSandbox.js +12 -15
  89. package/esm/useDemo/createStackBlitz.js +14 -20
  90. package/esm/useDemo/exportVariant.js +200 -180
  91. package/esm/useDemo/exportVariantAsCra.js +22 -25
  92. package/esm/useDemo/useDemo.js +80 -84
  93. package/esm/useErrors/ErrorsContext.js +1 -1
  94. package/esm/useErrors/useErrors.js +3 -3
  95. package/esm/useLocalStorageState/useLocalStorageState.js +23 -39
  96. package/esm/usePreference/PreferencesProvider.js +1 -1
  97. package/esm/usePreference/usePreference.js +9 -11
  98. package/esm/useSearch/useSearch.js +290 -387
  99. package/esm/useUrlHashState/useUrlHashState.js +11 -14
  100. package/esm/withDocsInfra/withDeploymentConfig.js +26 -21
  101. package/esm/withDocsInfra/withDocsInfra.js +99 -101
  102. package/package.json +7 -4
@@ -1,11 +1,3 @@
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
1
  import fs from 'node:fs/promises';
10
2
  import path from 'node:path';
11
3
  import { fileURLToPath } from 'node:url';
@@ -24,29 +16,27 @@ import { markdownToMetadata } from "../syncPageIndex/metadataToMarkdown.js";
24
16
  * e.g., "docs-infra" -> "Docs Infra", "components" -> "Components"
25
17
  */
26
18
  export function pathSegmentToTitle(segment) {
27
- return segment.split('-').map(function (word) {
28
- return word.charAt(0).toUpperCase() + word.slice(1);
29
- }).join(' ');
19
+ return segment.split('-').map(word => word.charAt(0).toUpperCase() + word.slice(1)).join(' ');
30
20
  }
31
21
 
32
22
  /**
33
23
  * Recursively removes titleMarkdown fields from a heading hierarchy
34
24
  */
35
25
  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), {}, {
26
+ const result = {};
27
+ for (const [key, value] of Object.entries(hierarchy)) {
28
+ if (typeof value === 'object' && value !== null) {
29
+ const {
30
+ titleMarkdown,
31
+ children,
32
+ ...rest
33
+ } = value;
34
+ const strippedChildren = children ? stripTitleMarkdown(children) : {};
35
+ result[key] = {
36
+ ...rest,
47
37
  // Only include children if it has keys, otherwise set to undefined
48
38
  children: Object.keys(strippedChildren).length > 0 ? strippedChildren : undefined
49
- });
39
+ };
50
40
  }
51
41
  }
52
42
  return result;
@@ -58,19 +48,19 @@ export function stripTitleMarkdown(hierarchy) {
58
48
  */
59
49
  export function extractPrefixAndTitle(absolutePath, rootContext) {
60
50
  // Get the relative path from the root context
61
- var relativePath = path.relative(rootContext, absolutePath);
51
+ const relativePath = path.relative(rootContext, absolutePath);
62
52
 
63
53
  // Extract the directory path (remove filename)
64
- var dirPath = path.dirname(relativePath);
54
+ const dirPath = path.dirname(relativePath);
65
55
 
66
56
  // Split into segments
67
- var allSegments = dirPath.split(path.sep);
57
+ const allSegments = dirPath.split(path.sep);
68
58
 
69
59
  // Filter out segments:
70
60
  // - Remove leading 'src' and 'app' directory markers (only if they're at the start)
71
61
  // - Remove Next.js route groups (segments in parentheses like '(public)')
72
62
  // - Remove current directory markers ('.' and empty strings)
73
- var segments = allSegments.filter(function (seg, index) {
63
+ const segments = allSegments.filter((seg, index) => {
74
64
  // Remove 'src' only if it's the first segment
75
65
  if (seg === 'src' && index === 0) {
76
66
  return false;
@@ -91,13 +81,13 @@ export function extractPrefixAndTitle(absolutePath, rootContext) {
91
81
  });
92
82
 
93
83
  // Generate prefix with leading and trailing slashes
94
- var prefix = segments.length > 0 ? "/".concat(segments.join('/'), "/") : '/';
84
+ const prefix = segments.length > 0 ? `/${segments.join('/')}/` : '/';
95
85
 
96
86
  // Generate title from path segments
97
- var title = segments.map(pathSegmentToTitle).join(' ');
87
+ const title = segments.map(pathSegmentToTitle).join(' ');
98
88
  return {
99
- prefix: prefix,
100
- title: title
89
+ prefix,
90
+ title
101
91
  };
102
92
  }
103
93
 
@@ -105,7 +95,7 @@ export function extractPrefixAndTitle(absolutePath, rootContext) {
105
95
  * Default loadServerPageIndex function that loads page index data from a markdown file.
106
96
  * This function uses process.cwd() as the root context for resolving relative paths.
107
97
  */
108
- export var loadServerPageIndex = createLoadServerPageIndex();
98
+ export const loadServerPageIndex = createLoadServerPageIndex();
109
99
 
110
100
  /**
111
101
  * Creates a loadServerPageIndex function with custom options.
@@ -119,58 +109,49 @@ export var loadServerPageIndex = createLoadServerPageIndex();
119
109
  * @param options - Configuration options for the loader
120
110
  * @returns LoadServerPageIndex function that takes a file path and returns Promise<SitemapSectionData | null>
121
111
  */
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);
112
+ export function createLoadServerPageIndex(options = {}) {
113
+ const rootContext = options.rootContext ?? process.cwd();
114
+ return async function loadPageIndex(filePath) {
115
+ // Convert file:// URLs to proper file system paths for reading the file
116
+ // Using fileURLToPath handles Windows drive letters correctly (e.g., file:///C:/... → C:\...)
117
+ const absolutePath = filePath.startsWith('file://') ? fileURLToPath(filePath) : filePath;
118
+
119
+ // Extract prefix and title from the import path
120
+ const {
121
+ prefix,
122
+ title: generatedTitle
123
+ } = extractPrefixAndTitle(absolutePath, rootContext);
124
+
125
+ // Read the markdown file
126
+ const markdownContent = await fs.readFile(absolutePath, 'utf-8');
127
+
128
+ // Parse the markdown to extract metadata
129
+ const metadata = await markdownToMetadata(markdownContent);
130
+ if (!metadata) {
131
+ return null;
173
132
  }
174
- return loadPageIndex;
175
- }();
133
+
134
+ // Add prefix and override title with the generated one from the path
135
+ // Strip descriptionMarkdown and titleMarkdown to reduce bundle size
136
+ const enrichedMetadata = {
137
+ ...metadata,
138
+ prefix,
139
+ // Use the generated title from the path (override markdown's H1)
140
+ title: generatedTitle,
141
+ // Strip markdown AST fields from each page to reduce size
142
+ pages: metadata.pages.map(page => {
143
+ const {
144
+ descriptionMarkdown,
145
+ sections,
146
+ ...pageWithoutMarkdown
147
+ } = page;
148
+ return {
149
+ ...pageWithoutMarkdown,
150
+ // Strip titleMarkdown from sections hierarchy
151
+ sections: sections ? stripTitleMarkdown(sections) : undefined
152
+ };
153
+ })
154
+ };
155
+ return enrichedMetadata;
156
+ };
176
157
  }
@@ -1,7 +1,3 @@
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
1
  import { readFile } from 'node:fs/promises';
6
2
  import path from 'node:path';
7
3
  import { fileURLToPath } from 'node:url';
@@ -37,7 +33,7 @@ export function createSitemapSchema() {
37
33
  * This function parses the sitemap index file to find createSitemap calls and resolves
38
34
  * the page index paths from the imports.
39
35
  */
40
- export var loadServerSitemap = createLoadServerSitemap();
36
+ export const loadServerSitemap = createLoadServerSitemap();
41
37
 
42
38
  /**
43
39
  * Creates a loadServerSitemap function with custom options.
@@ -51,120 +47,77 @@ export var loadServerSitemap = createLoadServerSitemap();
51
47
  * @param options - Configuration options for the loader
52
48
  * @returns LoadServerSitemap function that takes a file URL and returns Promise<Sitemap>
53
49
  */
54
- export function createLoadServerSitemap() {
55
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
56
- return /*#__PURE__*/function () {
57
- var _loadSitemap = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(url) {
58
- var _options$rootContext;
59
- var filePath, rootContext, loadPageIndex, source, sitemapCall, entries, results, sitemapData, errors, _iterator, _step, result, errorMessages;
60
- return _regenerator().w(function (_context2) {
61
- while (1) switch (_context2.n) {
62
- case 0:
63
- // Convert file:// URL to proper file system path for reading the file
64
- // Using fileURLToPath handles Windows drive letters correctly (e.g., file:///C:/... → C:\...)
65
- filePath = url.startsWith('file://') ? fileURLToPath(url) : url; // Determine root context from file path if not provided
66
- rootContext = (_options$rootContext = options.rootContext) != null ? _options$rootContext : path.dirname(filePath); // Create page index loader with root context
67
- loadPageIndex = createLoadServerPageIndex({
68
- rootContext: rootContext
69
- }); // Read the source file to find createSitemap calls
70
- _context2.n = 1;
71
- return readFile(filePath, 'utf-8');
72
- case 1:
73
- source = _context2.v;
74
- _context2.n = 2;
75
- return parseCreateFactoryCall(source, filePath);
76
- case 2:
77
- sitemapCall = _context2.v;
78
- if (!(!sitemapCall || !sitemapCall.variants)) {
79
- _context2.n = 3;
80
- break;
81
- }
82
- return _context2.a(2, {
83
- schema: createSitemapSchema(),
84
- data: {}
85
- });
86
- case 3:
87
- // Process all page index files in parallel
88
- entries = Object.entries(sitemapCall.variants);
89
- _context2.n = 4;
90
- return Promise.all(entries.map(/*#__PURE__*/function () {
91
- var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref) {
92
- var _ref3, key, importPath, metadata, _t;
93
- return _regenerator().w(function (_context) {
94
- while (1) switch (_context.p = _context.n) {
95
- case 0:
96
- _ref3 = _slicedToArray(_ref, 2), key = _ref3[0], importPath = _ref3[1];
97
- _context.p = 1;
98
- _context.n = 2;
99
- return loadPageIndex(importPath);
100
- case 2:
101
- metadata = _context.v;
102
- return _context.a(2, {
103
- key: key,
104
- metadata: metadata,
105
- error: null
106
- });
107
- case 3:
108
- _context.p = 3;
109
- _t = _context.v;
110
- return _context.a(2, {
111
- key: key,
112
- metadata: null,
113
- error: _t instanceof Error ? _t : new Error(String(_t))
114
- });
115
- }
116
- }, _callee, null, [[1, 3]]);
117
- }));
118
- return function (_x2) {
119
- return _ref2.apply(this, arguments);
120
- };
121
- }()));
122
- case 4:
123
- results = _context2.v;
124
- // Collect results and errors
125
- sitemapData = {};
126
- errors = [];
127
- _iterator = _createForOfIteratorHelper(results);
128
- try {
129
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
130
- result = _step.value;
131
- if (result.error) {
132
- errors.push({
133
- key: result.key,
134
- error: result.error
135
- });
136
- } else if (result.metadata) {
137
- sitemapData[result.key] = result.metadata;
138
- }
139
- }
50
+ export function createLoadServerSitemap(options = {}) {
51
+ return async function loadSitemap(url) {
52
+ // Convert file:// URL to proper file system path for reading the file
53
+ // Using fileURLToPath handles Windows drive letters correctly (e.g., file:///C:/... → C:\...)
54
+ const filePath = url.startsWith('file://') ? fileURLToPath(url) : url;
140
55
 
141
- // Throw if any pages failed to load
142
- } catch (err) {
143
- _iterator.e(err);
144
- } finally {
145
- _iterator.f();
146
- }
147
- if (!(errors.length > 0)) {
148
- _context2.n = 5;
149
- break;
150
- }
151
- errorMessages = errors.map(function (_ref4) {
152
- var key = _ref4.key,
153
- error = _ref4.error;
154
- return " ".concat(key, ": ").concat(error.message);
155
- }).join('\n');
156
- throw new Error("Failed to load ".concat(errors.length, " page index(es):\n").concat(errorMessages));
157
- case 5:
158
- return _context2.a(2, {
159
- schema: createSitemapSchema(),
160
- data: sitemapData
161
- });
162
- }
163
- }, _callee2);
56
+ // Determine root context from file path if not provided
57
+ const rootContext = options.rootContext ?? path.dirname(filePath);
58
+
59
+ // Create page index loader with root context
60
+ const loadPageIndex = createLoadServerPageIndex({
61
+ rootContext
62
+ });
63
+
64
+ // Read the source file to find createSitemap calls
65
+ const source = await readFile(filePath, 'utf-8');
66
+
67
+ // Parse the source to find createSitemap call with page imports
68
+ const sitemapCall = await parseCreateFactoryCall(source, filePath);
69
+ if (!sitemapCall || !sitemapCall.variants) {
70
+ // Return empty sitemap if no createSitemap call found
71
+ return {
72
+ schema: createSitemapSchema(),
73
+ data: {}
74
+ };
75
+ }
76
+
77
+ // Process all page index files in parallel
78
+ const entries = Object.entries(sitemapCall.variants);
79
+ const results = await Promise.all(entries.map(async ([key, importPath]) => {
80
+ try {
81
+ const metadata = await loadPageIndex(importPath);
82
+ return {
83
+ key,
84
+ metadata,
85
+ error: null
86
+ };
87
+ } catch (error) {
88
+ return {
89
+ key,
90
+ metadata: null,
91
+ error: error instanceof Error ? error : new Error(String(error))
92
+ };
93
+ }
164
94
  }));
165
- function loadSitemap(_x) {
166
- return _loadSitemap.apply(this, arguments);
95
+
96
+ // Collect results and errors
97
+ const sitemapData = {};
98
+ const errors = [];
99
+ for (const result of results) {
100
+ if (result.error) {
101
+ errors.push({
102
+ key: result.key,
103
+ error: result.error
104
+ });
105
+ } else if (result.metadata) {
106
+ sitemapData[result.key] = result.metadata;
107
+ }
108
+ }
109
+
110
+ // Throw if any pages failed to load
111
+ if (errors.length > 0) {
112
+ const errorMessages = errors.map(({
113
+ key,
114
+ error
115
+ }) => ` ${key}: ${error.message}`).join('\n');
116
+ throw new Error(`Failed to load ${errors.length} page index(es):\n${errorMessages}`);
167
117
  }
168
- return loadSitemap;
169
- }();
118
+ return {
119
+ schema: createSitemapSchema(),
120
+ data: sitemapData
121
+ };
122
+ };
170
123
  }