@rspack/core 0.0.0-1bce45e7c0-20221109113710

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