@mui/internal-docs-infra 0.2.3-canary.13 → 0.2.3-canary.14

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.
@@ -6,6 +6,7 @@ import _regenerator from "@babel/runtime/helpers/esm/regenerator";
6
6
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
7
7
  import { loadCodeVariant } from "./loadCodeVariant.js";
8
8
  import { getFileNameFromUrl } from "../loaderUtils/index.js";
9
+ import { performanceMeasure } from "../loadPrecomputedCodeHighlighter/performanceLogger.js";
9
10
 
10
11
  // Helper function to get the source for a specific filename from a variant
11
12
  function getFileSource(_x, _x2, _x3) {
@@ -100,6 +101,8 @@ function _loadCodeFallback() {
100
101
  variants,
101
102
  globalsCode,
102
103
  output,
104
+ functionName,
105
+ currentMark,
103
106
  initial,
104
107
  _allFileNames,
105
108
  fileSource,
@@ -107,11 +110,13 @@ function _loadCodeFallback() {
107
110
  result,
108
111
  parseSource,
109
112
  quickVariant,
113
+ beforeInitialVariantMark,
110
114
  _allFileNames2,
111
115
  _fileSource,
112
116
  _actualFilename,
113
117
  _result,
114
118
  _parseSource,
119
+ beforeGlobalsMark,
115
120
  globalsCodeObjects,
116
121
  hasStringUrls,
117
122
  globalsPromises,
@@ -123,6 +128,7 @@ function _loadCodeFallback() {
123
128
  _yield$loadCodeVarian,
124
129
  loadedVariant,
125
130
  allFileNames,
131
+ beforeAllVariantMark,
126
132
  allVariants,
127
133
  variantPromises,
128
134
  variantResults,
@@ -145,11 +151,14 @@ function _loadCodeFallback() {
145
151
  options = _args4.length > 3 && _args4[3] !== undefined ? _args4[3] : {};
146
152
  shouldHighlight = options.shouldHighlight, fallbackUsesExtraFiles = options.fallbackUsesExtraFiles, fallbackUsesAllVariants = options.fallbackUsesAllVariants, sourceParser = options.sourceParser, loadSource = options.loadSource, loadVariantMeta = options.loadVariantMeta, loadCodeMeta = options.loadCodeMeta, initialFilename = options.initialFilename, variants = options.variants, globalsCode = options.globalsCode, output = options.output;
147
153
  loaded = _extends({}, loaded);
148
-
149
- // Step 1: Ensure we have the initial variant loaded
154
+ functionName = 'Load Fallback Code';
155
+ currentMark = performanceMeasure(undefined, {
156
+ mark: 'Start',
157
+ measure: 'Start'
158
+ }, [functionName, url], true); // Step 1: Ensure we have the initial variant loaded
150
159
  initial = loaded[initialVariant];
151
160
  if (initial) {
152
- _context4.n = 5;
161
+ _context4.n = 6;
153
162
  break;
154
163
  }
155
164
  if (loadCodeMeta) {
@@ -177,8 +186,13 @@ function _loadCodeFallback() {
177
186
  }
178
187
  throw new Error("Initial variant \"".concat(initialVariant, "\" not found in loaded code."));
179
188
  case 5:
189
+ currentMark = performanceMeasure(currentMark, {
190
+ mark: 'Loaded Code Meta',
191
+ measure: 'Code Meta Loading'
192
+ }, [functionName, url]);
193
+ case 6:
180
194
  if (!(typeof initial !== 'string' && initial.allFilesListed && !fallbackUsesExtraFiles && !fallbackUsesAllVariants)) {
181
- _context4.n = 16;
195
+ _context4.n = 17;
182
196
  break;
183
197
  }
184
198
  // Collect all file names from the loaded code
@@ -193,40 +207,50 @@ function _loadCodeFallback() {
193
207
  }
194
208
 
195
209
  // Get the source for the requested filename (or main file if not specified)
196
- _context4.p = 6;
197
- _context4.n = 7;
210
+ _context4.p = 7;
211
+ _context4.n = 8;
198
212
  return getFileSource(initial, initialFilename, loadSource);
199
- case 7:
213
+ case 8:
200
214
  result = _context4.v;
201
215
  fileSource = result.source;
202
216
  actualFilename = result.filename;
203
- _context4.n = 9;
217
+ _context4.n = 10;
204
218
  break;
205
- case 8:
206
- _context4.p = 8;
219
+ case 9:
220
+ _context4.p = 9;
207
221
  _t5 = _context4.v;
208
222
  throw new Error("Failed to get source for file ".concat(initialFilename || initial.fileName, " in variant ").concat(initialVariant, ": ").concat(_t5));
209
- case 9:
223
+ case 10:
224
+ currentMark = performanceMeasure(currentMark, {
225
+ mark: 'Loaded Main File',
226
+ measure: 'Main File Loading'
227
+ }, [functionName, url]);
228
+
229
+ // If we need highlighting and have a string source, parse it
210
230
  if (!(shouldHighlight && typeof fileSource === 'string' && sourceParser && actualFilename)) {
211
- _context4.n = 14;
231
+ _context4.n = 15;
212
232
  break;
213
233
  }
214
- _context4.p = 10;
215
- _context4.n = 11;
234
+ _context4.p = 11;
235
+ _context4.n = 12;
216
236
  return sourceParser;
217
- case 11:
237
+ case 12:
218
238
  parseSource = _context4.v;
219
239
  fileSource = parseSource(fileSource, actualFilename);
220
- _context4.n = 13;
240
+ _context4.n = 14;
221
241
  break;
222
- case 12:
223
- _context4.p = 12;
242
+ case 13:
243
+ _context4.p = 13;
224
244
  _t6 = _context4.v;
225
245
  throw new Error("Failed to parse source for highlighting (variant: ".concat(initialVariant, ", file: ").concat(actualFilename, "): ").concat(JSON.stringify(_t6)));
226
- case 13:
227
- _context4.n = 15;
228
- break;
229
246
  case 14:
247
+ currentMark = performanceMeasure(currentMark, {
248
+ mark: 'Parsed Main File',
249
+ measure: 'Main File Parsing'
250
+ }, [functionName, url]);
251
+ _context4.n = 16;
252
+ break;
253
+ case 15:
230
254
  if (shouldHighlight && typeof fileSource === 'string' && !actualFilename) {
231
255
  // Create basic HAST node when we can't parse due to missing filename
232
256
  // This marks that the source has passed through the parsing pipeline
@@ -238,7 +262,7 @@ function _loadCodeFallback() {
238
262
  }]
239
263
  };
240
264
  }
241
- case 15:
265
+ case 16:
242
266
  // Update the loaded code with any changes we made
243
267
  if (actualFilename && actualFilename === initial.fileName) {
244
268
  initial = _extends(_extends({}, initial), {}, {
@@ -261,35 +285,40 @@ function _loadCodeFallback() {
261
285
  initialExtraFiles: initial.extraFiles || {},
262
286
  allFileNames: Array.from(_allFileNames)
263
287
  });
264
- case 16:
288
+ case 17:
265
289
  if (!(typeof initial === 'string')) {
266
- _context4.n = 33;
290
+ _context4.n = 34;
267
291
  break;
268
292
  }
269
- _context4.p = 17;
293
+ _context4.p = 18;
270
294
  if (!loadVariantMeta) {
271
- _context4.n = 19;
295
+ _context4.n = 20;
272
296
  break;
273
297
  }
274
- _context4.n = 18;
298
+ _context4.n = 19;
275
299
  return loadVariantMeta(initialVariant, initial);
276
- case 18:
300
+ case 19:
277
301
  quickVariant = _context4.v;
278
- _context4.n = 20;
302
+ currentMark = performanceMeasure(currentMark, {
303
+ mark: 'Loaded Initial Variant Meta',
304
+ measure: 'Initial Variant Meta Loading'
305
+ }, [functionName, url]);
306
+ _context4.n = 21;
279
307
  break;
280
- case 19:
308
+ case 20:
281
309
  // Create a basic variant using fallback logic
282
310
  quickVariant = {
283
311
  url: initial,
284
312
  fileName: getFileNameFromUrl(initial).fileName
285
313
  };
286
- case 20:
314
+ case 21:
315
+ beforeInitialVariantMark = currentMark;
287
316
  loaded = _extends(_extends({}, loaded), {}, _defineProperty({}, initialVariant, quickVariant));
288
317
  initial = quickVariant;
289
318
 
290
319
  // If we have all files listed and don't need extra file processing, we can optimize
291
320
  if (!(quickVariant.allFilesListed && !fallbackUsesExtraFiles && !fallbackUsesAllVariants)) {
292
- _context4.n = 31;
321
+ _context4.n = 32;
293
322
  break;
294
323
  }
295
324
  // Collect all file names from the quick load
@@ -304,40 +333,48 @@ function _loadCodeFallback() {
304
333
  }
305
334
 
306
335
  // Get the source for the requested filename (or main file if not specified)
307
- _context4.p = 21;
308
- _context4.n = 22;
336
+ _context4.p = 22;
337
+ _context4.n = 23;
309
338
  return getFileSource(quickVariant, initialFilename, loadSource);
310
- case 22:
339
+ case 23:
311
340
  _result = _context4.v;
312
341
  _fileSource = _result.source;
313
342
  _actualFilename = _result.filename;
314
- _context4.n = 24;
343
+ currentMark = performanceMeasure(currentMark, {
344
+ mark: 'Loaded Initial File',
345
+ measure: 'Initial File Loading'
346
+ }, [functionName, initialFilename || 'unknown', url]);
347
+ _context4.n = 25;
315
348
  break;
316
- case 23:
317
- _context4.p = 23;
349
+ case 24:
350
+ _context4.p = 24;
318
351
  _t7 = _context4.v;
319
352
  throw new Error("Failed to get source for file ".concat(initialFilename || quickVariant.fileName, " in variant ").concat(initialVariant, ": ").concat(_t7));
320
- case 24:
353
+ case 25:
321
354
  if (!(shouldHighlight && typeof _fileSource === 'string' && sourceParser && _actualFilename)) {
322
- _context4.n = 29;
355
+ _context4.n = 30;
323
356
  break;
324
357
  }
325
- _context4.p = 25;
326
- _context4.n = 26;
358
+ _context4.p = 26;
359
+ _context4.n = 27;
327
360
  return sourceParser;
328
- case 26:
361
+ case 27:
329
362
  _parseSource = _context4.v;
330
363
  _fileSource = _parseSource(_fileSource, _actualFilename);
331
- _context4.n = 28;
364
+ currentMark = performanceMeasure(currentMark, {
365
+ mark: 'Parsed Initial File',
366
+ measure: 'Initial File Parsing'
367
+ }, [functionName, initialFilename || 'unknown', url]);
368
+ _context4.n = 29;
332
369
  break;
333
- case 27:
334
- _context4.p = 27;
370
+ case 28:
371
+ _context4.p = 28;
335
372
  _t8 = _context4.v;
336
373
  throw new Error("Failed to parse source for highlighting (variant: ".concat(initialVariant, ", file: ").concat(_actualFilename, "): ").concat(JSON.stringify(_t8)));
337
- case 28:
338
- _context4.n = 30;
339
- break;
340
374
  case 29:
375
+ _context4.n = 31;
376
+ break;
377
+ case 30:
341
378
  if (shouldHighlight && typeof _fileSource === 'string' && !_actualFilename) {
342
379
  // Create basic HAST node when we can't parse due to missing filename
343
380
  // This marks that the source has passed through the parsing pipeline
@@ -349,7 +386,7 @@ function _loadCodeFallback() {
349
386
  }]
350
387
  };
351
388
  }
352
- case 30:
389
+ case 31:
353
390
  // Update the loaded code with any changes we made
354
391
  if (_actualFilename && _actualFilename === quickVariant.fileName) {
355
392
  initial = _extends(_extends({}, quickVariant), {}, {
@@ -363,6 +400,10 @@ function _loadCodeFallback() {
363
400
  });
364
401
  loaded = _extends(_extends({}, loaded), {}, _defineProperty({}, initialVariant, initial));
365
402
  }
403
+ currentMark = performanceMeasure(beforeInitialVariantMark, {
404
+ mark: 'Loaded Initial Files',
405
+ measure: 'Initial Files Loading'
406
+ }, [functionName, url], true);
366
407
 
367
408
  // Early return - we have all the info we need
368
409
  return _context4.a(2, {
@@ -372,31 +413,33 @@ function _loadCodeFallback() {
372
413
  initialExtraFiles: quickVariant.extraFiles || {},
373
414
  allFileNames: Array.from(_allFileNames2)
374
415
  });
375
- case 31:
376
- _context4.n = 33;
377
- break;
378
416
  case 32:
379
- _context4.p = 32;
417
+ _context4.n = 34;
418
+ break;
419
+ case 33:
420
+ _context4.p = 33;
380
421
  _t9 = _context4.v;
381
422
  throw new Error("Failed to load initial variant code (variant: ".concat(initialVariant, ", url: ").concat(initial, "): ").concat(JSON.stringify(_t9)));
382
- case 33:
423
+ case 34:
424
+ beforeGlobalsMark = currentMark; // Step 2b: Fall back to full loadCodeVariant processing
425
+ // Load globalsCode - convert string URLs to Code objects, keep Code objects as-is
383
426
  if (!(globalsCode && globalsCode.length > 0)) {
384
- _context4.n = 36;
427
+ _context4.n = 37;
385
428
  break;
386
429
  }
387
430
  hasStringUrls = globalsCode.some(function (item) {
388
431
  return typeof item === 'string';
389
432
  });
390
433
  if (!(hasStringUrls && !loadCodeMeta)) {
391
- _context4.n = 34;
434
+ _context4.n = 35;
392
435
  break;
393
436
  }
394
437
  throw new Error('loadCodeMeta function is required when globalsCode contains string URLs');
395
- case 34:
438
+ case 35:
396
439
  // Load all string URLs in parallel, keep Code objects as-is
397
440
  globalsPromises = globalsCode.map(/*#__PURE__*/function () {
398
441
  var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(globalItem) {
399
- var _t;
442
+ var codeMeta, _t;
400
443
  return _regenerator().w(function (_context2) {
401
444
  while (1) switch (_context2.p = _context2.n) {
402
445
  case 0:
@@ -408,7 +451,12 @@ function _loadCodeFallback() {
408
451
  _context2.n = 2;
409
452
  return loadCodeMeta(globalItem);
410
453
  case 2:
411
- return _context2.a(2, _context2.v);
454
+ codeMeta = _context2.v;
455
+ currentMark = performanceMeasure(currentMark, {
456
+ mark: 'Loaded Global Code Meta',
457
+ measure: 'Global Code Meta Loading'
458
+ }, [functionName, globalItem, url]);
459
+ return _context2.a(2, codeMeta);
412
460
  case 3:
413
461
  _context2.p = 3;
414
462
  _t = _context2.v;
@@ -424,11 +472,15 @@ function _loadCodeFallback() {
424
472
  return _ref.apply(this, arguments);
425
473
  };
426
474
  }());
427
- _context4.n = 35;
475
+ _context4.n = 36;
428
476
  return Promise.all(globalsPromises);
429
- case 35:
430
- globalsCodeObjects = _context4.v;
431
477
  case 36:
478
+ globalsCodeObjects = _context4.v;
479
+ currentMark = performanceMeasure(beforeGlobalsMark, {
480
+ mark: 'Loaded Globals Meta',
481
+ measure: 'Globals Meta Loading'
482
+ }, [functionName, url], true);
483
+ case 37:
432
484
  if (globalsCodeObjects && globalsCodeObjects.length > 0) {
433
485
  resolvedGlobalsCode = [];
434
486
  _iterator = _createForOfIteratorHelper(globalsCodeObjects);
@@ -447,8 +499,8 @@ function _loadCodeFallback() {
447
499
  _iterator.f();
448
500
  }
449
501
  }
450
- _context4.p = 37;
451
- _context4.n = 38;
502
+ _context4.p = 38;
503
+ _context4.n = 39;
452
504
  return loadCodeVariant(url, initialVariant, initial, {
453
505
  sourceParser: sourceParser,
454
506
  loadSource: loadSource,
@@ -463,19 +515,24 @@ function _loadCodeFallback() {
463
515
  // Pass resolved globalsCode
464
516
  output: output
465
517
  });
466
- case 38:
518
+ case 39:
467
519
  _yield$loadCodeVarian = _context4.v;
468
520
  loadedVariant = _yield$loadCodeVarian.code;
521
+ currentMark = performanceMeasure(currentMark, {
522
+ mark: 'Loaded Initial Variant',
523
+ measure: 'Initial Variant Loading'
524
+ }, [functionName, url], true);
525
+
469
526
  // Update the loaded code with the processed variant
470
527
  loaded = _extends(_extends({}, loaded), {}, _defineProperty({}, initialVariant, loadedVariant));
471
528
  initial = loadedVariant;
472
- _context4.n = 40;
529
+ _context4.n = 41;
473
530
  break;
474
- case 39:
475
- _context4.p = 39;
531
+ case 40:
532
+ _context4.p = 40;
476
533
  _t0 = _context4.v;
477
534
  throw new Error("Failed to load initial variant using loadCodeVariant (variant: ".concat(initialVariant, ", url: ").concat(url, "): ").concat(JSON.stringify(_t0)));
478
- case 40:
535
+ case 41:
479
536
  // Step 3: Collect all file names
480
537
  allFileNames = new Set();
481
538
  if (initial.fileName) {
@@ -491,19 +548,19 @@ function _loadCodeFallback() {
491
548
 
492
549
  // Step 4: Handle fallbackUsesAllVariants - load all variants to get all possible files
493
550
  if (!fallbackUsesAllVariants) {
494
- _context4.n = 43;
551
+ _context4.n = 45;
495
552
  break;
496
553
  }
497
- // Determine all variants to process - use provided variants or infer from loaded code
554
+ beforeAllVariantMark = currentMark; // Determine all variants to process - use provided variants or infer from loaded code
498
555
  allVariants = variants || Object.keys(loaded || {});
499
556
  if (!(allVariants.length === 0)) {
500
- _context4.n = 41;
557
+ _context4.n = 42;
501
558
  break;
502
559
  }
503
560
  console.warn('No variants found for fallbackUsesAllVariants processing');
504
- _context4.n = 43;
561
+ _context4.n = 44;
505
562
  break;
506
- case 41:
563
+ case 42:
507
564
  // Process all required variants, not just the ones already loaded
508
565
  variantPromises = allVariants.map(/*#__PURE__*/function () {
509
566
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(variantName) {
@@ -535,6 +592,10 @@ function _loadCodeFallback() {
535
592
  variant = allCode[variantName];
536
593
  // Update loaded with all variants from loadCodeMeta
537
594
  loaded = _extends(_extends({}, loaded), allCode);
595
+ currentMark = performanceMeasure(currentMark, {
596
+ mark: 'Loaded Initial Code Meta',
597
+ measure: 'Initial Code Meta Loading'
598
+ }, [functionName, url]);
538
599
  _context3.n = 5;
539
600
  break;
540
601
  case 4:
@@ -599,6 +660,10 @@ function _loadCodeFallback() {
599
660
  if (_loadedVariant.extraFiles) {
600
661
  fileNames.push.apply(fileNames, _toConsumableArray(Object.keys(_loadedVariant.extraFiles)));
601
662
  }
663
+ currentMark = performanceMeasure(currentMark, {
664
+ mark: 'Loaded Initial Variant',
665
+ measure: 'Initial Variant Loading'
666
+ }, [functionName, variantName, url], true);
602
667
  return _context3.a(2, {
603
668
  variantName: variantName,
604
669
  loadedVariant: _loadedVariant,
@@ -621,9 +686,9 @@ function _loadCodeFallback() {
621
686
  return _ref2.apply(this, arguments);
622
687
  };
623
688
  }());
624
- _context4.n = 42;
689
+ _context4.n = 43;
625
690
  return Promise.all(variantPromises);
626
- case 42:
691
+ case 43:
627
692
  variantResults = _context4.v;
628
693
  // Update loaded code and collect file names
629
694
  variantResults.forEach(function (_ref3) {
@@ -637,37 +702,46 @@ function _loadCodeFallback() {
637
702
  return allFileNames.add(fileName);
638
703
  });
639
704
  });
640
- case 43:
705
+ case 44:
706
+ currentMark = performanceMeasure(beforeAllVariantMark, {
707
+ mark: 'Loaded Initial Variants',
708
+ measure: 'Initial Variants Loading'
709
+ }, [functionName, url], true);
710
+ case 45:
641
711
  // Ensure we have the latest initial variant data
642
712
  finalInitial = loaded[initialVariant];
643
713
  if (!(!finalInitial || typeof finalInitial === 'string')) {
644
- _context4.n = 44;
714
+ _context4.n = 46;
645
715
  break;
646
716
  }
647
717
  throw new Error("Failed to process initial variant: ".concat(initialVariant));
648
- case 44:
649
- _context4.p = 44;
650
- _context4.n = 45;
718
+ case 46:
719
+ _context4.p = 46;
720
+ _context4.n = 47;
651
721
  return getFileSource(finalInitial, initialFilename, loadSource);
652
- case 45:
722
+ case 47:
653
723
  _result2 = _context4.v;
654
724
  finalFileSource = _result2.source;
655
725
  finalFilename = _result2.filename;
656
- _context4.n = 48;
726
+ _context4.n = 50;
657
727
  break;
658
- case 46:
659
- _context4.p = 46;
728
+ case 48:
729
+ _context4.p = 48;
660
730
  _t1 = _context4.v;
661
731
  if (!(!finalInitial.fileName && !finalInitial.source)) {
662
- _context4.n = 47;
732
+ _context4.n = 49;
663
733
  break;
664
734
  }
665
735
  throw new Error("Cannot determine filename for initial variant \"".concat(initialVariant, "\". ") + "No fileName available in variant definition, no initialFilename provided, and no source available.");
666
- case 47:
736
+ case 49:
667
737
  // Fall back to the main file with proper validation
668
738
  finalFileSource = finalInitial.source || '';
669
739
  finalFilename = finalInitial.fileName;
670
- case 48:
740
+ case 50:
741
+ currentMark = performanceMeasure(currentMark, {
742
+ mark: 'Loaded Initial File',
743
+ measure: 'Initial File Loading'
744
+ }, [functionName, url]);
671
745
  return _context4.a(2, {
672
746
  code: loaded,
673
747
  initialFilename: finalFilename,
@@ -677,7 +751,7 @@ function _loadCodeFallback() {
677
751
  processedGlobalsCode: globalsCodeObjects
678
752
  });
679
753
  }
680
- }, _callee4, null, [[44, 46], [37, 39], [25, 27], [21, 23], [17, 32], [10, 12], [6, 8], [1, 3]]);
754
+ }, _callee4, null, [[46, 48], [38, 40], [26, 28], [22, 24], [18, 33], [11, 13], [7, 9], [1, 3]]);
681
755
  }));
682
756
  return _loadCodeFallback.apply(this, arguments);
683
757
  }
@@ -12,6 +12,7 @@ import { transformSource } from "./transformSource.js";
12
12
  import { diffHast } from "./diffHast.js";
13
13
  import { getFileNameFromUrl } from "../loaderUtils/index.js";
14
14
  import { mergeExternals } from "../loaderUtils/mergeExternals.js";
15
+ import { performanceMeasure } from "../loadPrecomputedCodeHighlighter/performanceLogger.js";
15
16
  function compressAsync(input) {
16
17
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
17
18
  return new Promise(function (resolve, reject) {
@@ -138,6 +139,8 @@ function _loadSingleFile() {
138
139
  extraFilesFromSource,
139
140
  extraDependenciesFromSource,
140
141
  externalsFromSource,
142
+ functionName,
143
+ currentMark,
141
144
  loadPromise,
142
145
  loadResult,
143
146
  _i,
@@ -170,6 +173,11 @@ function _loadSingleFile() {
170
173
  knownExtraFiles = _args.length > 11 && _args[11] !== undefined ? _args[11] : new Set();
171
174
  _options$disableTrans = options.disableTransforms, disableTransforms = _options$disableTrans === void 0 ? false : _options$disableTrans, _options$disableParsi = options.disableParsing, disableParsing = _options$disableParsi === void 0 ? false : _options$disableParsi;
172
175
  finalSource = source;
176
+ functionName = 'Load Variant File';
177
+ currentMark = performanceMeasure(undefined, {
178
+ mark: 'Start',
179
+ measure: 'Start'
180
+ }, [functionName, url || fileName], true); // Load source if not provided
173
181
  if (finalSource) {
174
182
  _context.n = 20;
175
183
  break;
@@ -201,6 +209,10 @@ function _loadSingleFile() {
201
209
  extraFilesFromSource = loadResult.extraFiles;
202
210
  extraDependenciesFromSource = loadResult.extraDependencies;
203
211
  externalsFromSource = loadResult.externals;
212
+ currentMark = performanceMeasure(currentMark, {
213
+ mark: 'Loaded File',
214
+ measure: 'File Loading'
215
+ }, [functionName, url]);
204
216
 
205
217
  // Validate that extraFiles from loadSource contain only absolute URLs as values
206
218
  if (!extraFilesFromSource) {
@@ -321,6 +333,10 @@ function _loadSingleFile() {
321
333
  return transformSource(finalSource, normalizePathKey(fileName), sourceTransformers);
322
334
  case 21:
323
335
  finalTransforms = _context.v;
336
+ currentMark = performanceMeasure(currentMark, {
337
+ mark: 'Transformed File',
338
+ measure: 'File Transforming'
339
+ }, [functionName, url || fileName]);
324
340
  case 22:
325
341
  if (!(typeof finalSource === 'string' && !disableParsing)) {
326
342
  _context.n = 31;
@@ -339,6 +355,10 @@ function _loadSingleFile() {
339
355
  case 24:
340
356
  parseSource = _context.v;
341
357
  finalSource = parseSource(finalSource, fileName);
358
+ currentMark = performanceMeasure(currentMark, {
359
+ mark: 'Parsed File',
360
+ measure: 'File Parsing'
361
+ }, [functionName, url || fileName]);
342
362
  if (!(finalTransforms && !disableTransforms)) {
343
363
  _context.n = 26;
344
364
  break;
@@ -347,6 +367,10 @@ function _loadSingleFile() {
347
367
  return diffHast(sourceString, finalSource, normalizePathKey(fileName), finalTransforms, parseSource);
348
368
  case 25:
349
369
  finalTransforms = _context.v;
370
+ currentMark = performanceMeasure(currentMark, {
371
+ mark: 'Transform Parsed File',
372
+ measure: 'Parsed File Transforming'
373
+ }, [functionName, url || fileName]);
350
374
  case 26:
351
375
  if (!(options.output === 'hastGzip' && process.env.NODE_ENV === 'production')) {
352
376
  _context.n = 28;
@@ -363,6 +387,10 @@ function _loadSingleFile() {
363
387
  finalSource = {
364
388
  hastGzip: hastGzip
365
389
  };
390
+ currentMark = performanceMeasure(currentMark, {
391
+ mark: 'Compressed File',
392
+ measure: 'File Compression'
393
+ }, [functionName, url || fileName]);
366
394
  _context.n = 29;
367
395
  break;
368
396
  case 28:
@@ -371,6 +399,10 @@ function _loadSingleFile() {
371
399
  finalSource = {
372
400
  hastJson: JSON.stringify(finalSource)
373
401
  };
402
+ performanceMeasure(currentMark, {
403
+ mark: 'JSON Stringified File',
404
+ measure: 'File Stringification'
405
+ }, [functionName, url || fileName]);
374
406
  }
375
407
  case 29:
376
408
  _context.n = 31;
@@ -668,6 +700,8 @@ function _loadCodeVariant() {
668
700
  sourceTransformers,
669
701
  globalsCode,
670
702
  loadSourceCache,
703
+ functionName,
704
+ currentMark,
671
705
  _getFileNameFromUrl,
672
706
  _fileName,
673
707
  loadedFiles,
@@ -680,11 +714,11 @@ function _loadCodeVariant() {
680
714
  fileName,
681
715
  _finalVariant,
682
716
  mainFileResult,
683
- allExtraFiles,
684
717
  _i5,
685
718
  _Object$keys3,
686
719
  _extraFileName,
687
720
  extraFilesToLoad,
721
+ externalsMergedMark,
688
722
  globalsFileKeys,
689
723
  existingFiles,
690
724
  _i6,
@@ -701,6 +735,7 @@ function _loadCodeVariant() {
701
735
  _key,
702
736
  value,
703
737
  conflictFreeKey,
738
+ allExtraFiles,
704
739
  loadableFiles,
705
740
  _i8,
706
741
  _Object$entries4,
@@ -736,8 +771,13 @@ function _loadCodeVariant() {
736
771
  case 1:
737
772
  sourceParser = options.sourceParser, loadSource = options.loadSource, loadVariantMeta = options.loadVariantMeta, sourceTransformers = options.sourceTransformers, globalsCode = options.globalsCode; // Create a cache for loadSource calls scoped to this loadCodeVariant call
738
773
  loadSourceCache = new Map();
774
+ functionName = 'Load Variant';
775
+ currentMark = performanceMeasure(undefined, {
776
+ mark: 'Start',
777
+ measure: 'Start'
778
+ }, [functionName, url || variantName], true);
739
779
  if (!(typeof variant === 'string')) {
740
- _context6.n = 6;
780
+ _context6.n = 7;
741
781
  break;
742
782
  }
743
783
  if (loadVariantMeta) {
@@ -756,7 +796,7 @@ function _loadCodeVariant() {
756
796
  url: variant,
757
797
  fileName: _fileName
758
798
  };
759
- _context6.n = 6;
799
+ _context6.n = 7;
760
800
  break;
761
801
  case 3:
762
802
  _context6.p = 3;
@@ -771,6 +811,11 @@ function _loadCodeVariant() {
771
811
  _t9 = _context6.v;
772
812
  throw new Error("Failed to load variant code (variant: ".concat(variantName, ", url: ").concat(variant, "): ").concat(JSON.stringify(_t9)));
773
813
  case 6:
814
+ currentMark = performanceMeasure(currentMark, {
815
+ mark: 'Loaded Variant Meta',
816
+ measure: 'Variant Meta Loading'
817
+ }, [functionName, url || variantName]);
818
+ case 7:
774
819
  loadedFiles = new Set();
775
820
  if (url) {
776
821
  loadedFiles.add(url);
@@ -789,7 +834,7 @@ function _loadCodeVariant() {
789
834
  // Load main file
790
835
  fileName = variant.fileName || (url ? getFileNameFromUrl(url).fileName : undefined); // If we don't have a fileName and no URL, we can't parse or transform but can still return the code
791
836
  if (!(!fileName && !url)) {
792
- _context6.n = 7;
837
+ _context6.n = 8;
793
838
  break;
794
839
  }
795
840
  // Return the variant as-is without parsing or transforms
@@ -808,56 +853,66 @@ function _loadCodeVariant() {
808
853
  // No dependencies without URL
809
854
  externals: {} // No externals without URL
810
855
  });
811
- case 7:
856
+ case 8:
812
857
  if (fileName) {
813
- _context6.n = 8;
858
+ _context6.n = 9;
814
859
  break;
815
860
  }
816
861
  throw new Error("No fileName available for variant \"".concat(variantName, "\". ") + "Please provide a fileName in the variant definition or ensure the URL has a valid file extension.");
817
- case 8:
818
- _context6.n = 9;
862
+ case 9:
863
+ _context6.n = 10;
819
864
  return loadSingleFile(variantName, fileName, variant.source, url, loadSource, sourceParser, sourceTransformers, loadSourceCache, variant.transforms, _extends(_extends({}, options), {}, {
820
865
  loadedFiles: loadedFiles
821
866
  }), variant.allFilesListed || false, knownExtraFiles);
822
- case 9:
867
+ case 10:
823
868
  mainFileResult = _context6.v;
824
869
  // Add files used from main file loading
825
870
  if (mainFileResult.extraDependencies) {
826
871
  allFilesUsed.push.apply(allFilesUsed, _toConsumableArray(mainFileResult.extraDependencies));
827
872
  }
873
+ currentMark = performanceMeasure(currentMark, {
874
+ mark: 'Loaded Main File',
875
+ measure: 'Main File Loading'
876
+ }, [functionName, url || fileName], true);
828
877
 
829
- // Add externals from main file loading
830
- if (mainFileResult.externals) {
831
- allExternals = mergeExternals([allExternals, mainFileResult.externals]);
832
- }
833
- allExtraFiles = {}; // Validate extraFiles keys from variant definition
878
+ // Validate extraFiles keys from variant definition
834
879
  if (!variant.extraFiles) {
835
- _context6.n = 12;
880
+ _context6.n = 13;
836
881
  break;
837
882
  }
838
883
  _i5 = 0, _Object$keys3 = Object.keys(variant.extraFiles);
839
- case 10:
884
+ case 11:
840
885
  if (!(_i5 < _Object$keys3.length)) {
841
- _context6.n = 12;
886
+ _context6.n = 13;
842
887
  break;
843
888
  }
844
889
  _extraFileName = _Object$keys3[_i5];
845
890
  if (!isAbsolutePath(_extraFileName)) {
846
- _context6.n = 11;
891
+ _context6.n = 12;
847
892
  break;
848
893
  }
849
894
  throw new Error("Invalid extraFiles key in variant: \"".concat(_extraFileName, "\" appears to be an absolute path. ") + "extraFiles keys in variant definition should be relative paths from the main file.");
850
- case 11:
895
+ case 12:
851
896
  _i5++;
852
- _context6.n = 10;
897
+ _context6.n = 11;
853
898
  break;
854
- case 12:
899
+ case 13:
855
900
  // Collect extra files from variant definition and from loaded source
856
- extraFilesToLoad = _extends(_extends({}, variant.extraFiles || {}), mainFileResult.extraFiles || {}); // Track which files come from globals for metadata marking
901
+ extraFilesToLoad = _extends(_extends({}, variant.extraFiles || {}), mainFileResult.extraFiles || {}); // Add externals from main file loading
902
+ if (mainFileResult.externals) {
903
+ allExternals = mergeExternals([allExternals, mainFileResult.externals]);
904
+ }
905
+ externalsMergedMark = performanceMeasure(currentMark, {
906
+ mark: 'Externals Merged',
907
+ measure: 'Merging Externals'
908
+ }, [functionName, url || fileName]);
909
+ currentMark = externalsMergedMark;
910
+
911
+ // Track which files come from globals for metadata marking
857
912
  globalsFileKeys = new Set(); // Track globals file keys for loadExtraFiles
858
913
  // Process globalsCode array and add to extraFiles if provided
859
914
  if (!(globalsCode && globalsCode.length > 0)) {
860
- _context6.n = 14;
915
+ _context6.n = 15;
861
916
  break;
862
917
  }
863
918
  // Collect existing filenames to avoid conflicts
@@ -907,6 +962,10 @@ function _loadCodeVariant() {
907
962
  return loadVariantMeta(variantName, globalsItem);
908
963
  case 3:
909
964
  globalsVariant = _context5.v;
965
+ currentMark = performanceMeasure(currentMark, {
966
+ mark: 'Globals Variant Meta Loaded',
967
+ measure: 'Globals Variant Meta Loading'
968
+ }, [functionName, globalsItem, url || fileName]);
910
969
  _context5.n = 5;
911
970
  break;
912
971
  case 4:
@@ -927,6 +986,10 @@ function _loadCodeVariant() {
927
986
  );
928
987
  case 8:
929
988
  globalsResult = _context5.v;
989
+ currentMark = performanceMeasure(currentMark, {
990
+ mark: 'Globals Variant Loaded',
991
+ measure: 'Globals Variant Loading'
992
+ }, [functionName, globalsVariant.url || variantName, url || fileName]);
930
993
  return _context5.a(2, globalsResult);
931
994
  case 9:
932
995
  _context5.p = 9;
@@ -941,9 +1004,9 @@ function _loadCodeVariant() {
941
1004
  return _ref4.apply(this, arguments);
942
1005
  };
943
1006
  }()); // Wait for all globals to load
944
- _context6.n = 13;
1007
+ _context6.n = 14;
945
1008
  return Promise.all(globalsPromises);
946
- case 13:
1009
+ case 14:
947
1010
  globalsResults = _context6.v;
948
1011
  // Merge results from all globals
949
1012
  _iterator4 = _createForOfIteratorHelper(globalsResults);
@@ -981,13 +1044,18 @@ function _loadCodeVariant() {
981
1044
  } finally {
982
1045
  _iterator4.f();
983
1046
  }
984
- case 14:
1047
+ case 15:
1048
+ currentMark = performanceMeasure(externalsMergedMark, {
1049
+ mark: 'Globals Loaded',
1050
+ measure: 'Globals Loading'
1051
+ }, [functionName, url || fileName], true);
1052
+ allExtraFiles = {}; // Load all extra files if any exist and we have a URL
985
1053
  if (!(Object.keys(extraFilesToLoad).length > 0)) {
986
- _context6.n = 19;
1054
+ _context6.n = 21;
987
1055
  break;
988
1056
  }
989
1057
  if (url) {
990
- _context6.n = 17;
1058
+ _context6.n = 18;
991
1059
  break;
992
1060
  }
993
1061
  // If there's no URL, we can only load extra files that have inline source or absolute URLs
@@ -1005,7 +1073,7 @@ function _loadCodeVariant() {
1005
1073
  }
1006
1074
  }
1007
1075
  if (!(Object.keys(loadableFiles).length > 0)) {
1008
- _context6.n = 16;
1076
+ _context6.n = 17;
1009
1077
  break;
1010
1078
  }
1011
1079
  // Process loadable files: inline sources without URL-based loading, absolute URLs with loading
@@ -1032,10 +1100,10 @@ function _loadCodeVariant() {
1032
1100
  }
1033
1101
  }
1034
1102
  if (!(Object.keys(urlFilesToLoad).length > 0)) {
1035
- _context6.n = 16;
1103
+ _context6.n = 17;
1036
1104
  break;
1037
1105
  }
1038
- _context6.n = 15;
1106
+ _context6.n = 16;
1039
1107
  return loadExtraFiles(variantName, urlFilesToLoad, '',
1040
1108
  // No base URL needed for absolute URLs
1041
1109
  '',
@@ -1044,28 +1112,33 @@ function _loadCodeVariant() {
1044
1112
  loadedFiles: loadedFiles
1045
1113
  }), variant.allFilesListed || false, knownExtraFiles, globalsFileKeys // Pass globals file tracking
1046
1114
  );
1047
- case 15:
1115
+ case 16:
1048
1116
  extraFilesResult = _context6.v;
1049
1117
  allExtraFiles = _extends(_extends({}, allExtraFiles), extraFilesResult.extraFiles);
1050
1118
  allFilesUsed.push.apply(allFilesUsed, _toConsumableArray(extraFilesResult.allFilesUsed));
1051
1119
  allExternals = mergeExternals([allExternals, extraFilesResult.allExternals]);
1052
- case 16:
1053
- _context6.n = 19;
1054
- break;
1055
1120
  case 17:
1056
- _context6.n = 18;
1121
+ _context6.n = 20;
1122
+ break;
1123
+ case 18:
1124
+ _context6.n = 19;
1057
1125
  return loadExtraFiles(variantName, extraFilesToLoad, url, url,
1058
1126
  // Entry URL is the same as the main file URL
1059
1127
  loadSource, sourceParser, sourceTransformers, loadSourceCache, _extends(_extends({}, options), {}, {
1060
1128
  loadedFiles: loadedFiles
1061
1129
  }), variant.allFilesListed || false, knownExtraFiles, globalsFileKeys // Pass globals file tracking
1062
1130
  );
1063
- case 18:
1131
+ case 19:
1064
1132
  _extraFilesResult = _context6.v;
1065
1133
  allExtraFiles = _extraFilesResult.extraFiles;
1066
1134
  allFilesUsed.push.apply(allFilesUsed, _toConsumableArray(_extraFilesResult.allFilesUsed));
1067
1135
  allExternals = mergeExternals([allExternals, _extraFilesResult.allExternals]);
1068
- case 19:
1136
+ case 20:
1137
+ currentMark = performanceMeasure(currentMark, {
1138
+ mark: 'Extra Files Loaded',
1139
+ measure: 'Extra Files Loading'
1140
+ }, [functionName, url || fileName], true);
1141
+ case 21:
1069
1142
  // Note: metadata marking is now handled during loadExtraFiles processing
1070
1143
  finalVariant = _extends(_extends({}, variant), {}, {
1071
1144
  source: mainFileResult.source,
@@ -1,5 +1,10 @@
1
1
  import type { LoaderContext } from 'webpack';
2
2
  export type LoaderOptions = {
3
+ performance?: {
4
+ logging?: boolean;
5
+ notableMs?: number;
6
+ showWrapperMeasures?: boolean;
7
+ };
3
8
  output?: 'hast' | 'hastJson' | 'hastGzip';
4
9
  };
5
10
  /**
@@ -2,6 +2,9 @@ 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
+ // webpack does not like node: imports
6
+ // eslint-disable-next-line n/prefer-node-protocol
7
+ import path from 'path';
5
8
  import { loadCodeVariant } from "../loadCodeVariant/loadCodeVariant.js";
6
9
  import { createParseSource } from "../parseSource/index.js";
7
10
  // TODO: re-enable following benchmarking
@@ -12,6 +15,9 @@ import { resolveVariantPathsWithFs } from "../loadServerCodeMeta/resolveModulePa
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$loadCodeVarian, 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) {
@@ -116,6 +164,10 @@ function _loadPrecomputedCodeHighlighter() {
116
164
  _yield$loadCodeVarian = _context.v;
117
165
  processedVariant = _yield$loadCodeVarian.code;
118
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
+ }
@@ -47,6 +47,14 @@ export interface WithDocsInfraOptions {
47
47
  additionalTurbopackRules?: Record<string, {
48
48
  loaders: string[];
49
49
  }>;
50
+ /**
51
+ * Performance logging options
52
+ */
53
+ performance?: {
54
+ logging: boolean;
55
+ notableMs?: number;
56
+ showWrapperMeasures?: boolean;
57
+ };
50
58
  /**
51
59
  * Defer AST parsing option for code highlighter output.
52
60
  * 'gzip' - Default, outputs gzipped HAST for best performance.
@@ -40,6 +40,8 @@ export function withDocsInfra() {
40
40
  additionalDemoPatterns = _options$additionalDe === void 0 ? {} : _options$additionalDe,
41
41
  _options$additionalTu = options.additionalTurbopackRules,
42
42
  additionalTurbopackRules = _options$additionalTu === void 0 ? {} : _options$additionalTu,
43
+ _options$performance = options.performance,
44
+ performance = _options$performance === void 0 ? {} : _options$performance,
43
45
  _options$deferCodePar = options.deferCodeParsing,
44
46
  deferCodeParsing = _options$deferCodePar === void 0 ? 'gzip' : _options$deferCodePar;
45
47
  var output = 'hastGzip';
@@ -59,11 +61,17 @@ export function withDocsInfra() {
59
61
  loaders: [{
60
62
  loader: '@mui/internal-docs-infra/pipeline/loadPrecomputedCodeHighlighter',
61
63
  options: {
64
+ performance: performance,
62
65
  output: output
63
66
  }
64
67
  }]
65
68
  }), clientDemoPathPattern, {
66
- loaders: ['@mui/internal-docs-infra/pipeline/loadPrecomputedCodeHighlighterClient']
69
+ loaders: [{
70
+ loader: '@mui/internal-docs-infra/pipeline/loadPrecomputedCodeHighlighterClient',
71
+ options: {
72
+ performance: performance
73
+ }
74
+ }]
67
75
  });
68
76
 
69
77
  // Add additional demo patterns to Turbopack rules
@@ -73,6 +81,7 @@ export function withDocsInfra() {
73
81
  loaders: [{
74
82
  loader: '@mui/internal-docs-infra/pipeline/loadPrecomputedCodeHighlighter',
75
83
  options: {
84
+ performance: performance,
76
85
  output: output
77
86
  }
78
87
  }]
@@ -82,7 +91,12 @@ export function withDocsInfra() {
82
91
  if (additionalDemoPatterns.client) {
83
92
  additionalDemoPatterns.client.forEach(function (pattern) {
84
93
  turbopackRules[pattern] = {
85
- loaders: ['@mui/internal-docs-infra/pipeline/loadPrecomputedCodeHighlighterClient']
94
+ loaders: [{
95
+ loader: '@mui/internal-docs-infra/pipeline/loadPrecomputedCodeHighlighterClient',
96
+ options: {
97
+ performance: performance
98
+ }
99
+ }]
86
100
  };
87
101
  });
88
102
  }
@@ -118,6 +132,7 @@ export function withDocsInfra() {
118
132
  use: [defaultLoaders.babel, {
119
133
  loader: '@mui/internal-docs-infra/pipeline/loadPrecomputedCodeHighlighter',
120
134
  options: {
135
+ performance: performance,
121
136
  output: output
122
137
  }
123
138
  }]
@@ -126,7 +141,12 @@ export function withDocsInfra() {
126
141
  // Client files for live demos - processes externals
127
142
  webpackConfig.module.rules.push({
128
143
  test: new RegExp('/demos/[^/]+/client\\.ts$'),
129
- use: [defaultLoaders.babel, '@mui/internal-docs-infra/pipeline/loadPrecomputedCodeHighlighterClient']
144
+ use: [defaultLoaders.babel, {
145
+ loader: '@mui/internal-docs-infra/pipeline/loadPrecomputedCodeHighlighterClient',
146
+ options: {
147
+ performance: performance
148
+ }
149
+ }]
130
150
  });
131
151
 
132
152
  // Add webpack rules for additional demo patterns
@@ -144,6 +164,7 @@ export function withDocsInfra() {
144
164
  use: [defaultLoaders.babel, {
145
165
  loader: '@mui/internal-docs-infra/pipeline/loadPrecomputedCodeHighlighter',
146
166
  options: {
167
+ performance: performance,
147
168
  output: output
148
169
  }
149
170
  }]
@@ -161,7 +182,12 @@ export function withDocsInfra() {
161
182
 
162
183
  webpackConfig.module.rules.push({
163
184
  test: new RegExp("".concat(regexPattern, "$")),
164
- use: [defaultLoaders.babel, '@mui/internal-docs-infra/pipeline/loadPrecomputedCodeHighlighterClient']
185
+ use: [defaultLoaders.babel, {
186
+ loader: '@mui/internal-docs-infra/pipeline/loadPrecomputedCodeHighlighterClient',
187
+ options: {
188
+ performance: performance
189
+ }
190
+ }]
165
191
  });
166
192
  });
167
193
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/internal-docs-infra",
3
- "version": "0.2.3-canary.13",
3
+ "version": "0.2.3-canary.14",
4
4
  "author": "MUI Team",
5
5
  "description": "MUI Infra - internal documentation creation tools.",
6
6
  "keywords": [
@@ -235,5 +235,5 @@
235
235
  },
236
236
  "./esm": null
237
237
  },
238
- "gitSha": "8b1850f1e23152917fcc1e97d123805cd99d6a31"
238
+ "gitSha": "8e64ec558ea98ce0a577b4b11cd8ffd78de4f0a3"
239
239
  }