@rspack/core 0.0.0-01dbf86423-20221210100716

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