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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. package/README.md +3 -2
  2. package/esm/CodeHighlighter/CodeHighlighter.js +16 -16
  3. package/esm/CodeHighlighter/CodeHighlighterClient.js +33 -33
  4. package/esm/CodeHighlighter/errors.js +3 -3
  5. package/esm/CodeHighlighter/types.d.ts +1 -1
  6. package/esm/CodeProvider/CodeContext.d.ts +4 -4
  7. package/esm/CodeProvider/CodeProvider.js +7 -7
  8. package/esm/cli/index.d.ts +1 -0
  9. package/esm/cli/index.js +6 -0
  10. package/esm/cli/runValidate.d.ts +8 -0
  11. package/esm/cli/runValidate.js +297 -0
  12. package/esm/createSitemap/createSitemap.d.ts +23 -0
  13. package/esm/createSitemap/createSitemap.js +45 -0
  14. package/esm/createSitemap/index.d.ts +1 -0
  15. package/esm/createSitemap/index.js +1 -0
  16. package/esm/createSitemap/types.d.ts +68 -0
  17. package/esm/createSitemap/types.js +1 -0
  18. package/esm/pipeline/getFileConventions/fileConventions.d.ts +4 -0
  19. package/esm/pipeline/getFileConventions/fileConventions.js +4 -0
  20. package/esm/pipeline/getFileConventions/getFileConventions.d.ts +4 -0
  21. package/esm/pipeline/getFileConventions/getFileConventions.js +17 -0
  22. package/esm/pipeline/getFileConventions/index.d.ts +1 -0
  23. package/esm/pipeline/getFileConventions/index.js +1 -0
  24. package/esm/{CodeHighlighter/addPathsToVariant.d.ts → pipeline/loadCodeVariant/addCodeVariantPaths.d.ts} +1 -1
  25. package/esm/{CodeHighlighter/applyTransform.d.ts → pipeline/loadCodeVariant/applyCodeTransform.d.ts} +3 -3
  26. package/esm/{CodeHighlighter/applyTransform.js → pipeline/loadCodeVariant/applyCodeTransform.js} +4 -4
  27. package/esm/{CodeHighlighter → pipeline/loadCodeVariant}/calculateMainFilePath.js +1 -1
  28. package/esm/{CodeHighlighter/transformCode.d.ts → pipeline/loadCodeVariant/computeHastDeltas.d.ts} +9 -5
  29. package/esm/{CodeHighlighter/transformCode.js → pipeline/loadCodeVariant/computeHastDeltas.js} +20 -16
  30. package/esm/pipeline/loadCodeVariant/diffHast.d.ts +3 -0
  31. package/esm/{CodeHighlighter/transformParsedSource.js → pipeline/loadCodeVariant/diffHast.js} +5 -5
  32. package/esm/{CodeHighlighter/examineVariant.d.ts → pipeline/loadCodeVariant/examineCodeVariant.d.ts} +2 -2
  33. package/esm/{CodeHighlighter/examineVariant.js → pipeline/loadCodeVariant/examineCodeVariant.js} +1 -1
  34. package/esm/{useDemo/flattenVariant.d.ts → pipeline/loadCodeVariant/flattenCodeVariant.d.ts} +2 -2
  35. package/esm/{useDemo/flattenVariant.js → pipeline/loadCodeVariant/flattenCodeVariant.js} +3 -3
  36. package/esm/{CodeHighlighter/hasAllVariants.d.ts → pipeline/loadCodeVariant/hasAllCodeVariants.d.ts} +1 -1
  37. package/esm/pipeline/loadCodeVariant/index.d.ts +10 -0
  38. package/esm/pipeline/loadCodeVariant/index.js +17 -0
  39. package/esm/{CodeHighlighter/loadFallbackCode.d.ts → pipeline/loadCodeVariant/loadCodeFallback.d.ts} +2 -2
  40. package/esm/{CodeHighlighter/loadFallbackCode.js → pipeline/loadCodeVariant/loadCodeFallback.js} +180 -106
  41. package/esm/{CodeHighlighter/loadVariant.d.ts → pipeline/loadCodeVariant/loadCodeVariant.d.ts} +2 -2
  42. package/esm/{CodeHighlighter/loadVariant.js → pipeline/loadCodeVariant/loadCodeVariant.js} +122 -49
  43. package/esm/{CodeHighlighter/maybeInitialData.d.ts → pipeline/loadCodeVariant/maybeCodeInitialData.d.ts} +6 -6
  44. package/esm/{CodeHighlighter/maybeInitialData.js → pipeline/loadCodeVariant/maybeCodeInitialData.js} +6 -6
  45. package/esm/{CodeHighlighter/mergeMetadata.d.ts → pipeline/loadCodeVariant/mergeCodeMetadata.d.ts} +3 -3
  46. package/esm/{CodeHighlighter/mergeMetadata.js → pipeline/loadCodeVariant/mergeCodeMetadata.js} +3 -3
  47. package/esm/{CodeHighlighter → pipeline/loadCodeVariant}/parseCode.d.ts +1 -1
  48. package/esm/{CodeHighlighter → pipeline/loadCodeVariant}/transformSource.d.ts +1 -1
  49. package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.d.ts +5 -0
  50. package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.js +86 -13
  51. package/esm/pipeline/loadPrecomputedCodeHighlighter/performanceLogger.d.ts +30 -0
  52. package/esm/pipeline/loadPrecomputedCodeHighlighter/performanceLogger.js +77 -0
  53. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/loadPrecomputedCodeHighlighterClient.js +7 -7
  54. package/esm/pipeline/loadPrecomputedSitemap/index.d.ts +2 -0
  55. package/esm/pipeline/loadPrecomputedSitemap/index.js +4 -0
  56. package/esm/pipeline/loadPrecomputedSitemap/loadPrecomputedSitemap.d.ts +10 -0
  57. package/esm/pipeline/loadPrecomputedSitemap/loadPrecomputedSitemap.js +213 -0
  58. package/esm/pipeline/loadServerCodeMeta/index.d.ts +2 -1
  59. package/esm/pipeline/loadServerCodeMeta/index.js +2 -1
  60. package/esm/pipeline/loadServerCodeMeta/loadServerCodeMeta.d.ts +1 -1
  61. package/esm/pipeline/loadServerCodeMeta/loadServerCodeMeta.js +2 -2
  62. package/esm/pipeline/{loaderUtils → loadServerCodeMeta}/resolveModulePathWithFs.d.ts +1 -1
  63. package/esm/pipeline/{loaderUtils → loadServerCodeMeta}/resolveModulePathWithFs.js +1 -1
  64. package/esm/pipeline/loadServerPageIndex/index.d.ts +2 -0
  65. package/esm/pipeline/loadServerPageIndex/index.js +1 -0
  66. package/esm/pipeline/loadServerPageIndex/loadServerPageIndex.d.ts +51 -0
  67. package/esm/pipeline/loadServerPageIndex/loadServerPageIndex.js +174 -0
  68. package/esm/pipeline/loadServerSitemap/index.d.ts +2 -0
  69. package/esm/pipeline/loadServerSitemap/index.js +1 -0
  70. package/esm/pipeline/loadServerSitemap/loadServerSitemap.d.ts +39 -0
  71. package/esm/pipeline/loadServerSitemap/loadServerSitemap.js +168 -0
  72. package/esm/pipeline/loadServerSource/loadServerSource.js +1 -1
  73. package/esm/pipeline/loaderUtils/externalsToPackages.js +1 -1
  74. package/esm/pipeline/loaderUtils/processRelativeImports.js +16 -3
  75. package/esm/pipeline/loaderUtils/rewriteImports.d.ts +36 -0
  76. package/esm/pipeline/loaderUtils/rewriteImports.js +139 -8
  77. package/esm/pipeline/syncPageIndex/createMarkdownNodes.d.ts +76 -0
  78. package/esm/pipeline/syncPageIndex/createMarkdownNodes.js +305 -0
  79. package/esm/pipeline/syncPageIndex/index.d.ts +1 -0
  80. package/esm/pipeline/syncPageIndex/index.js +1 -0
  81. package/esm/pipeline/syncPageIndex/mergeMetadataMarkdown.d.ts +58 -0
  82. package/esm/pipeline/syncPageIndex/mergeMetadataMarkdown.js +214 -0
  83. package/esm/pipeline/syncPageIndex/metadataToMarkdown.d.ts +67 -0
  84. package/esm/pipeline/syncPageIndex/metadataToMarkdown.js +1486 -0
  85. package/esm/pipeline/syncPageIndex/syncPageIndex.d.ts +108 -0
  86. package/esm/pipeline/syncPageIndex/syncPageIndex.js +540 -0
  87. package/esm/pipeline/transformHtmlCodePrecomputed/transformHtmlCodePrecomputed.d.ts +2 -2
  88. package/esm/pipeline/transformHtmlCodePrecomputed/transformHtmlCodePrecomputed.js +5 -5
  89. package/esm/pipeline/transformMarkdownBlockquoteCallouts/index.d.ts +2 -0
  90. package/esm/pipeline/transformMarkdownBlockquoteCallouts/index.js +4 -0
  91. package/esm/pipeline/transformMarkdownBlockquoteCallouts/transformMarkdownBlockquoteCallouts.d.ts +16 -0
  92. package/esm/pipeline/transformMarkdownBlockquoteCallouts/transformMarkdownBlockquoteCallouts.js +58 -0
  93. package/esm/pipeline/transformMarkdownDemoLinks/index.d.ts +2 -0
  94. package/esm/pipeline/transformMarkdownDemoLinks/index.js +4 -0
  95. package/esm/pipeline/transformMarkdownDemoLinks/transformMarkdownDemoLinks.d.ts +26 -0
  96. package/esm/pipeline/transformMarkdownDemoLinks/transformMarkdownDemoLinks.js +107 -0
  97. package/esm/pipeline/transformMarkdownMetadata/index.d.ts +2 -0
  98. package/esm/pipeline/transformMarkdownMetadata/index.js +4 -0
  99. package/esm/pipeline/transformMarkdownMetadata/transformMarkdownMetadata.d.ts +3 -0
  100. package/esm/pipeline/transformMarkdownMetadata/transformMarkdownMetadata.js +1010 -0
  101. package/esm/pipeline/transformMarkdownMetadata/types.d.ts +110 -0
  102. package/esm/pipeline/transformMarkdownMetadata/types.js +1 -0
  103. package/esm/pipeline/transformMarkdownRelativePaths/index.d.ts +2 -0
  104. package/esm/pipeline/transformMarkdownRelativePaths/index.js +4 -0
  105. package/esm/pipeline/transformMarkdownRelativePaths/transformMarkdownRelativePaths.d.ts +15 -0
  106. package/esm/pipeline/transformMarkdownRelativePaths/transformMarkdownRelativePaths.js +40 -0
  107. package/esm/useCode/Pre.js +15 -2
  108. package/esm/useCode/useCode.d.ts +15 -2
  109. package/esm/useCode/useCode.js +15 -6
  110. package/esm/useCode/useCodeUtils.js +3 -3
  111. package/esm/useCode/useFileNavigation.d.ts +9 -3
  112. package/esm/useCode/useFileNavigation.js +124 -81
  113. package/esm/useCode/useUIState.d.ts +4 -1
  114. package/esm/useCode/useUIState.js +17 -2
  115. package/esm/useCode/useVariantSelection.d.ts +8 -3
  116. package/esm/useCode/useVariantSelection.js +144 -52
  117. package/esm/useCopier/index.js +5 -4
  118. package/esm/useDemo/createCodeSandbox.d.ts +1 -1
  119. package/esm/useDemo/createStackBlitz.d.ts +1 -1
  120. package/esm/useDemo/exportVariant.js +13 -11
  121. package/esm/useDemo/index.d.ts +1 -1
  122. package/esm/useDemo/index.js +1 -1
  123. package/esm/useDemo/useDemo.d.ts +5 -5
  124. package/esm/useDemo/useDemo.js +6 -6
  125. package/esm/useErrors/useErrors.d.ts +1 -1
  126. package/esm/useErrors/useErrors.js +6 -2
  127. package/esm/useSearch/index.d.ts +1 -0
  128. package/esm/useSearch/index.js +1 -0
  129. package/esm/useSearch/types.d.ts +165 -0
  130. package/esm/useSearch/types.js +1 -0
  131. package/esm/useSearch/useSearch.d.ts +56 -0
  132. package/esm/useSearch/useSearch.js +647 -0
  133. package/esm/withDocsInfra/withDeploymentConfig.js +4 -2
  134. package/esm/withDocsInfra/withDocsInfra.d.ts +39 -0
  135. package/esm/withDocsInfra/withDocsInfra.js +79 -7
  136. package/package.json +106 -6
  137. package/esm/CodeHighlighter/transformParsedSource.d.ts +0 -3
  138. /package/esm/{CodeHighlighter/addPathsToVariant.js → pipeline/loadCodeVariant/addCodeVariantPaths.js} +0 -0
  139. /package/esm/{CodeHighlighter → pipeline/loadCodeVariant}/calculateMainFilePath.d.ts +0 -0
  140. /package/esm/{CodeHighlighter/hasAllVariants.js → pipeline/loadCodeVariant/hasAllCodeVariants.js} +0 -0
  141. /package/esm/{CodeHighlighter → pipeline/loadCodeVariant}/parseCode.js +0 -0
  142. /package/esm/{CodeHighlighter → pipeline/loadCodeVariant}/pathUtils.d.ts +0 -0
  143. /package/esm/{CodeHighlighter → pipeline/loadCodeVariant}/pathUtils.js +0 -0
  144. /package/esm/{CodeHighlighter → pipeline/loadCodeVariant}/transformSource.js +0 -0
@@ -2,16 +2,22 @@ import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIt
2
2
  import _regenerator from "@babel/runtime/helpers/esm/regenerator";
3
3
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
4
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
5
- import { loadVariant } from "../../CodeHighlighter/loadVariant.js";
5
+ // webpack does not like node: imports
6
+ // eslint-disable-next-line n/prefer-node-protocol
7
+ import path from 'path';
8
+ import { loadCodeVariant } from "../loadCodeVariant/loadCodeVariant.js";
6
9
  import { createParseSource } from "../parseSource/index.js";
7
10
  // TODO: re-enable following benchmarking
8
11
  // import { TypescriptToJavascriptTransformer } from '../transformTypescriptToJavascript';
9
12
 
10
13
  import { parseCreateFactoryCall } from "./parseCreateFactoryCall.js";
11
- import { resolveVariantPathsWithFs } from "../loaderUtils/resolveModulePathWithFs.js";
14
+ import { resolveVariantPathsWithFs } from "../loadServerCodeMeta/resolveModulePathWithFs.js";
12
15
  import { replacePrecomputeValue } from "./replacePrecomputeValue.js";
13
16
  import { createLoadServerSource } from "../loadServerSource/index.js";
14
17
  import { getFileNameFromUrl } from "../loaderUtils/index.js";
18
+ import { createPerformanceLogger, logPerformance, performanceMeasure } from "./performanceLogger.js";
19
+ var functionName = 'Load Precomputed Code Highlighter';
20
+
15
21
  /**
16
22
  * Webpack loader that processes demo files and precomputes variant data.
17
23
  *
@@ -28,18 +34,44 @@ export function loadPrecomputedCodeHighlighter(_x) {
28
34
  }
29
35
  function _loadPrecomputedCodeHighlighter() {
30
36
  _loadPrecomputedCodeHighlighter = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(source) {
31
- var _this = this;
32
- var callback, demoCall, variantData, allDependencies, resolvedVariantMap, loadSource, sourceTransformers, sourceParser, variantPromises, variantResults, _iterator, _step, result, modifiedSource, _t2;
37
+ var _options$performance$,
38
+ _options$performance,
39
+ _options$performance$2,
40
+ _options$performance2,
41
+ _options$performance3,
42
+ _this = this;
43
+ var callback, options, performanceNotableMs, performanceShowWrapperMeasures, relativePath, observer, currentMark, _observer, _observer2, demoCall, variantData, allDependencies, resolvedVariantMap, loadSource, sourceTransformers, sourceParser, functionsInitMark, variantPromises, variantResults, _iterator, _step, result, modifiedSource, _observer3, _observer4, _t2;
33
44
  return _regenerator().w(function (_context2) {
34
45
  while (1) switch (_context2.p = _context2.n) {
35
46
  case 0:
36
47
  callback = this.async();
37
48
  this.cacheable();
49
+ options = this.getOptions();
50
+ performanceNotableMs = (_options$performance$ = (_options$performance = options.performance) == null ? void 0 : _options$performance.notableMs) != null ? _options$performance$ : 100;
51
+ performanceShowWrapperMeasures = (_options$performance$2 = (_options$performance2 = options.performance) == null ? void 0 : _options$performance2.showWrapperMeasures) != null ? _options$performance$2 : false;
52
+ relativePath = path.relative(this.rootContext || process.cwd(), this.resourcePath);
53
+ observer = undefined;
54
+ if ((_options$performance3 = options.performance) != null && _options$performance3.logging) {
55
+ observer = new PerformanceObserver(createPerformanceLogger(performanceNotableMs, performanceShowWrapperMeasures, relativePath));
56
+ observer.observe({
57
+ entryTypes: ['measure']
58
+ });
59
+ }
60
+ currentMark = performanceMeasure(undefined, {
61
+ mark: 'Start',
62
+ measure: 'Start'
63
+ }, [functionName, relativePath], true);
38
64
  _context2.p = 1;
39
65
  _context2.n = 2;
40
66
  return parseCreateFactoryCall(source, this.resourcePath);
41
67
  case 2:
42
68
  demoCall = _context2.v;
69
+ currentMark = performanceMeasure(currentMark, {
70
+ mark: 'Parsed Factory',
71
+ measure: 'Factory Parsing'
72
+ }, [functionName, relativePath]);
73
+
74
+ // If no createDemo call found, return the source unchanged
43
75
  if (demoCall) {
44
76
  _context2.n = 3;
45
77
  break;
@@ -61,6 +93,11 @@ function _loadPrecomputedCodeHighlighter() {
61
93
  return resolveVariantPathsWithFs(demoCall.variants || {});
62
94
  case 5:
63
95
  resolvedVariantMap = _context2.v;
96
+ currentMark = performanceMeasure(currentMark, {
97
+ mark: 'Paths Resolved',
98
+ measure: 'Path Resolution'
99
+ }, [functionName, relativePath]);
100
+
64
101
  // Create loader functions
65
102
  loadSource = createLoadServerSource({
66
103
  includeDependencies: true,
@@ -69,15 +106,26 @@ function _loadPrecomputedCodeHighlighter() {
69
106
  // const sourceTransformers: SourceTransformers = [TypescriptToJavascriptTransformer];
70
107
  // TODO: maybe we should have `loadPrecomputedCodeHighlighterWithJsToTs`
71
108
  sourceTransformers = []; // Create sourceParser promise for syntax highlighting
72
- sourceParser = createParseSource(); // Process variants in parallel
109
+ sourceParser = createParseSource();
110
+ functionsInitMark = performanceMeasure(currentMark, {
111
+ mark: 'Functions Init',
112
+ measure: 'Functions Init'
113
+ }, [functionName, relativePath]);
114
+ currentMark = functionsInitMark;
115
+
116
+ // Process variants in parallel
73
117
  variantPromises = Array.from(resolvedVariantMap.entries()).map(/*#__PURE__*/function () {
74
118
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref) {
75
119
  var _demoCall$namedExport;
76
- var _ref3, variantName, fileUrl, namedExport, variant, _getFileNameFromUrl, fileName, _yield$loadVariant, processedVariant, dependencies, _t;
120
+ var _ref3, variantName, fileUrl, variantMark, namedExport, variant, _getFileNameFromUrl, fileName, _yield$loadCodeVarian, processedVariant, dependencies, _t;
77
121
  return _regenerator().w(function (_context) {
78
122
  while (1) switch (_context.p = _context.n) {
79
123
  case 0:
80
124
  _ref3 = _slicedToArray(_ref, 2), variantName = _ref3[0], fileUrl = _ref3[1];
125
+ variantMark = performanceMeasure(functionsInitMark, {
126
+ mark: 'Variant Started',
127
+ measure: 'Variant Start'
128
+ }, [functionName, variantName, relativePath], true);
81
129
  namedExport = (_demoCall$namedExport = demoCall.namedExports) == null ? void 0 : _demoCall$namedExport[variantName];
82
130
  variant = fileUrl;
83
131
  if (!namedExport) {
@@ -99,7 +147,7 @@ function _loadPrecomputedCodeHighlighter() {
99
147
  case 2:
100
148
  _context.p = 2;
101
149
  _context.n = 3;
102
- return loadVariant(fileUrl,
150
+ return loadCodeVariant(fileUrl,
103
151
  // URL for the variant entry point (already includes file://)
104
152
  variantName, variant, {
105
153
  sourceParser: sourceParser,
@@ -113,9 +161,13 @@ function _loadPrecomputedCodeHighlighter() {
113
161
  output: _this.getOptions().output || 'hastGzip'
114
162
  });
115
163
  case 3:
116
- _yield$loadVariant = _context.v;
117
- processedVariant = _yield$loadVariant.code;
118
- dependencies = _yield$loadVariant.dependencies;
164
+ _yield$loadCodeVarian = _context.v;
165
+ processedVariant = _yield$loadCodeVarian.code;
166
+ dependencies = _yield$loadCodeVarian.dependencies;
167
+ performanceMeasure(variantMark, {
168
+ mark: 'Variant Loaded',
169
+ measure: 'Variant Loading'
170
+ }, [functionName, variantName, relativePath], true);
119
171
  return _context.a(2, {
120
172
  variantName: variantName,
121
173
  variantData: processedVariant,
@@ -151,24 +203,45 @@ function _loadPrecomputedCodeHighlighter() {
151
203
  });
152
204
  }
153
205
  }
154
-
155
- // Replace the factory function call with the actual precomputed data
156
206
  } catch (err) {
157
207
  _iterator.e(err);
158
208
  } finally {
159
209
  _iterator.f();
160
210
  }
161
- modifiedSource = replacePrecomputeValue(source, variantData, demoCall); // Add all dependencies to webpack's watch list
211
+ currentMark = performanceMeasure(functionsInitMark, {
212
+ mark: 'All Variants Loaded',
213
+ measure: 'Complete Variants Loading'
214
+ }, [functionName, relativePath], true);
215
+
216
+ // Replace the factory function call with the actual precomputed data
217
+ modifiedSource = replacePrecomputeValue(source, variantData, demoCall);
218
+ currentMark = performanceMeasure(currentMark, {
219
+ mark: 'Replaced Precompute',
220
+ measure: 'Precompute Replacement'
221
+ }, [functionName, relativePath]);
222
+
223
+ // Add all dependencies to webpack's watch list
162
224
  allDependencies.forEach(function (dep) {
163
225
  // Strip 'file://' prefix if present before adding to webpack's dependency tracking
164
226
  _this.addDependency(dep.startsWith('file://') ? dep.slice(7) : dep);
165
227
  });
228
+
229
+ // log any pending performance entries before completing
230
+ (_observer = observer) == null || (_observer = _observer.takeRecords()) == null || _observer.forEach(function (entry) {
231
+ return logPerformance(entry, performanceNotableMs, performanceShowWrapperMeasures, relativePath);
232
+ });
233
+ (_observer2 = observer) == null || _observer2.disconnect();
166
234
  callback(null, modifiedSource);
167
235
  _context2.n = 8;
168
236
  break;
169
237
  case 7:
170
238
  _context2.p = 7;
171
239
  _t2 = _context2.v;
240
+ // log any pending performance entries before completing
241
+ (_observer3 = observer) == null || (_observer3 = _observer3.takeRecords()) == null || _observer3.forEach(function (entry) {
242
+ return logPerformance(entry, performanceNotableMs, performanceShowWrapperMeasures, relativePath);
243
+ });
244
+ (_observer4 = observer) == null || _observer4.disconnect();
172
245
  callback(_t2 instanceof Error ? _t2 : new Error(String(_t2)));
173
246
  case 8:
174
247
  return _context2.a(2);
@@ -0,0 +1,30 @@
1
+ export declare function logPerformance(entry: PerformanceEntry, notableMs: number, showWrapperMeasures: boolean, filterContext?: string): void;
2
+ export declare function createPerformanceLogger(notableMs: number, showWrapperMeasures: boolean, filterContext?: string): PerformanceObserverCallback;
3
+ export declare function nameMark(functionName: string, event: string, context: string[], wrapper?: boolean): string;
4
+ /**
5
+ * Helper to create a performance mark and measure in one call.
6
+ *
7
+ * @param startMark - Optional start mark name for the measure (typically currentMark)
8
+ * @param names - Object with mark and measure names
9
+ * @param context - Array of context strings [functionName, ...context]
10
+ * @param wrapper - Whether this is a wrapper measure (uses pipe delimiter)
11
+ * @returns The mark name that was created
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * currentMark = performanceMeasure(
16
+ * currentMark,
17
+ * { mark: 'processed', measure: 'processing' },
18
+ * [functionName, relativePath],
19
+ * true,
20
+ * );
21
+ * ```
22
+ */
23
+ export declare function performanceMeasure(startMark: string | undefined, names: {
24
+ mark: string;
25
+ measure: string;
26
+ } | {
27
+ prefix?: string;
28
+ mark: string;
29
+ measure: string;
30
+ }, context: string[], wrapper?: boolean): string;
@@ -0,0 +1,77 @@
1
+ import _arrayLikeToArray from "@babel/runtime/helpers/esm/arrayLikeToArray";
2
+ import _toArray from "@babel/runtime/helpers/esm/toArray";
3
+ import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
4
+ export function logPerformance(entry, notableMs, showWrapperMeasures, filterContext) {
5
+ if (entry.duration < notableMs) {
6
+ return;
7
+ }
8
+
9
+ // If filterContext is provided, only log entries that include it
10
+ if (filterContext && !entry.name.includes(filterContext)) {
11
+ return;
12
+ }
13
+ var delim = '-';
14
+ var message = entry.name;
15
+ if (message.startsWith('| ')) {
16
+ if (!showWrapperMeasures) {
17
+ return;
18
+ }
19
+ delim = '|';
20
+ message = message.slice(2);
21
+ }
22
+ var duration = Math.round(entry.duration).toString().padStart(4, ' ');
23
+ console.warn("".concat(duration, "ms ").concat(delim, " ").concat(message));
24
+ }
25
+ export function createPerformanceLogger(notableMs, showWrapperMeasures, filterContext) {
26
+ var performanceLogger = function performanceLogger(list) {
27
+ var _iterator = _createForOfIteratorHelper(list.getEntries()),
28
+ _step;
29
+ try {
30
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
31
+ var entry = _step.value;
32
+ logPerformance(entry, notableMs, showWrapperMeasures, filterContext);
33
+ }
34
+ } catch (err) {
35
+ _iterator.e(err);
36
+ } finally {
37
+ _iterator.f();
38
+ }
39
+ };
40
+ return performanceLogger;
41
+ }
42
+ export function nameMark(functionName, event, context) {
43
+ var wrapper = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
44
+ return "".concat(wrapper ? '| ' : '').concat(functionName, " ").concat(wrapper ? '|' : '-', " ").concat(event, " - ").concat(context.join(' - '));
45
+ }
46
+
47
+ /**
48
+ * Helper to create a performance mark and measure in one call.
49
+ *
50
+ * @param startMark - Optional start mark name for the measure (typically currentMark)
51
+ * @param names - Object with mark and measure names
52
+ * @param context - Array of context strings [functionName, ...context]
53
+ * @param wrapper - Whether this is a wrapper measure (uses pipe delimiter)
54
+ * @returns The mark name that was created
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * currentMark = performanceMeasure(
59
+ * currentMark,
60
+ * { mark: 'processed', measure: 'processing' },
61
+ * [functionName, relativePath],
62
+ * true,
63
+ * );
64
+ * ```
65
+ */
66
+ export function performanceMeasure(startMark, names, context) {
67
+ var wrapper = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
68
+ var _context = _toArray(context),
69
+ functionName = _context[0],
70
+ restContext = _arrayLikeToArray(_context).slice(1);
71
+ var prefix = 'prefix' in names && names.prefix ? "".concat(names.prefix, " ") : '';
72
+ var markName = nameMark(functionName, "".concat(prefix).concat(names.mark), restContext, wrapper);
73
+ var measureName = nameMark(functionName, "".concat(prefix).concat(names.measure), restContext, wrapper);
74
+ performance.mark(markName);
75
+ performance.measure(measureName, startMark, markName);
76
+ return markName;
77
+ }
@@ -7,9 +7,9 @@ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
7
7
  import { readFile } from 'fs/promises';
8
8
  import { parseCreateFactoryCall } from "../loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js";
9
9
  import { generateResolvedExternals } from "./generateResolvedExternals.js";
10
- import { loadVariant } from "../../CodeHighlighter/loadVariant.js";
10
+ import { loadCodeVariant } from "../loadCodeVariant/loadCodeVariant.js";
11
11
  import { createLoadServerSource } from "../loadServerSource/index.js";
12
- import { resolveVariantPathsWithFs } from "../loaderUtils/resolveModulePathWithFs.js";
12
+ import { resolveVariantPathsWithFs } from "../loadServerCodeMeta/resolveModulePathWithFs.js";
13
13
  import { getFileNameFromUrl } from "../loaderUtils/index.js";
14
14
  import { mergeExternals } from "../loaderUtils/mergeExternals.js";
15
15
  import { filterRuntimeExternals } from "./filterRuntimeExternals.js";
@@ -116,7 +116,7 @@ function _loadPrecomputedCodeHighlighterClient() {
116
116
  variantPromises = Array.from(resolvedVariantMap.entries()).map(/*#__PURE__*/function () {
117
117
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref) {
118
118
  var _indexDemoCall$namedE;
119
- var _ref3, variantName, fileUrl, namedExport, variant, _getFileNameFromUrl, fileName, _yield$loadVariant, dependencies, externals, _t;
119
+ var _ref3, variantName, fileUrl, namedExport, variant, _getFileNameFromUrl, fileName, _yield$loadCodeVarian, dependencies, externals, _t;
120
120
  return _regenerator().w(function (_context) {
121
121
  while (1) switch (_context.p = _context.n) {
122
122
  case 0:
@@ -142,7 +142,7 @@ function _loadPrecomputedCodeHighlighterClient() {
142
142
  case 2:
143
143
  _context.p = 2;
144
144
  _context.n = 3;
145
- return loadVariant(fileUrl,
145
+ return loadCodeVariant(fileUrl,
146
146
  // URL for the variant entry point (already includes file://)
147
147
  variantName, variant, {
148
148
  loadSource: loadSource,
@@ -152,9 +152,9 @@ function _loadPrecomputedCodeHighlighterClient() {
152
152
  disableTransforms: true
153
153
  });
154
154
  case 3:
155
- _yield$loadVariant = _context.v;
156
- dependencies = _yield$loadVariant.dependencies;
157
- externals = _yield$loadVariant.externals;
155
+ _yield$loadCodeVarian = _context.v;
156
+ dependencies = _yield$loadCodeVarian.dependencies;
157
+ externals = _yield$loadCodeVarian.externals;
158
158
  return _context.a(2, {
159
159
  variantName: variantName,
160
160
  dependencies: dependencies,
@@ -0,0 +1,2 @@
1
+ import { loadPrecomputedSitemap } from "./loadPrecomputedSitemap.js";
2
+ export default loadPrecomputedSitemap;
@@ -0,0 +1,4 @@
1
+ // This is export format a Webpack / Turbopack loader expects
2
+
3
+ import { loadPrecomputedSitemap } from "./loadPrecomputedSitemap.js";
4
+ export default loadPrecomputedSitemap;
@@ -0,0 +1,10 @@
1
+ import type { LoaderContext } from 'webpack';
2
+ export type LoaderOptions = {
3
+ performance?: {
4
+ logging?: boolean;
5
+ notableMs?: number;
6
+ showWrapperMeasures?: boolean;
7
+ significantDependencyCountThreshold?: number;
8
+ };
9
+ };
10
+ export declare function loadPrecomputedSitemap(this: LoaderContext<LoaderOptions>, source: string): Promise<void>;
@@ -0,0 +1,213 @@
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
+ import { createPerformanceLogger, logPerformance, nameMark, performanceMeasure } from "../loadPrecomputedCodeHighlighter/performanceLogger.js";
9
+ import { parseCreateFactoryCall } from "../loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js";
10
+ import { replacePrecomputeValue } from "../loadPrecomputedCodeHighlighter/replacePrecomputeValue.js";
11
+ import { rewriteImportsToNull } from "../loaderUtils/rewriteImports.js";
12
+ import { createLoadServerPageIndex } from "../loadServerPageIndex/loadServerPageIndex.js";
13
+ import { createSitemapSchema } from "../loadServerSitemap/loadServerSitemap.js";
14
+ var functionName = 'Load Precomputed Sitemap';
15
+ export function loadPrecomputedSitemap(_x) {
16
+ return _loadPrecomputedSitemap.apply(this, arguments);
17
+ }
18
+ function _loadPrecomputedSitemap() {
19
+ _loadPrecomputedSitemap = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(source) {
20
+ var _options$performance$, _options$performance, _options$performance$2, _options$performance2, _options$performance3;
21
+ var callback, options, performanceNotableMs, performanceShowWrapperMeasures, relativePath, observer, currentMark, _observer, _observer2, 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;
22
+ return _regenerator().w(function (_context2) {
23
+ while (1) switch (_context2.p = _context2.n) {
24
+ case 0:
25
+ callback = this.async();
26
+ this.cacheable();
27
+ options = this.getOptions();
28
+ performanceNotableMs = (_options$performance$ = (_options$performance = options.performance) == null ? void 0 : _options$performance.notableMs) != null ? _options$performance$ : 100;
29
+ performanceShowWrapperMeasures = (_options$performance$2 = (_options$performance2 = options.performance) == null ? void 0 : _options$performance2.showWrapperMeasures) != null ? _options$performance$2 : false; // const resourceName = extractNameAndSlugFromUrl(
30
+ // new URL('.', `file://${this.resourcePath}`).pathname,
31
+ // ).name;
32
+ relativePath = path.relative(this.rootContext || process.cwd(), this.resourcePath);
33
+ observer = undefined;
34
+ if ((_options$performance3 = options.performance) != null && _options$performance3.logging) {
35
+ observer = new PerformanceObserver(createPerformanceLogger(performanceNotableMs, performanceShowWrapperMeasures, relativePath));
36
+ observer.observe({
37
+ entryTypes: ['measure']
38
+ });
39
+ }
40
+ currentMark = nameMark(functionName, 'Start Loading', [relativePath]);
41
+ performance.mark(currentMark);
42
+ _context2.p = 1;
43
+ _context2.n = 2;
44
+ return parseCreateFactoryCall(source, this.resourcePath);
45
+ case 2:
46
+ sitemapCall = _context2.v;
47
+ currentMark = performanceMeasure(currentMark, {
48
+ mark: 'Parsed Factory',
49
+ measure: 'Factory Parsing'
50
+ }, [functionName, relativePath]);
51
+
52
+ // If no createSitemap call found, return the source unchanged
53
+ if (sitemapCall) {
54
+ _context2.n = 3;
55
+ break;
56
+ }
57
+ callback(null, source);
58
+ return _context2.a(2);
59
+ case 3:
60
+ if (!sitemapCall.options.skipPrecompute) {
61
+ _context2.n = 4;
62
+ break;
63
+ }
64
+ callback(null, source);
65
+ return _context2.a(2);
66
+ case 4:
67
+ // Extract the variants (imported markdown files)
68
+ variants = sitemapCall.variants;
69
+ if (!(!variants || Object.keys(variants).length === 0)) {
70
+ _context2.n = 5;
71
+ break;
72
+ }
73
+ callback(null, source);
74
+ return _context2.a(2);
75
+ case 5:
76
+ currentMark = performanceMeasure(currentMark, {
77
+ mark: 'Extracted Variants',
78
+ measure: 'Variant Extraction'
79
+ }, [functionName, relativePath]);
80
+
81
+ // Read and parse each markdown file
82
+ sitemapData = {}; // Create page index loader with root context
83
+ rootContext = this.rootContext || process.cwd();
84
+ loadPageIndex = createLoadServerPageIndex({
85
+ rootContext: rootContext
86
+ }); // Process all markdown files in parallel using shared logic
87
+ entries = Object.entries(variants);
88
+ _context2.n = 6;
89
+ return Promise.all(entries.map(/*#__PURE__*/function () {
90
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref) {
91
+ var _ref3, key, importPath, absolutePath, metadata, _t;
92
+ return _regenerator().w(function (_context) {
93
+ while (1) switch (_context.p = _context.n) {
94
+ case 0:
95
+ _ref3 = _slicedToArray(_ref, 2), key = _ref3[0], importPath = _ref3[1];
96
+ absolutePath = importPath.startsWith('file://') ? importPath.slice(7) : importPath;
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
+ absolutePath: absolutePath,
105
+ metadata: metadata,
106
+ error: null
107
+ });
108
+ case 3:
109
+ _context.p = 3;
110
+ _t = _context.v;
111
+ return _context.a(2, {
112
+ key: key,
113
+ absolutePath: absolutePath,
114
+ metadata: null,
115
+ error: _t instanceof Error ? _t : new Error(String(_t))
116
+ });
117
+ }
118
+ }, _callee, null, [[1, 3]]);
119
+ }));
120
+ return function (_x2) {
121
+ return _ref2.apply(this, arguments);
122
+ };
123
+ }()));
124
+ case 6:
125
+ results = _context2.v;
126
+ currentMark = performanceMeasure(currentMark, {
127
+ mark: 'Processed All Files',
128
+ measure: 'Process Markdown Files'
129
+ }, [functionName, relativePath]);
130
+
131
+ // Collect results and dependencies
132
+ _iterator = _createForOfIteratorHelper(results);
133
+ try {
134
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
135
+ result = _step.value;
136
+ if (result.error) {
137
+ // Log error but continue processing other files
138
+ console.error("Failed to process ".concat(result.key, " at ").concat(result.absolutePath, ":"), result.error);
139
+ } else if (result.metadata) {
140
+ sitemapData[result.key] = result.metadata;
141
+ // Add to dependencies for webpack watching
142
+ this.addDependency(result.absolutePath);
143
+ }
144
+ }
145
+
146
+ // Create sitemap with Orama schema for search indexing
147
+ } catch (err) {
148
+ _iterator.e(err);
149
+ } finally {
150
+ _iterator.f();
151
+ }
152
+ precomputeData = {
153
+ schema: createSitemapSchema(),
154
+ data: sitemapData
155
+ }; // Replace the factory function call with the precomputed sitemap data
156
+ modifiedSource = replacePrecomputeValue(source, precomputeData, sitemapCall);
157
+ performanceMeasure(currentMark, {
158
+ mark: 'replaced precompute',
159
+ measure: 'precompute replacement'
160
+ }, [functionName, relativePath]);
161
+
162
+ // Rewrite MDX imports to const declarations since we've precomputed the data
163
+ if (sitemapCall.importsAndComments) {
164
+ relative = sitemapCall.importsAndComments.relative; // Build a set of MDX imports to rewrite
165
+ importPathsToRewrite = new Set();
166
+ importResult = {};
167
+ for (_i = 0, _Object$entries = Object.entries(relative); _i < _Object$entries.length; _i++) {
168
+ _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2), importPath = _Object$entries$_i[0], importData = _Object$entries$_i[1];
169
+ // Check if this is an MDX file
170
+ if (importPath.endsWith('.mdx')) {
171
+ // Add to the set of imports to rewrite
172
+ importPathsToRewrite.add(importPath);
173
+ importResult[importPath] = {
174
+ positions: importData.positions,
175
+ names: importData.names
176
+ };
177
+ }
178
+ }
179
+
180
+ // Rewrite the import statements to const declarations if there are any MDX imports
181
+ if (importPathsToRewrite.size > 0) {
182
+ modifiedSource = rewriteImportsToNull(modifiedSource, importPathsToRewrite, importResult);
183
+ currentMark = performanceMeasure(currentMark, {
184
+ mark: 'rewritten imports',
185
+ measure: 'import rewriting'
186
+ }, [functionName, relativePath]);
187
+ }
188
+ }
189
+
190
+ // log any pending performance entries before completing
191
+ (_observer = observer) == null || (_observer = _observer.takeRecords()) == null || _observer.forEach(function (entry) {
192
+ return logPerformance(entry, performanceNotableMs, performanceShowWrapperMeasures, relativePath);
193
+ });
194
+ (_observer2 = observer) == null || _observer2.disconnect();
195
+ callback(null, modifiedSource);
196
+ _context2.n = 8;
197
+ break;
198
+ case 7:
199
+ _context2.p = 7;
200
+ _t2 = _context2.v;
201
+ // log any pending performance entries before completing
202
+ (_observer3 = observer) == null || (_observer3 = _observer3.takeRecords()) == null || _observer3.forEach(function (entry) {
203
+ return logPerformance(entry, performanceNotableMs, performanceShowWrapperMeasures, relativePath);
204
+ });
205
+ (_observer4 = observer) == null || _observer4.disconnect();
206
+ callback(_t2 instanceof Error ? _t2 : new Error(String(_t2)));
207
+ case 8:
208
+ return _context2.a(2);
209
+ }
210
+ }, _callee2, this, [[1, 7]]);
211
+ }));
212
+ return _loadPrecomputedSitemap.apply(this, arguments);
213
+ }
@@ -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,7 @@ 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 { resolveVariantPathsWithFs } from "./resolveModulePathWithFs.js";
6
6
  import { parseCreateFactoryCall } from "../loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js";
7
7
  import { getFileNameFromUrl } from "../loaderUtils/index.js";
8
8
  /**
@@ -22,7 +22,7 @@ export var loadServerCodeMeta = createLoadServerCodeMeta();
22
22
  * 3. Returns a Code object mapping variant names to their resolved file URLs
23
23
  *
24
24
  * The actual loading, parsing, and transformation of the variants is handled
25
- * elsewhere by the CodeHighlighter component using loadVariant.
25
+ * elsewhere by the CodeHighlighter component using loadCodeVariant.
26
26
  *
27
27
  * @param options - Configuration options (currently unused)
28
28
  * @returns LoadCodeMeta function that takes a URL and returns Promise<Code>
@@ -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.
@@ -3,7 +3,7 @@ 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
+ import { resolveModulePath, resolveModulePaths, resolveImportResult, resolveVariantPaths } from "../loaderUtils/resolveModulePath.js";
7
7
 
8
8
  /**
9
9
  * Node.js filesystem-based directory reader that converts Dirent objects
@@ -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";