@rspack/core 0.2.5 → 0.2.6

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 (50) hide show
  1. package/dist/compilation.d.ts +3 -0
  2. package/dist/compilation.d.ts.map +1 -1
  3. package/dist/compilation.js +8 -0
  4. package/dist/compilation.js.map +1 -1
  5. package/dist/compiler.d.ts.map +1 -1
  6. package/dist/compiler.js +2 -0
  7. package/dist/compiler.js.map +1 -1
  8. package/dist/config/adapter-rule-use.d.ts +2 -2
  9. package/dist/config/adapter-rule-use.d.ts.map +1 -1
  10. package/dist/config/adapter-rule-use.js.map +1 -1
  11. package/dist/config/adapter.d.ts.map +1 -1
  12. package/dist/config/adapter.js +17 -1
  13. package/dist/config/adapter.js.map +1 -1
  14. package/dist/config/defaults.d.ts.map +1 -1
  15. package/dist/config/defaults.js +7 -4
  16. package/dist/config/defaults.js.map +1 -1
  17. package/dist/config/types.d.ts +4 -1
  18. package/dist/config/types.d.ts.map +1 -1
  19. package/dist/lib/BannerPlugin.js +1 -1
  20. package/dist/lib/BannerPlugin.js.map +1 -1
  21. package/dist/multiStats.d.ts +2 -1
  22. package/dist/multiStats.d.ts.map +1 -1
  23. package/dist/multiStats.js.map +1 -1
  24. package/dist/rspackOptionsApply.d.ts.map +1 -1
  25. package/dist/rspackOptionsApply.js +2 -0
  26. package/dist/rspackOptionsApply.js.map +1 -1
  27. package/dist/stats/DefaultStatsFactoryPlugin.d.ts +38 -0
  28. package/dist/stats/DefaultStatsFactoryPlugin.d.ts.map +1 -0
  29. package/dist/stats/DefaultStatsFactoryPlugin.js +3 -0
  30. package/dist/stats/DefaultStatsFactoryPlugin.js.map +1 -0
  31. package/dist/stats/DefaultStatsPrinterPlugin.d.ts +14 -0
  32. package/dist/stats/DefaultStatsPrinterPlugin.d.ts.map +1 -0
  33. package/dist/stats/DefaultStatsPrinterPlugin.js +1041 -0
  34. package/dist/stats/DefaultStatsPrinterPlugin.js.map +1 -0
  35. package/dist/stats/StatsPrinter.d.ts +58 -0
  36. package/dist/stats/StatsPrinter.d.ts.map +1 -0
  37. package/dist/stats/StatsPrinter.js +146 -0
  38. package/dist/stats/StatsPrinter.js.map +1 -0
  39. package/dist/stats.d.ts +2 -35
  40. package/dist/stats.d.ts.map +1 -1
  41. package/dist/stats.js +9 -749
  42. package/dist/stats.js.map +1 -1
  43. package/dist/util/SizeFormatHelpers.d.ts +11 -0
  44. package/dist/util/SizeFormatHelpers.d.ts.map +1 -0
  45. package/dist/util/SizeFormatHelpers.js +25 -0
  46. package/dist/util/SizeFormatHelpers.js.map +1 -0
  47. package/dist/util/index.d.ts.map +1 -1
  48. package/dist/util/index.js +1 -0
  49. package/dist/util/index.js.map +1 -1
  50. package/package.json +8 -8
package/dist/stats.js CHANGED
@@ -12,8 +12,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
12
12
  };
13
13
  var _Stats_inner;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.normalizeStatsPreset = exports.optionsOrFallback = exports.Stats = void 0;
16
- const Logger_1 = require("./logging/Logger");
15
+ exports.normalizeStatsPreset = exports.Stats = void 0;
17
16
  class Stats {
18
17
  constructor(compilation) {
19
18
  _Stats_inner.set(this, void 0);
@@ -38,6 +37,11 @@ class Stats {
38
37
  if (options.hash) {
39
38
  obj.hash = __classPrivateFieldGet(this, _Stats_inner, "f").getHash();
40
39
  }
40
+ if (options.version) {
41
+ const { version, webpackVersion } = require("../package.json");
42
+ obj.version = webpackVersion;
43
+ obj.rspackVersion = version;
44
+ }
41
45
  if (options.timings) {
42
46
  obj.time = this.compilation.endTime - this.compilation.startTime;
43
47
  }
@@ -102,758 +106,14 @@ class Stats {
102
106
  const options = this.compilation.createStatsOptions(opts, {
103
107
  forToString: true
104
108
  });
105
- const useColors = (0, exports.optionsOrFallback)(options.colors, false);
106
109
  const obj = this.toJson(options, true);
107
- return Stats.jsonToString(obj, useColors);
108
- }
109
- static jsonToString(obj, useColors) {
110
- var _a, _b, _c;
111
- const buf = [];
112
- const defaultColors = {
113
- bold: "\u001b[1m",
114
- yellow: "\u001b[1m\u001b[33m",
115
- red: "\u001b[1m\u001b[31m",
116
- green: "\u001b[1m\u001b[32m",
117
- cyan: "\u001b[1m\u001b[36m",
118
- magenta: "\u001b[1m\u001b[35m"
119
- };
120
- const colors = Object.keys(defaultColors).reduce((obj, color) => {
121
- // @ts-expect-error
122
- obj[color] = str => {
123
- if (useColors) {
124
- buf.push(useColors === true || useColors[color] === undefined
125
- ? // @ts-expect-error
126
- defaultColors[color]
127
- : useColors[color]);
128
- }
129
- buf.push(str);
130
- if (useColors) {
131
- buf.push("\u001b[39m\u001b[22m");
132
- }
133
- };
134
- return obj;
135
- }, {
136
- // @ts-expect-error
137
- normal: str => buf.push(str)
138
- });
139
- const coloredTime = (time) => {
140
- let times = [800, 400, 200, 100];
141
- if (obj.time) {
142
- times = [obj.time / 2, obj.time / 4, obj.time / 8, obj.time / 16];
143
- }
144
- if (time < times[3])
145
- colors.normal(`${time}ms`);
146
- else if (time < times[2])
147
- colors.bold(`${time}ms`);
148
- else if (time < times[1])
149
- colors.green(`${time}ms`);
150
- else if (time < times[0])
151
- colors.yellow(`${time}ms`);
152
- else
153
- colors.red(`${time}ms`);
154
- };
155
- const newline = () => buf.push("\n");
156
- const getText = (arr, row, col) => {
157
- return arr[row][col].value;
158
- };
159
- const table = (array, align, splitter) => {
160
- const rows = array.length;
161
- const cols = array[0].length;
162
- const colSizes = new Array(cols);
163
- for (let col = 0; col < cols; col++) {
164
- colSizes[col] = 0;
165
- }
166
- for (let row = 0; row < rows; row++) {
167
- for (let col = 0; col < cols; col++) {
168
- // @ts-expect-error
169
- const value = `${getText(array, row, col)}`;
170
- if (value.length > colSizes[col]) {
171
- colSizes[col] = value.length;
172
- }
173
- }
174
- }
175
- for (let row = 0; row < rows; row++) {
176
- for (let col = 0; col < cols; col++) {
177
- const format = array[row][col].color;
178
- // @ts-expect-error
179
- const value = `${getText(array, row, col)}`;
180
- let l = value.length;
181
- if (align[col] === "l") {
182
- format(value);
183
- }
184
- for (; l < colSizes[col] && col !== cols - 1; l++) {
185
- colors.normal(" ");
186
- }
187
- if (align[col] === "r") {
188
- format(value);
189
- }
190
- if (col + 1 < cols && colSizes[col] !== 0) {
191
- colors.normal(splitter || " ");
192
- }
193
- }
194
- newline();
195
- }
196
- };
197
- const getAssetColor = (asset, defaultColor) => {
198
- if (asset.isOverSizeLimit) {
199
- return colors.yellow;
200
- }
201
- return defaultColor;
202
- };
203
- if (obj.hash) {
204
- colors.normal("Hash: ");
205
- colors.bold(obj.hash);
206
- newline();
207
- }
208
- if (obj.version) {
209
- colors.normal("Version: rspack ");
210
- colors.bold(obj.version);
211
- newline();
212
- }
213
- if (typeof obj.time === "number") {
214
- colors.normal("Time: ");
215
- colors.bold(obj.time);
216
- colors.normal("ms");
217
- newline();
218
- }
219
- if (typeof obj.builtAt === "number") {
220
- const builtAtDate = new Date(obj.builtAt);
221
- let timeZone = undefined;
222
- try {
223
- builtAtDate.toLocaleTimeString();
224
- }
225
- catch (err) {
226
- // Force UTC if runtime timezone is unsupported
227
- timeZone = "UTC";
228
- }
229
- colors.normal("Built at: ");
230
- colors.normal(builtAtDate.toLocaleDateString(undefined, {
231
- day: "2-digit",
232
- month: "2-digit",
233
- year: "numeric",
234
- timeZone
235
- }));
236
- colors.normal(" ");
237
- colors.bold(builtAtDate.toLocaleTimeString(undefined, { timeZone }));
238
- newline();
239
- }
240
- if (obj.env) {
241
- colors.normal("Environment (--env): ");
242
- colors.bold(JSON.stringify(obj.env, null, 2));
243
- newline();
244
- }
245
- if (obj.publicPath) {
246
- colors.normal("PublicPath: ");
247
- colors.bold(obj.publicPath);
248
- newline();
249
- }
250
- if (obj.assets && obj.assets.length > 0) {
251
- const t = [
252
- [
253
- {
254
- value: "Asset",
255
- color: colors.bold
256
- },
257
- {
258
- value: "Size",
259
- color: colors.bold
260
- },
261
- {
262
- value: "Chunks",
263
- color: colors.bold
264
- },
265
- {
266
- value: "",
267
- color: colors.bold
268
- },
269
- {
270
- value: "",
271
- color: colors.bold
272
- },
273
- {
274
- value: "Chunk Names",
275
- color: colors.bold
276
- }
277
- ]
278
- ];
279
- for (const asset of obj.assets) {
280
- t.push([
281
- {
282
- value: asset.name,
283
- color: getAssetColor(asset, colors.green)
284
- },
285
- {
286
- value: SizeFormatHelpers.formatSize(asset.size),
287
- color: getAssetColor(asset, colors.normal)
288
- },
289
- {
290
- value: asset.chunks.join(", "),
291
- color: colors.bold
292
- },
293
- {
294
- value: [
295
- asset.emitted && "[emitted]",
296
- ((_a = asset.info) === null || _a === void 0 ? void 0 : _a.immutable) && "[immutable]",
297
- ((_b = asset.info) === null || _b === void 0 ? void 0 : _b.development) && "[dev]",
298
- ((_c = asset.info) === null || _c === void 0 ? void 0 : _c.hotModuleReplacement) && "[hmr]"
299
- ]
300
- .filter(Boolean)
301
- .join(" "),
302
- color: colors.green
303
- },
304
- {
305
- value: asset.isOverSizeLimit ? "[big]" : "",
306
- color: getAssetColor(asset, colors.normal)
307
- },
308
- {
309
- value: asset.chunkNames.join(", "),
310
- color: colors.normal
311
- }
312
- ]);
313
- }
314
- table(t, "rrrlll");
315
- }
316
- if (obj.filteredAssets > 0) {
317
- colors.normal(" ");
318
- if (obj.assets.length > 0)
319
- colors.normal("+ ");
320
- colors.normal(obj.filteredAssets);
321
- if (obj.assets.length > 0)
322
- colors.normal(" hidden");
323
- colors.normal(obj.filteredAssets !== 1 ? " assets" : " asset");
324
- newline();
325
- }
326
- const processChunkGroups = (namedGroups, prefix) => {
327
- for (const name of Object.keys(namedGroups)) {
328
- const cg = namedGroups[name];
329
- colors.normal(`${prefix} `);
330
- colors.bold(name);
331
- if (cg.isOverSizeLimit) {
332
- colors.normal(" ");
333
- colors.yellow("[big]");
334
- }
335
- colors.normal(" =");
336
- for (const asset of cg.assets) {
337
- colors.normal(" ");
338
- colors.green(asset.name);
339
- }
340
- // for (const name of Object.keys(cg.childAssets)) {
341
- // const assets = cg.childAssets[name];
342
- // if (assets && assets.length > 0) {
343
- // colors.normal(" ");
344
- // colors.magenta(`(${name}:`);
345
- // for (const asset of assets) {
346
- // colors.normal(" ");
347
- // colors.green(asset);
348
- // }
349
- // colors.magenta(")");
350
- // }
351
- // }
352
- newline();
353
- }
354
- };
355
- if (obj.entrypoints) {
356
- processChunkGroups(obj.entrypoints, "Entrypoint");
357
- }
358
- if (obj.namedChunkGroups) {
359
- let outputChunkGroups = obj.namedChunkGroups;
360
- if (obj.entrypoints) {
361
- outputChunkGroups = Object.keys(outputChunkGroups)
362
- .filter(name => !obj.entrypoints[name])
363
- .reduce((result, name) => {
364
- // @ts-expect-error
365
- result[name] = obj.namedChunkGroups[name];
366
- return result;
367
- }, {});
368
- }
369
- processChunkGroups(outputChunkGroups, "Chunk Group");
370
- }
371
- const modulesByIdentifier = {};
372
- if (obj.modules) {
373
- for (const module of obj.modules) {
374
- // @ts-expect-error
375
- modulesByIdentifier[`$${module.identifier}`] = module;
376
- }
377
- }
378
- else if (obj.chunks) {
379
- for (const chunk of obj.chunks) {
380
- if (chunk.modules) {
381
- for (const module of chunk.modules) {
382
- // @ts-expect-error
383
- modulesByIdentifier[`$${module.identifier}`] = module;
384
- }
385
- }
386
- }
387
- }
388
- const processModuleAttributes = (module) => {
389
- colors.normal(" ");
390
- colors.normal(SizeFormatHelpers.formatSize(module.size));
391
- if (module.chunks) {
392
- for (const chunk of module.chunks) {
393
- colors.normal(" {");
394
- colors.yellow(chunk);
395
- colors.normal("}");
396
- }
397
- }
398
- if (typeof module.depth === "number") {
399
- colors.normal(` [depth ${module.depth}]`);
400
- }
401
- if (module.cacheable === false) {
402
- colors.red(" [not cacheable]");
403
- }
404
- if (module.optional) {
405
- colors.yellow(" [optional]");
406
- }
407
- if (module.built) {
408
- colors.green(" [built]");
409
- }
410
- if (module.assets && module.assets.length) {
411
- colors.magenta(` [${module.assets.length} asset${module.assets.length === 1 ? "" : "s"}]`);
412
- }
413
- if (module.prefetched) {
414
- colors.magenta(" [prefetched]");
415
- }
416
- if (module.failed)
417
- colors.red(" [failed]");
418
- if (module.warnings) {
419
- colors.yellow(` [${module.warnings} warning${module.warnings === 1 ? "" : "s"}]`);
420
- }
421
- if (module.errors) {
422
- colors.red(` [${module.errors} error${module.errors === 1 ? "" : "s"}]`);
423
- }
424
- };
425
- const processModuleContent = (module, prefix) => {
426
- if (Array.isArray(module.providedExports)) {
427
- colors.normal(prefix);
428
- if (module.providedExports.length === 0) {
429
- colors.cyan("[no exports]");
430
- }
431
- else {
432
- colors.cyan(`[exports: ${module.providedExports.join(", ")}]`);
433
- }
434
- newline();
435
- }
436
- if (module.usedExports !== undefined) {
437
- if (module.usedExports !== true) {
438
- colors.normal(prefix);
439
- if (module.usedExports === null) {
440
- colors.cyan("[used exports unknown]");
441
- }
442
- else if (module.usedExports === false) {
443
- colors.cyan("[no exports used]");
444
- }
445
- else if (Array.isArray(module.usedExports) &&
446
- module.usedExports.length === 0) {
447
- colors.cyan("[no exports used]");
448
- }
449
- else if (Array.isArray(module.usedExports)) {
450
- const providedExportsCount = Array.isArray(module.providedExports)
451
- ? module.providedExports.length
452
- : null;
453
- if (providedExportsCount !== null &&
454
- providedExportsCount === module.usedExports.length) {
455
- colors.cyan("[all exports used]");
456
- }
457
- else {
458
- colors.cyan(`[only some exports used: ${module.usedExports.join(", ")}]`);
459
- }
460
- }
461
- newline();
462
- }
463
- }
464
- if (Array.isArray(module.optimizationBailout)) {
465
- for (const item of module.optimizationBailout) {
466
- colors.normal(prefix);
467
- colors.yellow(item);
468
- newline();
469
- }
470
- }
471
- if (module.reasons) {
472
- for (const reason of module.reasons) {
473
- colors.normal(prefix);
474
- if (reason.type) {
475
- colors.normal(reason.type);
476
- colors.normal(" ");
477
- }
478
- if (reason.userRequest) {
479
- colors.cyan(reason.userRequest);
480
- colors.normal(" ");
481
- }
482
- if (reason.moduleId) {
483
- colors.normal("[");
484
- colors.normal(reason.moduleId);
485
- colors.normal("]");
486
- }
487
- if (reason.module && reason.module !== reason.moduleId) {
488
- colors.normal(" ");
489
- colors.magenta(reason.module);
490
- }
491
- if (reason.loc) {
492
- colors.normal(" ");
493
- colors.normal(reason.loc);
494
- }
495
- if (reason.explanation) {
496
- colors.normal(" ");
497
- colors.cyan(reason.explanation);
498
- }
499
- newline();
500
- }
501
- }
502
- if (module.profile) {
503
- colors.normal(prefix);
504
- let sum = 0;
505
- if (module.issuerPath) {
506
- for (const m of module.issuerPath) {
507
- colors.normal("[");
508
- colors.normal(m.id);
509
- colors.normal("] ");
510
- if (m.profile) {
511
- const time = (m.profile.factory || 0) + (m.profile.building || 0);
512
- coloredTime(time);
513
- sum += time;
514
- colors.normal(" ");
515
- }
516
- colors.normal("-> ");
517
- }
518
- }
519
- for (const key of Object.keys(module.profile)) {
520
- colors.normal(`${key}:`);
521
- const time = module.profile[key];
522
- coloredTime(time);
523
- colors.normal(" ");
524
- sum += time;
525
- }
526
- colors.normal("= ");
527
- coloredTime(sum);
528
- newline();
529
- }
530
- if (module.modules) {
531
- // @ts-expect-error
532
- processModulesList(module, prefix + "| ");
533
- }
534
- };
535
- const processModulesList = (obj, prefix) => {
536
- if (obj.modules) {
537
- let maxModuleId = 0;
538
- for (const module of obj.modules) {
539
- if (typeof module.id === "number") {
540
- if (maxModuleId < module.id)
541
- maxModuleId = module.id;
542
- }
543
- }
544
- let contentPrefix = prefix + " ";
545
- if (maxModuleId >= 10)
546
- contentPrefix += " ";
547
- if (maxModuleId >= 100)
548
- contentPrefix += " ";
549
- if (maxModuleId >= 1000)
550
- contentPrefix += " ";
551
- for (const module of obj.modules) {
552
- colors.normal(prefix);
553
- const name = module.name || module.identifier;
554
- if (typeof module.id === "string" || typeof module.id === "number") {
555
- if (typeof module.id === "number") {
556
- if (module.id < 1000 && maxModuleId >= 1000)
557
- colors.normal(" ");
558
- if (module.id < 100 && maxModuleId >= 100)
559
- colors.normal(" ");
560
- if (module.id < 10 && maxModuleId >= 10)
561
- colors.normal(" ");
562
- }
563
- else {
564
- if (maxModuleId >= 1000)
565
- colors.normal(" ");
566
- if (maxModuleId >= 100)
567
- colors.normal(" ");
568
- if (maxModuleId >= 10)
569
- colors.normal(" ");
570
- }
571
- if (name !== module.id) {
572
- colors.normal("[");
573
- colors.normal(module.id);
574
- colors.normal("]");
575
- colors.normal(" ");
576
- }
577
- else {
578
- colors.normal("[");
579
- colors.bold(module.id);
580
- colors.normal("]");
581
- }
582
- }
583
- if (name !== module.id) {
584
- colors.bold(name);
585
- }
586
- processModuleAttributes(module);
587
- newline();
588
- processModuleContent(module, contentPrefix);
589
- }
590
- if (obj.filteredModules > 0) {
591
- colors.normal(prefix);
592
- colors.normal(" ");
593
- if (obj.modules.length > 0)
594
- colors.normal(" + ");
595
- colors.normal(obj.filteredModules);
596
- if (obj.modules.length > 0)
597
- colors.normal(" hidden");
598
- colors.normal(obj.filteredModules !== 1 ? " modules" : " module");
599
- newline();
600
- }
601
- }
602
- };
603
- if (obj.chunks) {
604
- for (const chunk of obj.chunks) {
605
- colors.normal("chunk ");
606
- if (chunk.id < 1000)
607
- colors.normal(" ");
608
- if (chunk.id < 100)
609
- colors.normal(" ");
610
- if (chunk.id < 10)
611
- colors.normal(" ");
612
- colors.normal("{");
613
- colors.yellow(chunk.id);
614
- colors.normal("} ");
615
- colors.green(chunk.files.join(", "));
616
- if (chunk.names && chunk.names.length > 0) {
617
- colors.normal(" (");
618
- colors.normal(chunk.names.join(", "));
619
- colors.normal(")");
620
- }
621
- colors.normal(" ");
622
- colors.normal(SizeFormatHelpers.formatSize(chunk.size));
623
- // TODO: stats chunk relation
624
- // for (const id of chunk.parents) {
625
- // colors.normal(" <{");
626
- // colors.yellow(id);
627
- // colors.normal("}>");
628
- // }
629
- // for (const id of chunk.siblings) {
630
- // colors.normal(" ={");
631
- // colors.yellow(id);
632
- // colors.normal("}=");
633
- // }
634
- // for (const id of chunk.children) {
635
- // colors.normal(" >{");
636
- // colors.yellow(id);
637
- // colors.normal("}<");
638
- // }
639
- if (chunk.childrenByOrder) {
640
- for (const name of Object.keys(chunk.childrenByOrder)) {
641
- const children = chunk.childrenByOrder[name];
642
- colors.normal(" ");
643
- colors.magenta(`(${name}:`);
644
- for (const id of children) {
645
- colors.normal(" {");
646
- colors.yellow(id);
647
- colors.normal("}");
648
- }
649
- colors.magenta(")");
650
- }
651
- }
652
- if (chunk.entry) {
653
- colors.yellow(" [entry]");
654
- }
655
- else if (chunk.initial) {
656
- colors.yellow(" [initial]");
657
- }
658
- if (chunk.rendered) {
659
- colors.green(" [rendered]");
660
- }
661
- if (chunk.recorded) {
662
- colors.green(" [recorded]");
663
- }
664
- if (chunk.reason) {
665
- colors.yellow(` ${chunk.reason}`);
666
- }
667
- newline();
668
- if (chunk.origins) {
669
- for (const origin of chunk.origins) {
670
- colors.normal(" > ");
671
- if (origin.reasons && origin.reasons.length) {
672
- colors.yellow(origin.reasons.join(" "));
673
- colors.normal(" ");
674
- }
675
- if (origin.request) {
676
- colors.normal(origin.request);
677
- colors.normal(" ");
678
- }
679
- if (origin.module) {
680
- colors.normal("[");
681
- colors.normal(origin.moduleId);
682
- colors.normal("] ");
683
- // @ts-expect-error
684
- const module = modulesByIdentifier[`$${origin.module}`];
685
- if (module) {
686
- colors.bold(module.name);
687
- colors.normal(" ");
688
- }
689
- }
690
- if (origin.loc) {
691
- colors.normal(origin.loc);
692
- }
693
- newline();
694
- }
695
- }
696
- processModulesList(chunk, " ");
697
- }
698
- }
699
- processModulesList(obj, "");
700
- if (obj.logging) {
701
- for (const origin of Object.keys(obj.logging)) {
702
- const logData = obj.logging[origin];
703
- if (logData.entries.length > 0) {
704
- newline();
705
- if (logData.debug) {
706
- colors.red("DEBUG ");
707
- }
708
- colors.bold("LOG from " + origin);
709
- newline();
710
- let indent = "";
711
- for (const entry of logData.entries) {
712
- let color = colors.normal;
713
- let prefix = " ";
714
- switch (entry.type) {
715
- case Logger_1.LogType.clear:
716
- colors.normal(`${indent}-------`);
717
- newline();
718
- continue;
719
- case Logger_1.LogType.error:
720
- color = colors.red;
721
- prefix = "<e> ";
722
- break;
723
- case Logger_1.LogType.warn:
724
- color = colors.yellow;
725
- prefix = "<w> ";
726
- break;
727
- case Logger_1.LogType.info:
728
- color = colors.green;
729
- prefix = "<i> ";
730
- break;
731
- case Logger_1.LogType.log:
732
- color = colors.bold;
733
- break;
734
- case Logger_1.LogType.trace:
735
- case Logger_1.LogType.debug:
736
- color = colors.normal;
737
- break;
738
- case Logger_1.LogType.status:
739
- color = colors.magenta;
740
- prefix = "<s> ";
741
- break;
742
- case Logger_1.LogType.profile:
743
- color = colors.magenta;
744
- prefix = "<p> ";
745
- break;
746
- case Logger_1.LogType.profileEnd:
747
- color = colors.magenta;
748
- prefix = "</p> ";
749
- break;
750
- case Logger_1.LogType.time:
751
- color = colors.magenta;
752
- prefix = "<t> ";
753
- break;
754
- case Logger_1.LogType.group:
755
- color = colors.cyan;
756
- prefix = "<-> ";
757
- break;
758
- case Logger_1.LogType.groupCollapsed:
759
- color = colors.cyan;
760
- prefix = "<+> ";
761
- break;
762
- case Logger_1.LogType.groupEnd:
763
- if (indent.length >= 2)
764
- indent = indent.slice(0, indent.length - 2);
765
- continue;
766
- }
767
- if (entry.message) {
768
- for (const line of entry.message.split("\n")) {
769
- colors.normal(`${indent}${prefix}`);
770
- color(line);
771
- newline();
772
- }
773
- }
774
- if (entry.trace) {
775
- for (const line of entry.trace) {
776
- colors.normal(`${indent}| ${line}`);
777
- newline();
778
- }
779
- }
780
- switch (entry.type) {
781
- case Logger_1.LogType.group:
782
- indent += " ";
783
- break;
784
- }
785
- }
786
- if (logData.filteredEntries) {
787
- colors.normal(`+ ${logData.filteredEntries} hidden lines`);
788
- newline();
789
- }
790
- }
791
- }
792
- }
793
- if (obj.warnings) {
794
- for (const warning of obj.warnings) {
795
- newline();
796
- // formatted warning already have color.
797
- colors.normal(formatError(warning));
798
- newline();
799
- }
800
- }
801
- if (obj.errors) {
802
- for (const error of obj.errors) {
803
- newline();
804
- // formatted error already have color.
805
- colors.normal(formatError(error));
806
- newline();
807
- }
808
- }
809
- if (obj.children) {
810
- for (const child of obj.children) {
811
- const childString = Stats.jsonToString(child, useColors);
812
- if (childString) {
813
- if (child.name) {
814
- colors.normal("Child ");
815
- colors.bold(child.name);
816
- colors.normal(":");
817
- }
818
- else {
819
- colors.normal("Child");
820
- }
821
- newline();
822
- buf.push(" ");
823
- buf.push(childString.replace(/\n/g, "\n "));
824
- newline();
825
- }
826
- }
827
- }
828
- if (obj.needAdditionalPass) {
829
- colors.yellow("Compilation needs an additional pass and will compile again.");
830
- }
831
- while (buf[buf.length - 1] === "\n") {
832
- buf.pop();
833
- }
834
- return buf.join("");
110
+ const statsPrinter = this.compilation.createStatsPrinter(options);
111
+ const result = statsPrinter.print("compilation", obj);
112
+ return result === undefined ? "" : result;
835
113
  }
836
114
  }
837
115
  exports.Stats = Stats;
838
116
  _Stats_inner = new WeakMap();
839
- const SizeFormatHelpers = {
840
- formatSize: (size) => {
841
- if (typeof size !== "number" || Number.isNaN(size) === true) {
842
- return "unknown size";
843
- }
844
- if (size <= 0) {
845
- return "0 bytes";
846
- }
847
- const abbreviations = ["bytes", "KiB", "MiB", "GiB"];
848
- const index = Math.floor(Math.log(size) / Math.log(1024));
849
- return `${+(size / Math.pow(1024, index)).toPrecision(3)} ${abbreviations[index]}`;
850
- }
851
- };
852
- const formatError = (e) => {
853
- return e.formatted;
854
- };
855
- const optionsOrFallback = (options, fallback) => options !== null && options !== void 0 ? options : fallback;
856
- exports.optionsOrFallback = optionsOrFallback;
857
117
  function normalizeStatsPreset(options) {
858
118
  if (typeof options === "boolean" || typeof options === "string")
859
119
  return presetToOptions(options);