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

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,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
  // webpack does not like node: imports
6
2
  // eslint-disable-next-line n/prefer-node-protocol
7
3
  import path from 'path';
@@ -13,208 +9,164 @@ import { replacePrecomputeValue } from "../loadPrecomputedCodeHighlighter/replac
13
9
  import { rewriteImportsToNull } from "../loaderUtils/rewriteImports.js";
14
10
  import { createLoadServerPageIndex } from "../loadServerPageIndex/loadServerPageIndex.js";
15
11
  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);
12
+ const functionName = 'Load Precomputed Sitemap';
13
+ export async function loadPrecomputedSitemap(source) {
14
+ const callback = this.async();
15
+ this.cacheable();
16
+ const options = this.getOptions();
17
+ const performanceNotableMs = options.performance?.notableMs ?? 100;
18
+ const performanceShowWrapperMeasures = options.performance?.showWrapperMeasures ?? false;
19
+
20
+ // const resourceName = extractNameAndSlugFromUrl(
21
+ // new URL('.', `file://${this.resourcePath}`).pathname,
22
+ // ).name;
23
+
24
+ const relativePath = path.relative(this.rootContext || process.cwd(), this.resourcePath);
25
+ let observer = undefined;
26
+ if (options.performance?.logging) {
27
+ observer = new PerformanceObserver(createPerformanceLogger(performanceNotableMs, performanceShowWrapperMeasures, relativePath));
28
+ observer.observe({
29
+ entryTypes: ['measure']
30
+ });
31
+ }
32
+ let currentMark = nameMark(functionName, 'Start Loading', [relativePath]);
33
+ performance.mark(currentMark);
34
+ try {
35
+ // Convert the filesystem path to a file:// URL for cross-platform compatibility
36
+ // pathToFileURL handles Windows drive letters correctly (e.g., C:\... → file:///C:/...)
37
+ const resourceFileUrl = pathToFileURL(this.resourcePath).toString();
38
+
39
+ // Parse the source to find a single createSitemap call
40
+ const sitemapCall = await parseCreateFactoryCall(source, resourceFileUrl);
41
+ currentMark = performanceMeasure(currentMark, {
42
+ mark: 'Parsed Factory',
43
+ measure: 'Factory Parsing'
44
+ }, [functionName, relativePath]);
45
+
46
+ // If no createSitemap call found, return the source unchanged
47
+ if (!sitemapCall) {
48
+ callback(null, source);
49
+ return;
50
+ }
51
+
52
+ // If skipPrecompute is true, return the source unchanged
53
+ if (sitemapCall.options.skipPrecompute) {
54
+ callback(null, source);
55
+ return;
56
+ }
57
+
58
+ // Extract the variants (imported markdown files)
59
+ const variants = sitemapCall.variants;
60
+ if (!variants || Object.keys(variants).length === 0) {
61
+ callback(null, source);
62
+ return;
63
+ }
64
+ currentMark = performanceMeasure(currentMark, {
65
+ mark: 'Extracted Variants',
66
+ measure: 'Variant Extraction'
67
+ }, [functionName, relativePath]);
68
+
69
+ // Read and parse each markdown file
70
+ const sitemapData = {};
71
+
72
+ // Create page index loader with root context
73
+ const rootContext = this.rootContext || process.cwd();
74
+ const loadPageIndex = createLoadServerPageIndex({
75
+ rootContext
76
+ });
77
+
78
+ // Process all markdown files in parallel using shared logic
79
+ const entries = Object.entries(variants);
80
+ const results = await Promise.all(entries.map(async ([key, importPath]) => {
81
+ // Convert file:// URLs to proper file system paths for webpack's dependency tracking
82
+ // Using fileURLToPath handles Windows drive letters correctly (e.g., file:///C:/... → C:\...)
83
+ const absolutePath = importPath.startsWith('file://') ? fileURLToPath(importPath) : importPath;
84
+ try {
85
+ const metadata = await loadPageIndex(importPath);
86
+ return {
87
+ key,
88
+ absolutePath,
89
+ metadata,
90
+ error: null
91
+ };
92
+ } catch (error) {
93
+ return {
94
+ key,
95
+ absolutePath,
96
+ metadata: null,
97
+ error: error instanceof Error ? error : new Error(String(error))
98
+ };
216
99
  }
217
- }, _callee2, this, [[1, 7]]);
218
- }));
219
- return _loadPrecomputedSitemap.apply(this, arguments);
100
+ }));
101
+ currentMark = performanceMeasure(currentMark, {
102
+ mark: 'Processed All Files',
103
+ measure: 'Process Markdown Files'
104
+ }, [functionName, relativePath]);
105
+
106
+ // Collect results and dependencies
107
+ for (const result of results) {
108
+ if (result.error) {
109
+ // Log error but continue processing other files
110
+ console.error(`Failed to process ${result.key} at ${result.absolutePath}:`, result.error);
111
+ } else if (result.metadata) {
112
+ sitemapData[result.key] = result.metadata;
113
+ // Add to dependencies for webpack watching
114
+ this.addDependency(result.absolutePath);
115
+ }
116
+ }
117
+
118
+ // Create sitemap with Orama schema for search indexing
119
+ const precomputeData = {
120
+ schema: createSitemapSchema(),
121
+ data: sitemapData
122
+ };
123
+
124
+ // Replace the factory function call with the precomputed sitemap data
125
+ let modifiedSource = replacePrecomputeValue(source, precomputeData, sitemapCall);
126
+ performanceMeasure(currentMark, {
127
+ mark: 'replaced precompute',
128
+ measure: 'precompute replacement'
129
+ }, [functionName, relativePath]);
130
+
131
+ // Rewrite MDX imports to const declarations since we've precomputed the data
132
+ if (sitemapCall.importsAndComments) {
133
+ const {
134
+ relative
135
+ } = sitemapCall.importsAndComments;
136
+
137
+ // Build a set of MDX imports to rewrite
138
+ const importPathsToRewrite = new Set();
139
+ const importResult = {};
140
+ for (const [importPath, importData] of Object.entries(relative)) {
141
+ // Check if this is an MDX file
142
+ if (importPath.endsWith('.mdx')) {
143
+ // Add to the set of imports to rewrite
144
+ importPathsToRewrite.add(importPath);
145
+ importResult[importPath] = {
146
+ positions: importData.positions,
147
+ names: importData.names
148
+ };
149
+ }
150
+ }
151
+
152
+ // Rewrite the import statements to const declarations if there are any MDX imports
153
+ if (importPathsToRewrite.size > 0) {
154
+ modifiedSource = rewriteImportsToNull(modifiedSource, importPathsToRewrite, importResult);
155
+ currentMark = performanceMeasure(currentMark, {
156
+ mark: 'rewritten imports',
157
+ measure: 'import rewriting'
158
+ }, [functionName, relativePath]);
159
+ }
160
+ }
161
+
162
+ // log any pending performance entries before completing
163
+ observer?.takeRecords()?.forEach(entry => logPerformance(entry, performanceNotableMs, performanceShowWrapperMeasures, relativePath));
164
+ observer?.disconnect();
165
+ callback(null, modifiedSource);
166
+ } catch (error) {
167
+ // log any pending performance entries before completing
168
+ observer?.takeRecords()?.forEach(entry => logPerformance(entry, performanceNotableMs, performanceShowWrapperMeasures, relativePath));
169
+ observer?.disconnect();
170
+ callback(error instanceof Error ? error : new Error(String(error)));
171
+ }
220
172
  }
@@ -1,6 +1,3 @@
1
- import _regenerator from "@babel/runtime/helpers/esm/regenerator";
2
- import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
- import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
4
1
  import { readFile } from 'node:fs/promises';
5
2
  import { fileURLToPath } from 'node:url';
6
3
  import { resolveVariantPathsWithFs } from "./resolveModulePathWithFs.js";
@@ -12,7 +9,7 @@ import { getFileNameFromUrl } from "../loaderUtils/index.js";
12
9
  * It reads the demo file, parses it to find `createDemo` calls with variants, and resolves the paths for those variants.
13
10
  * It returns a Code object mapping variant names to their resolved file URLs.
14
11
  */
15
- export var loadServerCodeMeta = createLoadServerCodeMeta();
12
+ export const loadServerCodeMeta = createLoadServerCodeMeta();
16
13
 
17
14
  /**
18
15
  * Creates a loadCodeMeta function that resolves variant paths from demo files.
@@ -28,65 +25,46 @@ export var loadServerCodeMeta = createLoadServerCodeMeta();
28
25
  * @param options - Configuration options (currently unused)
29
26
  * @returns LoadCodeMeta function that takes a URL and returns Promise<Code>
30
27
  */
31
- export function createLoadServerCodeMeta() {
32
- var _options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
33
- return /*#__PURE__*/function () {
34
- var _loadCodeMeta = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(url) {
35
- var filePath, source, demoCall, code, resolvedVariantMap;
36
- return _regenerator().w(function (_context) {
37
- while (1) switch (_context.n) {
38
- case 0:
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
42
- _context.n = 1;
43
- return readFile(filePath, 'utf-8');
44
- case 1:
45
- source = _context.v;
46
- _context.n = 2;
47
- return parseCreateFactoryCall(source, url);
48
- case 2:
49
- demoCall = _context.v;
50
- if (!(!demoCall || !demoCall.variants)) {
51
- _context.n = 3;
52
- break;
53
- }
54
- return _context.a(2, {});
55
- case 3:
56
- code = {}; // Resolve all variant paths and get them as file URLs
57
- _context.n = 4;
58
- return resolveVariantPathsWithFs(demoCall.variants || {});
59
- case 4:
60
- resolvedVariantMap = _context.v;
61
- // Build Code object from the resolved variant map
62
- Array.from(resolvedVariantMap.entries()).forEach(function (_ref) {
63
- var _demoCall$namedExport;
64
- var _ref2 = _slicedToArray(_ref, 2),
65
- variantName = _ref2[0],
66
- fileUrl = _ref2[1];
67
- var namedExport = (_demoCall$namedExport = demoCall.namedExports) == null ? void 0 : _demoCall$namedExport[variantName];
68
- code[variantName] = fileUrl;
69
- if (namedExport) {
70
- var _getFileNameFromUrl = getFileNameFromUrl(fileUrl),
71
- fileName = _getFileNameFromUrl.fileName;
72
- if (!fileName) {
73
- throw new Error("Cannot determine fileName from URL \"".concat(fileUrl, "\" for variant \"").concat(variantName, "\". ") + "Please ensure the URL has a valid file extension.");
74
- }
75
- code[variantName] = {
76
- url: fileUrl,
77
- fileName: fileName,
78
- namedExport: namedExport
79
- };
80
- }
81
- // TODO: will this cause loadVariantMeta not to run? Maybe we should always run it
82
- });
83
- return _context.a(2, code);
84
- }
85
- }, _callee);
86
- }));
87
- function loadCodeMeta(_x) {
88
- return _loadCodeMeta.apply(this, arguments);
28
+ export function createLoadServerCodeMeta(_options = {}) {
29
+ return async function loadCodeMeta(url) {
30
+ // Convert file:// URL to proper file system path for reading the file
31
+ // Using fileURLToPath handles Windows drive letters correctly (e.g., file:///C:/... → C:\...)
32
+ const filePath = url.startsWith('file://') ? fileURLToPath(url) : url;
33
+
34
+ // Read the source file to find createDemo calls
35
+ const source = await readFile(filePath, 'utf-8');
36
+
37
+ // Parse the source to find createDemo call with variants
38
+ // Pass the original URL to parseCreateFactoryCall for cross-platform path handling
39
+ const demoCall = await parseCreateFactoryCall(source, url);
40
+ if (!demoCall || !demoCall.variants) {
41
+ // Return empty code object if no variants found
42
+ return {};
89
43
  }
90
- return loadCodeMeta;
91
- }();
44
+ const code = {};
45
+
46
+ // Resolve all variant paths and get them as file URLs
47
+ const resolvedVariantMap = await resolveVariantPathsWithFs(demoCall.variants || {});
48
+
49
+ // Build Code object from the resolved variant map
50
+ Array.from(resolvedVariantMap.entries()).forEach(([variantName, fileUrl]) => {
51
+ const namedExport = demoCall.namedExports?.[variantName];
52
+ code[variantName] = fileUrl;
53
+ if (namedExport) {
54
+ const {
55
+ fileName
56
+ } = getFileNameFromUrl(fileUrl);
57
+ if (!fileName) {
58
+ throw new Error(`Cannot determine fileName from URL "${fileUrl}" for variant "${variantName}". ` + `Please ensure the URL has a valid file extension.`);
59
+ }
60
+ code[variantName] = {
61
+ url: fileUrl,
62
+ fileName,
63
+ namedExport
64
+ };
65
+ }
66
+ // TODO: will this cause loadVariantMeta not to run? Maybe we should always run it
67
+ });
68
+ return code;
69
+ };
92
70
  }
@@ -1,5 +1,3 @@
1
- import _regenerator from "@babel/runtime/helpers/esm/regenerator";
2
- import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
1
  // webpack does not like node: imports
4
2
  // eslint-disable-next-line n/prefer-node-protocol
5
3
  import { readdir } from 'fs/promises';
@@ -13,34 +11,18 @@ import { resolveModulePath, resolveModulePaths, resolveImportResult, resolveVari
13
11
  *
14
12
  * The input is a file:// URL. We convert it to a filesystem path using fileURLToPath.
15
13
  */
16
- var nodeDirectoryReader = /*#__PURE__*/function () {
17
- var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(fileUrl) {
18
- var fsPath, entries;
19
- return _regenerator().w(function (_context) {
20
- while (1) switch (_context.n) {
21
- case 0:
22
- // Convert file:// URL to filesystem path for Node.js fs APIs
23
- fsPath = fileURLToPath(fileUrl);
24
- _context.n = 1;
25
- return readdir(fsPath, {
26
- withFileTypes: true
27
- });
28
- case 1:
29
- entries = _context.v;
30
- return _context.a(2, entries.map(function (entry) {
31
- return {
32
- name: entry.name,
33
- isFile: entry.isFile(),
34
- isDirectory: entry.isDirectory()
35
- };
36
- }));
37
- }
38
- }, _callee);
14
+ const nodeDirectoryReader = async fileUrl => {
15
+ // Convert file:// URL to filesystem path for Node.js fs APIs
16
+ const fsPath = fileURLToPath(fileUrl);
17
+ const entries = await readdir(fsPath, {
18
+ withFileTypes: true
19
+ });
20
+ return entries.map(entry => ({
21
+ name: entry.name,
22
+ isFile: entry.isFile(),
23
+ isDirectory: entry.isDirectory()
39
24
  }));
40
- return function nodeDirectoryReader(_x) {
41
- return _ref.apply(this, arguments);
42
- };
43
- }();
25
+ };
44
26
 
45
27
  /**
46
28
  * Resolves a module path using Node.js filesystem APIs.
@@ -52,8 +34,8 @@ var nodeDirectoryReader = /*#__PURE__*/function () {
52
34
  * @returns Promise<string | TypeAwareResolveResult> - The resolved file path(s), or throws if not found
53
35
  */
54
36
 
55
- export function resolveModulePathWithFs(_x2) {
56
- return _resolveModulePathWithFs.apply(this, arguments);
37
+ export async function resolveModulePathWithFs(moduleUrl, options = {}, includeTypeDefs) {
38
+ return resolveModulePath(moduleUrl, nodeDirectoryReader, options, includeTypeDefs);
57
39
  }
58
40
 
59
41
  /**
@@ -64,24 +46,8 @@ export function resolveModulePathWithFs(_x2) {
64
46
  * @param options - Configuration options
65
47
  * @returns Promise<Map<string, string>> - Map from input path to resolved file path
66
48
  */
67
- function _resolveModulePathWithFs() {
68
- _resolveModulePathWithFs = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(moduleUrl) {
69
- var options,
70
- includeTypeDefs,
71
- _args2 = arguments;
72
- return _regenerator().w(function (_context2) {
73
- while (1) switch (_context2.n) {
74
- case 0:
75
- options = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : {};
76
- includeTypeDefs = _args2.length > 2 ? _args2[2] : undefined;
77
- return _context2.a(2, resolveModulePath(moduleUrl, nodeDirectoryReader, options, includeTypeDefs));
78
- }
79
- }, _callee2);
80
- }));
81
- return _resolveModulePathWithFs.apply(this, arguments);
82
- }
83
- export function resolveModulePathsWithFs(_x3) {
84
- return _resolveModulePathsWithFs.apply(this, arguments);
49
+ export async function resolveModulePathsWithFs(moduleUrls, options = {}) {
50
+ return resolveModulePaths(moduleUrls, nodeDirectoryReader, options);
85
51
  }
86
52
 
87
53
  /**
@@ -94,22 +60,8 @@ export function resolveModulePathsWithFs(_x3) {
94
60
  * @param options - Configuration options for module resolution
95
61
  * @returns Promise<Map<string, string>> - Map from import path to resolved file path
96
62
  */
97
- function _resolveModulePathsWithFs() {
98
- _resolveModulePathsWithFs = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(moduleUrls) {
99
- var options,
100
- _args3 = arguments;
101
- return _regenerator().w(function (_context3) {
102
- while (1) switch (_context3.n) {
103
- case 0:
104
- options = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : {};
105
- return _context3.a(2, resolveModulePaths(moduleUrls, nodeDirectoryReader, options));
106
- }
107
- }, _callee3);
108
- }));
109
- return _resolveModulePathsWithFs.apply(this, arguments);
110
- }
111
- export function resolveImportResultWithFs(_x4) {
112
- return _resolveImportResultWithFs.apply(this, arguments);
63
+ export async function resolveImportResultWithFs(importResult, options = {}) {
64
+ return resolveImportResult(importResult, nodeDirectoryReader, options);
113
65
  }
114
66
 
115
67
  /**
@@ -121,36 +73,8 @@ export function resolveImportResultWithFs(_x4) {
121
73
  * @param options - Configuration options for module resolution
122
74
  * @returns Promise<Map<string, string>> - Map from variant name to resolved file URL
123
75
  */
124
- function _resolveImportResultWithFs() {
125
- _resolveImportResultWithFs = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(importResult) {
126
- var options,
127
- _args4 = arguments;
128
- return _regenerator().w(function (_context4) {
129
- while (1) switch (_context4.n) {
130
- case 0:
131
- options = _args4.length > 1 && _args4[1] !== undefined ? _args4[1] : {};
132
- return _context4.a(2, resolveImportResult(importResult, nodeDirectoryReader, options));
133
- }
134
- }, _callee4);
135
- }));
136
- return _resolveImportResultWithFs.apply(this, arguments);
137
- }
138
- export function resolveVariantPathsWithFs(_x5) {
139
- return _resolveVariantPathsWithFs.apply(this, arguments);
76
+ export async function resolveVariantPathsWithFs(variants, options = {}) {
77
+ return resolveVariantPaths(variants, nodeDirectoryReader, options);
140
78
  }
141
79
 
142
- // Re-export types for convenience
143
- function _resolveVariantPathsWithFs() {
144
- _resolveVariantPathsWithFs = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(variants) {
145
- var options,
146
- _args5 = arguments;
147
- return _regenerator().w(function (_context5) {
148
- while (1) switch (_context5.n) {
149
- case 0:
150
- options = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : {};
151
- return _context5.a(2, resolveVariantPaths(variants, nodeDirectoryReader, options));
152
- }
153
- }, _callee5);
154
- }));
155
- return _resolveVariantPathsWithFs.apply(this, arguments);
156
- }
80
+ // Re-export types for convenience