@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
@@ -0,0 +1,1041 @@
1
+ "use strict";
2
+ /**
3
+ * The following code is modified based on
4
+ * https://github.com/webpack/webpack/tree/4b4ca3bb53f36a5b8fc6bc1bd976ed7af161bd80/lib/stats
5
+ *
6
+ * MIT Licensed
7
+ * Author Tobias Koppers @sokra
8
+ * Copyright (c) JS Foundation and other contributors
9
+ * https://github.com/webpack/webpack/blob/main/LICENSE
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.DefaultStatsPrinterPlugin = void 0;
13
+ const SizeFormatHelpers_1 = require("../util/SizeFormatHelpers");
14
+ const DATA_URI_CONTENT_LENGTH = 16;
15
+ const plural = (n, singular, plural) => n === 1 ? singular : plural;
16
+ const printSizes = (sizes, { formatSize = (n) => `${n}` }) => {
17
+ const keys = Object.keys(sizes);
18
+ if (keys.length > 1) {
19
+ return keys.map(key => `${formatSize(sizes[key])} (${key})`).join(" ");
20
+ }
21
+ else if (keys.length === 1) {
22
+ return formatSize(sizes[keys[0]]);
23
+ }
24
+ };
25
+ const getResourceName = (resource) => {
26
+ const dataUrl = /^data:[^,]+,/.exec(resource);
27
+ if (!dataUrl)
28
+ return resource;
29
+ const len = dataUrl[0].length + DATA_URI_CONTENT_LENGTH;
30
+ if (resource.length < len)
31
+ return resource;
32
+ return `${resource.slice(0, Math.min(resource.length - /* '..'.length */ 2, len))}..`;
33
+ };
34
+ const getModuleName = (name) => {
35
+ const [, prefix, resource] = /^(.*!)?([^!]*)$/.exec(name) || [];
36
+ return [prefix, getResourceName(resource)];
37
+ };
38
+ const mapLines = (str, fn) => str.split("\n").map(fn).join("\n");
39
+ const twoDigit = (n) => (n >= 10 ? `${n}` : `0${n}`);
40
+ const isValidId = (id) => {
41
+ return typeof id === "number" || id;
42
+ };
43
+ const moreCount = (list, count) => {
44
+ return list && list.length > 0 ? `+ ${count}` : `${count}`;
45
+ };
46
+ const SIMPLE_PRINTERS = {
47
+ "compilation.summary!": (_, { type, bold, green, red, yellow, formatDateTime, formatTime, compilation: { name, hash, rspackVersion, time, builtAt, errorsCount, warningsCount } }) => {
48
+ const root = type === "compilation.summary!";
49
+ const warningsMessage = warningsCount && warningsCount > 0
50
+ ? yellow(`${warningsCount} ${plural(warningsCount, "warning", "warnings")}`)
51
+ : "";
52
+ const errorsMessage = errorsCount && errorsCount > 0
53
+ ? red(`${errorsCount} ${plural(errorsCount, "error", "errors")}`)
54
+ : "";
55
+ const timeMessage = root && time ? ` in ${formatTime(time)}` : "";
56
+ const hashMessage = hash ? ` (${hash})` : "";
57
+ const builtAtMessage = root && builtAt ? `${formatDateTime(builtAt)}: ` : "";
58
+ const versionMessage = root && rspackVersion ? `rspack ${rspackVersion}` : "";
59
+ const nameMessage = root && name
60
+ ? bold(name)
61
+ : name
62
+ ? `Child ${bold(name)}`
63
+ : root
64
+ ? ""
65
+ : "Child";
66
+ const subjectMessage = nameMessage && versionMessage
67
+ ? `${nameMessage} (${versionMessage})`
68
+ : versionMessage || nameMessage || "rspack";
69
+ let statusMessage;
70
+ if (errorsMessage && warningsMessage) {
71
+ statusMessage = `compiled with ${errorsMessage} and ${warningsMessage}`;
72
+ }
73
+ else if (errorsMessage) {
74
+ statusMessage = `compiled with ${errorsMessage}`;
75
+ }
76
+ else if (warningsMessage) {
77
+ statusMessage = `compiled with ${warningsMessage}`;
78
+ }
79
+ else if (errorsCount === 0 && warningsCount === 0) {
80
+ statusMessage = `compiled ${green("successfully")}`;
81
+ }
82
+ else {
83
+ statusMessage = `compiled`;
84
+ }
85
+ if (builtAtMessage ||
86
+ versionMessage ||
87
+ errorsMessage ||
88
+ warningsMessage ||
89
+ (errorsCount === 0 && warningsCount === 0) ||
90
+ timeMessage ||
91
+ hashMessage)
92
+ return `${builtAtMessage}${subjectMessage} ${statusMessage}${timeMessage}${hashMessage}`;
93
+ },
94
+ "compilation.filteredWarningDetailsCount": count => count
95
+ ? `${count} ${plural(count, "warning has", "warnings have")} detailed information that is not shown.\nUse 'stats.errorDetails: true' resp. '--stats-error-details' to show it.`
96
+ : undefined,
97
+ "compilation.filteredErrorDetailsCount": (count, { yellow }) => count
98
+ ? yellow(`${count} ${plural(count, "error has", "errors have")} detailed information that is not shown.\nUse 'stats.errorDetails: true' resp. '--stats-error-details' to show it.`)
99
+ : undefined,
100
+ "compilation.env": (env, { bold }) => env
101
+ ? `Environment (--env): ${bold(JSON.stringify(env, null, 2))}`
102
+ : undefined,
103
+ "compilation.publicPath": (publicPath, { bold }) => `PublicPath: ${bold(publicPath || "(none)")}`,
104
+ "compilation.entrypoints": (entrypoints, context, printer) => Array.isArray(entrypoints)
105
+ ? undefined
106
+ : printer.print(context.type, Object.values(entrypoints), {
107
+ ...context,
108
+ chunkGroupKind: "Entrypoint"
109
+ }),
110
+ "compilation.namedChunkGroups": (namedChunkGroups, context, printer) => {
111
+ if (!Array.isArray(namedChunkGroups)) {
112
+ const { compilation: { entrypoints } } = context;
113
+ let chunkGroups = Object.values(namedChunkGroups);
114
+ if (entrypoints) {
115
+ chunkGroups = chunkGroups.filter(group => !Object.prototype.hasOwnProperty.call(entrypoints, group.name));
116
+ }
117
+ return printer.print(context.type, chunkGroups, {
118
+ ...context,
119
+ chunkGroupKind: "Chunk Group"
120
+ });
121
+ }
122
+ },
123
+ "compilation.assetsByChunkName": () => "",
124
+ "compilation.filteredModules": (filteredModules, { compilation: { modules } }) => filteredModules > 0
125
+ ? `${moreCount(modules, filteredModules)} ${plural(filteredModules, "module", "modules")}`
126
+ : undefined,
127
+ "compilation.filteredAssets": (filteredAssets, { compilation: { assets } }) => filteredAssets > 0
128
+ ? `${moreCount(assets, filteredAssets)} ${plural(filteredAssets, "asset", "assets")}`
129
+ : undefined,
130
+ // "compilation.logging": (logging, context, printer) =>
131
+ // Array.isArray(logging)
132
+ // ? undefined
133
+ // : printer.print(
134
+ // context.type,
135
+ // Object.entries(logging).map(([name, value]) => ({ ...value, name })),
136
+ // context
137
+ // ),
138
+ "compilation.warningsInChildren!": (_, { yellow, compilation }) => {
139
+ if (!compilation.children &&
140
+ compilation.warningsCount &&
141
+ compilation.warningsCount > 0 &&
142
+ compilation.warnings) {
143
+ const childWarnings = compilation.warningsCount - compilation.warnings.length;
144
+ if (childWarnings > 0) {
145
+ return yellow(`${childWarnings} ${plural(childWarnings, "WARNING", "WARNINGS")} in child compilations${compilation.children
146
+ ? ""
147
+ : " (Use 'stats.children: true' resp. '--stats-children' for more details)"}`);
148
+ }
149
+ }
150
+ },
151
+ "compilation.errorsInChildren!": (_, { red, compilation }) => {
152
+ if (!compilation.children &&
153
+ compilation.errorsCount &&
154
+ compilation.errorsCount > 0 &&
155
+ compilation.errors) {
156
+ const childErrors = compilation.errorsCount - compilation.errors.length;
157
+ if (childErrors > 0) {
158
+ return red(`${childErrors} ${plural(childErrors, "ERROR", "ERRORS")} in child compilations${compilation.children
159
+ ? ""
160
+ : " (Use 'stats.children: true' resp. '--stats-children' for more details)"}`);
161
+ }
162
+ }
163
+ },
164
+ "asset.type": type => type,
165
+ "asset.name": (name, { formatFilename, asset: { isOverSizeLimit } }) => formatFilename(name, isOverSizeLimit),
166
+ "asset.size": (size, { asset: { isOverSizeLimit }, yellow, green, formatSize }) => (isOverSizeLimit ? yellow(formatSize(size)) : formatSize(size)),
167
+ "asset.emitted": (emitted, { green, formatFlag }) => emitted ? green(formatFlag("emitted")) : undefined,
168
+ "asset.comparedForEmit": (comparedForEmit, { yellow, formatFlag }) => comparedForEmit ? yellow(formatFlag("compared for emit")) : undefined,
169
+ "asset.cached": (cached, { green, formatFlag }) => cached ? green(formatFlag("cached")) : undefined,
170
+ "asset.isOverSizeLimit": (isOverSizeLimit, { yellow, formatFlag }) => isOverSizeLimit ? yellow === null || yellow === void 0 ? void 0 : yellow(formatFlag("big")) : undefined,
171
+ "asset.info.immutable": (immutable, { green, formatFlag }) => immutable ? green(formatFlag("immutable")) : undefined,
172
+ "asset.info.javascriptModule": (javascriptModule, { formatFlag }) => javascriptModule ? formatFlag("javascript module") : undefined,
173
+ "asset.info.sourceFilename": (sourceFilename, { formatFlag }) => sourceFilename
174
+ ? formatFlag(sourceFilename === true
175
+ ? "from source file"
176
+ : `from: ${sourceFilename}`)
177
+ : undefined,
178
+ "asset.info.development": (development, { green, formatFlag }) => development ? green(formatFlag("dev")) : undefined,
179
+ "asset.info.hotModuleReplacement": (hotModuleReplacement, { green, formatFlag }) => (hotModuleReplacement ? green(formatFlag("hmr")) : undefined),
180
+ "asset.separator!": () => "\n",
181
+ "asset.filteredRelated": (filteredRelated, { asset: { related } }) => filteredRelated > 0
182
+ ? `${moreCount(related, filteredRelated)} related ${plural(filteredRelated, "asset", "assets")}`
183
+ : undefined,
184
+ "asset.filteredChildren": (filteredChildren, { asset: { children } }) => filteredChildren > 0
185
+ ? `${moreCount(children, filteredChildren)} ${plural(filteredChildren, "asset", "assets")}`
186
+ : undefined,
187
+ assetChunk: (id, { formatChunkId }) => formatChunkId(id),
188
+ assetChunkName: name => name,
189
+ assetChunkIdHint: name => name,
190
+ "module.type": type => (type !== "module" ? type : undefined),
191
+ "module.id": (id, { formatModuleId }) => isValidId(id) ? formatModuleId(id) : undefined,
192
+ "module.name": (name, { bold }) => {
193
+ const [prefix, resource] = getModuleName(name);
194
+ return `${prefix || ""}${bold(resource || "")}`;
195
+ },
196
+ "module.identifier": identifier => undefined,
197
+ "module.layer": (layer, { formatLayer }) => layer ? formatLayer(layer) : undefined,
198
+ "module.sizes": printSizes,
199
+ "module.chunks[]": (id, { formatChunkId }) => formatChunkId(id),
200
+ "module.depth": (depth, { formatFlag }) => depth !== null ? formatFlag(`depth ${depth}`) : undefined,
201
+ "module.cacheable": (cacheable, { formatFlag, red }) => cacheable === false ? red(formatFlag("not cacheable")) : undefined,
202
+ "module.orphan": (orphan, { formatFlag, yellow }) => orphan ? yellow(formatFlag("orphan")) : undefined,
203
+ "module.runtime": (runtime, { formatFlag, yellow }) => runtime ? yellow(formatFlag("runtime")) : undefined,
204
+ "module.optional": (optional, { formatFlag, yellow }) => optional ? yellow(formatFlag("optional")) : undefined,
205
+ "module.dependent": (dependent, { formatFlag, cyan }) => dependent ? cyan(formatFlag("dependent")) : undefined,
206
+ "module.built": (built, { formatFlag, yellow }) => built ? yellow(formatFlag("built")) : undefined,
207
+ "module.codeGenerated": (codeGenerated, { formatFlag, yellow }) => codeGenerated ? yellow(formatFlag("code generated")) : undefined,
208
+ "module.buildTimeExecuted": (buildTimeExecuted, { formatFlag, green }) => buildTimeExecuted ? green(formatFlag("build time executed")) : undefined,
209
+ "module.cached": (cached, { formatFlag, green }) => cached ? green(formatFlag("cached")) : undefined,
210
+ "module.assets": (assets, { formatFlag, magenta }) => assets && assets.length
211
+ ? magenta(formatFlag(`${assets.length} ${plural(assets.length, "asset", "assets")}`))
212
+ : undefined,
213
+ "module.warnings": (warnings, { formatFlag, yellow }) => warnings === true
214
+ ? yellow(formatFlag("warnings"))
215
+ : warnings
216
+ ? yellow(formatFlag(`${warnings} ${plural(warnings, "warning", "warnings")}`))
217
+ : undefined,
218
+ "module.errors": (errors, { formatFlag, red }) => errors === true
219
+ ? red(formatFlag("errors"))
220
+ : errors
221
+ ? red(formatFlag(`${errors} ${plural(errors, "error", "errors")}`))
222
+ : undefined,
223
+ "module.providedExports": (providedExports, { formatFlag, cyan }) => {
224
+ if (Array.isArray(providedExports)) {
225
+ if (providedExports.length === 0)
226
+ return cyan(formatFlag("no exports"));
227
+ return cyan(formatFlag(`exports: ${providedExports.join(", ")}`));
228
+ }
229
+ },
230
+ "module.usedExports": (usedExports, { formatFlag, cyan, module }) => {
231
+ if (usedExports !== true) {
232
+ if (usedExports === null)
233
+ return cyan(formatFlag("used exports unknown"));
234
+ if (usedExports === false)
235
+ return cyan(formatFlag("module unused"));
236
+ if (Array.isArray(usedExports)) {
237
+ if (usedExports.length === 0)
238
+ return cyan(formatFlag("no exports used"));
239
+ const providedExportsCount = Array.isArray(module.providedExports)
240
+ ? module.providedExports.length
241
+ : null;
242
+ if (providedExportsCount !== null &&
243
+ providedExportsCount === usedExports.length) {
244
+ return cyan(formatFlag("all exports used"));
245
+ }
246
+ else {
247
+ return cyan(formatFlag(`only some exports used: ${usedExports.join(", ")}`));
248
+ }
249
+ }
250
+ }
251
+ },
252
+ "module.optimizationBailout[]": (optimizationBailout, { yellow }) => yellow(optimizationBailout),
253
+ "module.issuerPath": (issuerPath, { module }) => module.profile ? undefined : "",
254
+ "module.profile": profile => undefined,
255
+ "module.filteredModules": (filteredModules, { module: { modules } }) => filteredModules > 0
256
+ ? `${moreCount(modules, filteredModules)} nested ${plural(filteredModules, "module", "modules")}`
257
+ : undefined,
258
+ "module.filteredReasons": (filteredReasons, { module: { reasons } }) => filteredReasons > 0
259
+ ? `${moreCount(reasons, filteredReasons)} ${plural(filteredReasons, "reason", "reasons")}`
260
+ : undefined,
261
+ "module.filteredChildren": (filteredChildren, { module: { children } }) => filteredChildren > 0
262
+ ? `${moreCount(children, filteredChildren)} ${plural(filteredChildren, "module", "modules")}`
263
+ : undefined,
264
+ "module.separator!": () => "\n",
265
+ "moduleIssuer.id": (id, { formatModuleId }) => formatModuleId(id),
266
+ "moduleIssuer.profile.total": (value, { formatTime }) => formatTime(value),
267
+ "moduleReason.type": type => type,
268
+ "moduleReason.userRequest": (userRequest, { cyan }) => cyan(getResourceName(userRequest)),
269
+ "moduleReason.moduleId": (moduleId, { formatModuleId }) => isValidId(moduleId) ? formatModuleId(moduleId) : undefined,
270
+ "moduleReason.module": (module, { magenta }) => magenta(module),
271
+ "moduleReason.loc": loc => loc,
272
+ "moduleReason.explanation": (explanation, { cyan }) => cyan(explanation),
273
+ "moduleReason.active": (active, { formatFlag }) => active ? undefined : formatFlag("inactive"),
274
+ "moduleReason.resolvedModule": (module, { magenta }) => magenta(module),
275
+ "moduleReason.filteredChildren": (filteredChildren, { moduleReason: { children } }) => filteredChildren > 0
276
+ ? `${moreCount(children, filteredChildren)} ${plural(filteredChildren, "reason", "reasons")}`
277
+ : undefined,
278
+ "module.profile.total": (value, { formatTime }) => formatTime(value),
279
+ "module.profile.resolving": (value, { formatTime }) => `resolving: ${formatTime(value)}`,
280
+ "module.profile.restoring": (value, { formatTime }) => `restoring: ${formatTime(value)}`,
281
+ "module.profile.integration": (value, { formatTime }) => `integration: ${formatTime(value)}`,
282
+ "module.profile.building": (value, { formatTime }) => `building: ${formatTime(value)}`,
283
+ "module.profile.storing": (value, { formatTime }) => `storing: ${formatTime(value)}`,
284
+ "module.profile.additionalResolving": (value, { formatTime }) => value ? `additional resolving: ${formatTime(value)}` : undefined,
285
+ "module.profile.additionalIntegration": (value, { formatTime }) => value ? `additional integration: ${formatTime(value)}` : undefined,
286
+ "chunkGroup.kind!": (_, { chunkGroupKind }) => chunkGroupKind,
287
+ "chunkGroup.separator!": () => "\n",
288
+ "chunkGroup.name": (name, { bold }) => bold(name),
289
+ "chunkGroup.isOverSizeLimit": (isOverSizeLimit, { formatFlag, yellow }) => isOverSizeLimit ? yellow(formatFlag("big")) : undefined,
290
+ "chunkGroup.assetsSize": (size, { formatSize }) => size ? formatSize(size) : undefined,
291
+ "chunkGroup.auxiliaryAssetsSize": (size, { formatSize }) => size ? `(${formatSize(size)})` : undefined,
292
+ "chunkGroup.filteredAssets": (n, { chunkGroup: { assets } }) => n > 0
293
+ ? `${moreCount(assets, n)} ${plural(n, "asset", "assets")}`
294
+ : undefined,
295
+ "chunkGroup.filteredAuxiliaryAssets": (n, { chunkGroup: { auxiliaryAssets } }) => n > 0
296
+ ? `${moreCount(auxiliaryAssets, n)} auxiliary ${plural(n, "asset", "assets")}`
297
+ : undefined,
298
+ "chunkGroup.is!": () => "=",
299
+ "chunkGroupAsset.name": (asset, { green }) => green(asset),
300
+ "chunkGroupAsset.size": (size, { formatSize, chunkGroup }) => (chunkGroup.assets && chunkGroup.assets.length > 1) ||
301
+ (chunkGroup.auxiliaryAssets && chunkGroup.auxiliaryAssets.length > 0)
302
+ ? formatSize(size)
303
+ : undefined,
304
+ "chunkGroup.children": (children, context, printer) => Array.isArray(children)
305
+ ? undefined
306
+ : printer.print(context.type, Object.keys(children).map(key => ({
307
+ type: key,
308
+ children: children[key]
309
+ })), context),
310
+ "chunkGroupChildGroup.type": type => `${type}:`,
311
+ "chunkGroupChild.assets[]": (file, { formatFilename }) => formatFilename(file),
312
+ "chunkGroupChild.chunks[]": (id, { formatChunkId }) => formatChunkId(id),
313
+ "chunkGroupChild.name": name => (name ? `(name: ${name})` : undefined),
314
+ "chunk.id": (id, { formatChunkId }) => formatChunkId(id),
315
+ "chunk.files[]": (file, { formatFilename }) => formatFilename(file),
316
+ "chunk.names[]": name => name,
317
+ "chunk.idHints[]": name => name,
318
+ "chunk.runtime[]": name => name,
319
+ "chunk.sizes": (sizes, context) => printSizes(sizes, context),
320
+ "chunk.parents[]": (parents, context) => context.formatChunkId(parents, "parent"),
321
+ "chunk.siblings[]": (siblings, context) => context.formatChunkId(siblings, "sibling"),
322
+ "chunk.children[]": (children, context) => context.formatChunkId(children, "child"),
323
+ "chunk.childrenByOrder": (childrenByOrder, context, printer) => Array.isArray(childrenByOrder)
324
+ ? undefined
325
+ : printer.print(context.type, Object.keys(childrenByOrder).map(key => ({
326
+ type: key,
327
+ children: childrenByOrder[key]
328
+ })), context),
329
+ "chunk.childrenByOrder[].type": type => `${type}:`,
330
+ "chunk.childrenByOrder[].children[]": (id, { formatChunkId }) => isValidId(id) ? formatChunkId(id) : undefined,
331
+ "chunk.entry": (entry, { formatFlag, yellow }) => entry ? yellow(formatFlag("entry")) : undefined,
332
+ "chunk.initial": (initial, { formatFlag, yellow }) => initial ? yellow(formatFlag("initial")) : undefined,
333
+ "chunk.rendered": (rendered, { formatFlag, green }) => rendered ? green(formatFlag("rendered")) : undefined,
334
+ "chunk.recorded": (recorded, { formatFlag, green }) => recorded ? green(formatFlag("recorded")) : undefined,
335
+ "chunk.reason": (reason, { yellow }) => (reason ? yellow(reason) : undefined),
336
+ "chunk.filteredModules": (filteredModules, { chunk: { modules } }) => filteredModules > 0
337
+ ? `${moreCount(modules, filteredModules)} chunk ${plural(filteredModules, "module", "modules")}`
338
+ : undefined,
339
+ "chunk.separator!": () => "\n",
340
+ "chunkOrigin.request": request => request,
341
+ "chunkOrigin.moduleId": (moduleId, { formatModuleId }) => isValidId(moduleId) ? formatModuleId(moduleId) : undefined,
342
+ "chunkOrigin.moduleName": (moduleName, { bold }) => bold(moduleName),
343
+ "chunkOrigin.loc": loc => loc,
344
+ // Error was already formatted on the native.
345
+ error: error => error.formatted,
346
+ "loggingEntry(error).loggingEntry.message": (message, { red }) => mapLines(message, x => `<e> ${red(x)}`),
347
+ "loggingEntry(warn).loggingEntry.message": (message, { yellow }) => mapLines(message, x => `<w> ${yellow(x)}`),
348
+ "loggingEntry(info).loggingEntry.message": (message, { green }) => mapLines(message, x => `<i> ${green(x)}`),
349
+ "loggingEntry(log).loggingEntry.message": (message, { bold }) => mapLines(message, x => ` ${bold(x)}`),
350
+ "loggingEntry(debug).loggingEntry.message": message => mapLines(message, x => ` ${x}`),
351
+ "loggingEntry(trace).loggingEntry.message": message => mapLines(message, x => ` ${x}`),
352
+ "loggingEntry(status).loggingEntry.message": (message, { magenta }) => mapLines(message, x => `<s> ${magenta(x)}`),
353
+ "loggingEntry(profile).loggingEntry.message": (message, { magenta }) => mapLines(message, x => `<p> ${magenta(x)}`),
354
+ "loggingEntry(profileEnd).loggingEntry.message": (message, { magenta }) => mapLines(message, x => `</p> ${magenta(x)}`),
355
+ "loggingEntry(time).loggingEntry.message": (message, { magenta }) => mapLines(message, x => `<t> ${magenta(x)}`),
356
+ "loggingEntry(group).loggingEntry.message": (message, { cyan }) => mapLines(message, x => `<-> ${cyan(x)}`),
357
+ "loggingEntry(groupCollapsed).loggingEntry.message": (message, { cyan }) => mapLines(message, x => `<+> ${cyan(x)}`),
358
+ "loggingEntry(clear).loggingEntry": () => " -------",
359
+ "loggingEntry(groupCollapsed).loggingEntry.children": () => "",
360
+ "loggingEntry.trace[]": trace => trace ? mapLines(trace, x => `| ${x}`) : undefined,
361
+ "moduleTraceItem.originName": originName => originName,
362
+ loggingGroup: loggingGroup => loggingGroup.entries.length === 0 ? "" : undefined,
363
+ "loggingGroup.debug": (flag, { red }) => (flag ? red("DEBUG") : undefined),
364
+ "loggingGroup.name": (name, { bold }) => bold(`LOG from ${name}`),
365
+ "loggingGroup.separator!": () => "\n",
366
+ "loggingGroup.filteredEntries": filteredEntries => filteredEntries > 0 ? `+ ${filteredEntries} hidden lines` : undefined,
367
+ "moduleTraceDependency.loc": loc => loc
368
+ };
369
+ const ITEM_NAMES = {
370
+ "compilation.assets[]": "asset",
371
+ "compilation.modules[]": "module",
372
+ "compilation.chunks[]": "chunk",
373
+ "compilation.entrypoints[]": "chunkGroup",
374
+ "compilation.namedChunkGroups[]": "chunkGroup",
375
+ "compilation.errors[]": "error",
376
+ "compilation.warnings[]": "error",
377
+ "compilation.logging[]": "loggingGroup",
378
+ "compilation.children[]": "compilation",
379
+ "asset.related[]": "asset",
380
+ "asset.children[]": "asset",
381
+ "asset.chunks[]": "assetChunk",
382
+ "asset.auxiliaryChunks[]": "assetChunk",
383
+ "asset.chunkNames[]": "assetChunkName",
384
+ "asset.chunkIdHints[]": "assetChunkIdHint",
385
+ "asset.auxiliaryChunkNames[]": "assetChunkName",
386
+ "asset.auxiliaryChunkIdHints[]": "assetChunkIdHint",
387
+ "chunkGroup.assets[]": "chunkGroupAsset",
388
+ "chunkGroup.auxiliaryAssets[]": "chunkGroupAsset",
389
+ "chunkGroupChild.assets[]": "chunkGroupAsset",
390
+ "chunkGroupChild.auxiliaryAssets[]": "chunkGroupAsset",
391
+ "chunkGroup.children[]": "chunkGroupChildGroup",
392
+ "chunkGroupChildGroup.children[]": "chunkGroupChild",
393
+ "module.modules[]": "module",
394
+ "module.children[]": "module",
395
+ "module.reasons[]": "moduleReason",
396
+ "moduleReason.children[]": "moduleReason",
397
+ "module.issuerPath[]": "moduleIssuer",
398
+ "chunk.origins[]": "chunkOrigin",
399
+ "chunk.modules[]": "module",
400
+ "loggingGroup.entries[]": (logEntry) => `loggingEntry(${logEntry.type}).loggingEntry`,
401
+ "loggingEntry.children[]": (logEntry) => `loggingEntry(${logEntry.type}).loggingEntry`,
402
+ "error.moduleTrace[]": "moduleTraceItem",
403
+ "moduleTraceItem.dependencies[]": "moduleTraceDependency"
404
+ };
405
+ const ERROR_PREFERRED_ORDER = [
406
+ "compilerPath",
407
+ "chunkId",
408
+ "chunkEntry",
409
+ "chunkInitial",
410
+ "file",
411
+ "separator!",
412
+ "moduleName",
413
+ "loc",
414
+ "separator!",
415
+ "message",
416
+ "separator!",
417
+ "details",
418
+ "separator!",
419
+ "stack",
420
+ "separator!",
421
+ "missing",
422
+ "separator!",
423
+ "moduleTrace"
424
+ ];
425
+ const PREFERRED_ORDERS = {
426
+ compilation: [
427
+ "name",
428
+ "hash",
429
+ "rspackVersion",
430
+ "time",
431
+ "builtAt",
432
+ "env",
433
+ "publicPath",
434
+ "assets",
435
+ "filteredAssets",
436
+ "entrypoints",
437
+ "namedChunkGroups",
438
+ "chunks",
439
+ "modules",
440
+ "filteredModules",
441
+ "children",
442
+ "logging",
443
+ "warnings",
444
+ "warningsInChildren!",
445
+ "filteredWarningDetailsCount",
446
+ "errors",
447
+ "errorsInChildren!",
448
+ "filteredErrorDetailsCount",
449
+ "summary!",
450
+ "needAdditionalPass"
451
+ ],
452
+ asset: [
453
+ "type",
454
+ "name",
455
+ "size",
456
+ "chunks",
457
+ "auxiliaryChunks",
458
+ "emitted",
459
+ "comparedForEmit",
460
+ "cached",
461
+ "info",
462
+ "isOverSizeLimit",
463
+ "chunkNames",
464
+ "auxiliaryChunkNames",
465
+ "chunkIdHints",
466
+ "auxiliaryChunkIdHints",
467
+ "related",
468
+ "filteredRelated",
469
+ "children",
470
+ "filteredChildren"
471
+ ],
472
+ "asset.info": [
473
+ "immutable",
474
+ "sourceFilename",
475
+ "javascriptModule",
476
+ "development",
477
+ "hotModuleReplacement"
478
+ ],
479
+ chunkGroup: [
480
+ "kind!",
481
+ "name",
482
+ "isOverSizeLimit",
483
+ "assetsSize",
484
+ "auxiliaryAssetsSize",
485
+ "is!",
486
+ "assets",
487
+ "filteredAssets",
488
+ "auxiliaryAssets",
489
+ "filteredAuxiliaryAssets",
490
+ "separator!",
491
+ "children"
492
+ ],
493
+ chunkGroupAsset: ["name", "size"],
494
+ chunkGroupChildGroup: ["type", "children"],
495
+ chunkGroupChild: ["assets", "chunks", "name"],
496
+ module: [
497
+ "type",
498
+ "name",
499
+ "identifier",
500
+ "id",
501
+ "layer",
502
+ "sizes",
503
+ "chunks",
504
+ "depth",
505
+ "cacheable",
506
+ "orphan",
507
+ "runtime",
508
+ "optional",
509
+ "dependent",
510
+ "built",
511
+ "codeGenerated",
512
+ "cached",
513
+ "assets",
514
+ "failed",
515
+ "warnings",
516
+ "errors",
517
+ "children",
518
+ "filteredChildren",
519
+ "providedExports",
520
+ "usedExports",
521
+ "optimizationBailout",
522
+ "reasons",
523
+ "filteredReasons",
524
+ "issuerPath",
525
+ "profile",
526
+ "modules",
527
+ "filteredModules"
528
+ ],
529
+ moduleReason: [
530
+ "active",
531
+ "type",
532
+ "userRequest",
533
+ "moduleId",
534
+ "module",
535
+ "resolvedModule",
536
+ "loc",
537
+ "explanation",
538
+ "children",
539
+ "filteredChildren"
540
+ ],
541
+ "module.profile": [
542
+ "total",
543
+ "separator!",
544
+ "resolving",
545
+ "restoring",
546
+ "integration",
547
+ "building",
548
+ "storing",
549
+ "additionalResolving",
550
+ "additionalIntegration"
551
+ ],
552
+ chunk: [
553
+ "id",
554
+ "runtime",
555
+ "files",
556
+ "names",
557
+ "idHints",
558
+ "sizes",
559
+ "parents",
560
+ "siblings",
561
+ "children",
562
+ "childrenByOrder",
563
+ "entry",
564
+ "initial",
565
+ "rendered",
566
+ "recorded",
567
+ "reason",
568
+ "separator!",
569
+ "origins",
570
+ "separator!",
571
+ "modules",
572
+ "separator!",
573
+ "filteredModules"
574
+ ],
575
+ chunkOrigin: ["request", "moduleId", "moduleName", "loc"],
576
+ error: ERROR_PREFERRED_ORDER,
577
+ warning: ERROR_PREFERRED_ORDER,
578
+ "chunk.childrenByOrder[]": ["type", "children"],
579
+ loggingGroup: [
580
+ "debug",
581
+ "name",
582
+ "separator!",
583
+ "entries",
584
+ "separator!",
585
+ "filteredEntries"
586
+ ],
587
+ loggingEntry: ["message", "trace", "children"]
588
+ };
589
+ const itemsJoinOneLine = (items) => items.filter(Boolean).join(" ");
590
+ const itemsJoinOneLineBrackets = (items) => items.length > 0 ? `(${items.filter(Boolean).join(" ")})` : undefined;
591
+ const itemsJoinMoreSpacing = (items) => items.filter(Boolean).join("\n\n");
592
+ const itemsJoinComma = (items) => items.filter(Boolean).join(", ");
593
+ const itemsJoinCommaBrackets = (items) => items.length > 0 ? `(${items.filter(Boolean).join(", ")})` : undefined;
594
+ const itemsJoinCommaBracketsWithName = (name) => (items) => items.length > 0
595
+ ? `(${name}: ${items.filter(Boolean).join(", ")})`
596
+ : undefined;
597
+ const SIMPLE_ITEMS_JOINER = {
598
+ "chunk.parents": itemsJoinOneLine,
599
+ "chunk.siblings": itemsJoinOneLine,
600
+ "chunk.children": itemsJoinOneLine,
601
+ "chunk.names": itemsJoinCommaBrackets,
602
+ "chunk.idHints": itemsJoinCommaBracketsWithName("id hint"),
603
+ "chunk.runtime": itemsJoinCommaBracketsWithName("runtime"),
604
+ "chunk.files": itemsJoinComma,
605
+ "chunk.childrenByOrder": itemsJoinOneLine,
606
+ "chunk.childrenByOrder[].children": itemsJoinOneLine,
607
+ "chunkGroup.assets": itemsJoinOneLine,
608
+ "chunkGroup.auxiliaryAssets": itemsJoinOneLineBrackets,
609
+ "chunkGroupChildGroup.children": itemsJoinComma,
610
+ "chunkGroupChild.assets": itemsJoinOneLine,
611
+ "chunkGroupChild.auxiliaryAssets": itemsJoinOneLineBrackets,
612
+ "asset.chunks": itemsJoinComma,
613
+ "asset.auxiliaryChunks": itemsJoinCommaBrackets,
614
+ "asset.chunkNames": itemsJoinCommaBracketsWithName("name"),
615
+ "asset.auxiliaryChunkNames": itemsJoinCommaBracketsWithName("auxiliary name"),
616
+ "asset.chunkIdHints": itemsJoinCommaBracketsWithName("id hint"),
617
+ "asset.auxiliaryChunkIdHints": itemsJoinCommaBracketsWithName("auxiliary id hint"),
618
+ "module.chunks": itemsJoinOneLine,
619
+ "module.issuerPath": items => items
620
+ .filter(Boolean)
621
+ .map(item => `${item} ->`)
622
+ .join(" "),
623
+ "compilation.errors": itemsJoinMoreSpacing,
624
+ "compilation.warnings": itemsJoinMoreSpacing,
625
+ "compilation.logging": itemsJoinMoreSpacing,
626
+ "compilation.children": items => indent(itemsJoinMoreSpacing(items), " "),
627
+ "moduleTraceItem.dependencies": itemsJoinOneLine,
628
+ "loggingEntry.children": items => indent(items.filter(Boolean).join("\n"), " ", false)
629
+ };
630
+ const joinOneLine = (items) => items
631
+ .map(item => item.content)
632
+ .filter(Boolean)
633
+ .join(" ");
634
+ const joinInBrackets = (items) => {
635
+ const res = [];
636
+ let mode = 0;
637
+ for (const item of items) {
638
+ if (item.element === "separator!") {
639
+ switch (mode) {
640
+ case 0:
641
+ case 1:
642
+ mode += 2;
643
+ break;
644
+ case 4:
645
+ res.push(")");
646
+ mode = 3;
647
+ break;
648
+ }
649
+ }
650
+ if (!item.content)
651
+ continue;
652
+ switch (mode) {
653
+ case 0:
654
+ mode = 1;
655
+ break;
656
+ case 1:
657
+ res.push(" ");
658
+ break;
659
+ case 2:
660
+ res.push("(");
661
+ mode = 4;
662
+ break;
663
+ case 3:
664
+ res.push(" (");
665
+ mode = 4;
666
+ break;
667
+ case 4:
668
+ res.push(", ");
669
+ break;
670
+ }
671
+ res.push(item.content);
672
+ }
673
+ if (mode === 4)
674
+ res.push(")");
675
+ return res.join("");
676
+ };
677
+ const indent = (str, prefix, noPrefixInFirstLine) => {
678
+ const rem = str.replace(/\n([^\n])/g, "\n" + prefix + "$1");
679
+ if (noPrefixInFirstLine)
680
+ return rem;
681
+ const ind = str[0] === "\n" ? "" : prefix;
682
+ return ind + rem;
683
+ };
684
+ const joinExplicitNewLine = (items, indenter) => {
685
+ let firstInLine = true;
686
+ let first = true;
687
+ return items
688
+ .map(item => {
689
+ if (!item || !item.content)
690
+ return;
691
+ let content = indent(item.content, first ? "" : indenter, !firstInLine);
692
+ if (firstInLine) {
693
+ content = content.replace(/^\n+/, "");
694
+ }
695
+ if (!content)
696
+ return;
697
+ first = false;
698
+ const noJoiner = firstInLine || content.startsWith("\n");
699
+ firstInLine = content.endsWith("\n");
700
+ return noJoiner ? content : " " + content;
701
+ })
702
+ .filter(Boolean)
703
+ .join("")
704
+ .trim();
705
+ };
706
+ const joinError = error => (items, { red, yellow }) => `${error ? red("ERROR") : yellow("WARNING")} in ${joinExplicitNewLine(items, "")}`;
707
+ const SIMPLE_ELEMENT_JOINERS = {
708
+ compilation: items => {
709
+ const result = [];
710
+ let lastNeedMore = false;
711
+ for (const item of items) {
712
+ if (!item.content)
713
+ continue;
714
+ const needMoreSpace = [
715
+ "warnings",
716
+ "filteredWarningDetailsCount",
717
+ "errors",
718
+ "filteredErrorDetailsCount",
719
+ "logging"
720
+ ].includes(item.element);
721
+ if (result.length !== 0) {
722
+ result.push(needMoreSpace || lastNeedMore ? "\n\n" : "\n");
723
+ }
724
+ result.push(item.content);
725
+ lastNeedMore = needMoreSpace;
726
+ }
727
+ if (lastNeedMore)
728
+ result.push("\n");
729
+ return result.join("");
730
+ },
731
+ asset: items => joinExplicitNewLine(items.map(item => {
732
+ if ((item.element === "related" || item.element === "children") &&
733
+ item.content) {
734
+ return {
735
+ ...item,
736
+ content: `\n${item.content}\n`
737
+ };
738
+ }
739
+ return item;
740
+ }), " "),
741
+ "asset.info": joinOneLine,
742
+ module: (items, { module }) => {
743
+ let hasName = false;
744
+ return joinExplicitNewLine(items.map(item => {
745
+ switch (item.element) {
746
+ case "id":
747
+ if (module && module.id === module.name) {
748
+ if (hasName)
749
+ return false;
750
+ if (item.content)
751
+ hasName = true;
752
+ }
753
+ break;
754
+ case "name":
755
+ if (hasName)
756
+ return false;
757
+ if (item.content)
758
+ hasName = true;
759
+ break;
760
+ case "providedExports":
761
+ case "usedExports":
762
+ case "optimizationBailout":
763
+ case "reasons":
764
+ case "issuerPath":
765
+ case "profile":
766
+ case "children":
767
+ case "modules":
768
+ if (item.content) {
769
+ return {
770
+ ...item,
771
+ content: `\n${item.content}\n`
772
+ };
773
+ }
774
+ break;
775
+ }
776
+ return item;
777
+ }), " ");
778
+ },
779
+ chunk: items => {
780
+ let hasEntry = false;
781
+ return ("chunk " +
782
+ joinExplicitNewLine(items.filter(item => {
783
+ switch (item.element) {
784
+ case "entry":
785
+ if (item.content)
786
+ hasEntry = true;
787
+ break;
788
+ case "initial":
789
+ if (hasEntry)
790
+ return false;
791
+ break;
792
+ }
793
+ return true;
794
+ }), " "));
795
+ },
796
+ "chunk.childrenByOrder[]": items => `(${joinOneLine(items)})`,
797
+ chunkGroup: items => joinExplicitNewLine(items, " "),
798
+ chunkGroupAsset: joinOneLine,
799
+ chunkGroupChildGroup: joinOneLine,
800
+ chunkGroupChild: joinOneLine,
801
+ moduleReason: (items, { moduleReason }) => {
802
+ let hasName = false;
803
+ return joinExplicitNewLine(items.map(item => {
804
+ switch (item.element) {
805
+ case "moduleId":
806
+ if (moduleReason &&
807
+ moduleReason.moduleId === moduleReason.module &&
808
+ item.content)
809
+ hasName = true;
810
+ break;
811
+ case "module":
812
+ if (hasName)
813
+ return false;
814
+ break;
815
+ case "resolvedModule":
816
+ if (moduleReason &&
817
+ moduleReason.module === moduleReason.resolvedModule)
818
+ return false;
819
+ break;
820
+ case "children":
821
+ if (item.content) {
822
+ return {
823
+ ...item,
824
+ content: `\n${item.content}\n`
825
+ };
826
+ }
827
+ break;
828
+ }
829
+ return item;
830
+ }), " ");
831
+ },
832
+ "module.profile": joinInBrackets,
833
+ moduleIssuer: joinOneLine,
834
+ chunkOrigin: items => "> " + joinOneLine(items),
835
+ "errors[].error": joinError(true),
836
+ "warnings[].error": joinError(false),
837
+ loggingGroup: items => joinExplicitNewLine(items, "").trimEnd(),
838
+ moduleTraceItem: items => " @ " + joinOneLine(items),
839
+ moduleTraceDependency: joinOneLine
840
+ };
841
+ const AVAILABLE_COLORS = {
842
+ bold: "\u001b[1m",
843
+ yellow: "\u001b[1m\u001b[33m",
844
+ red: "\u001b[1m\u001b[31m",
845
+ green: "\u001b[1m\u001b[32m",
846
+ cyan: "\u001b[1m\u001b[36m",
847
+ magenta: "\u001b[1m\u001b[35m"
848
+ };
849
+ const AVAILABLE_FORMATS = {
850
+ formatChunkId: (id, { yellow }, direction) => {
851
+ switch (direction) {
852
+ case "parent":
853
+ return `<{${yellow(id)}}>`;
854
+ case "sibling":
855
+ return `={${yellow(id)}}=`;
856
+ case "child":
857
+ return `>{${yellow(id)}}<`;
858
+ default:
859
+ return `{${yellow(id)}}`;
860
+ }
861
+ },
862
+ formatModuleId: id => `[${id}]`,
863
+ formatFilename: (filename, { green, yellow }, oversize) => (oversize ? yellow : green)(filename),
864
+ formatFlag: (flag) => `[${flag}]`,
865
+ formatLayer: layer => `(in ${layer})`,
866
+ formatSize: SizeFormatHelpers_1.formatSize,
867
+ formatDateTime: (dateTime, { bold }) => {
868
+ const d = new Date(dateTime);
869
+ const x = twoDigit;
870
+ const date = `${d.getFullYear()}-${x(d.getMonth() + 1)}-${x(d.getDate())}`;
871
+ const time = `${x(d.getHours())}:${x(d.getMinutes())}:${x(d.getSeconds())}`;
872
+ return `${date} ${bold(time)}`;
873
+ },
874
+ formatTime: (time, { timeReference, bold, green, yellow, red }, boldQuantity) => {
875
+ const unit = " ms";
876
+ if (timeReference && time !== timeReference) {
877
+ const times = [
878
+ timeReference / 2,
879
+ timeReference / 4,
880
+ timeReference / 8,
881
+ timeReference / 16
882
+ ];
883
+ if (time < times[3])
884
+ return `${time}${unit}`;
885
+ else if (time < times[2])
886
+ return bold(`${time}${unit}`);
887
+ else if (time < times[1])
888
+ return green(`${time}${unit}`);
889
+ else if (time < times[0])
890
+ return yellow(`${time}${unit}`);
891
+ else
892
+ return red(`${time}${unit}`);
893
+ }
894
+ else {
895
+ return `${boldQuantity ? bold(time.toString()) : time}${unit}`;
896
+ }
897
+ },
898
+ formatError: (msg, { green, yellow, red }) => {
899
+ let message = msg;
900
+ if (message.includes("\u001b["))
901
+ return message;
902
+ const highlights = [
903
+ { regExp: /(Did you mean .+)/g, format: green },
904
+ {
905
+ regExp: /(Set 'mode' option to 'development' or 'production')/g,
906
+ format: green
907
+ },
908
+ { regExp: /(\(module has no exports\))/g, format: red },
909
+ { regExp: /\(possible exports: (.+)\)/g, format: green },
910
+ { regExp: /(?:^|\n)(.* doesn't exist)/g, format: red },
911
+ { regExp: /('\w+' option has not been set)/g, format: red },
912
+ {
913
+ regExp: /(Emitted value instead of an instance of Error)/g,
914
+ format: yellow
915
+ },
916
+ { regExp: /(Used? .+ instead)/gi, format: yellow },
917
+ { regExp: /\b(deprecated|must|required)\b/g, format: yellow },
918
+ {
919
+ regExp: /\b(BREAKING CHANGE)\b/gi,
920
+ format: red
921
+ },
922
+ {
923
+ regExp: /\b(error|failed|unexpected|invalid|not found|not supported|not available|not possible|not implemented|doesn't support|conflict|conflicting|not existing|duplicate)\b/gi,
924
+ format: red
925
+ }
926
+ ];
927
+ for (const { regExp, format } of highlights) {
928
+ message = message.replace(regExp, (match, content) => {
929
+ return match.replace(content, format(content));
930
+ });
931
+ }
932
+ return message;
933
+ }
934
+ };
935
+ const RESULT_MODIFIER = {
936
+ "module.modules": (result) => {
937
+ return indent(result, "| ");
938
+ }
939
+ };
940
+ const createOrder = (array, preferredOrder) => {
941
+ const originalArray = array.slice();
942
+ const set = new Set(array);
943
+ const usedSet = new Set();
944
+ array.length = 0;
945
+ for (const element of preferredOrder) {
946
+ if (element.endsWith("!") || set.has(element)) {
947
+ array.push(element);
948
+ usedSet.add(element);
949
+ }
950
+ }
951
+ for (const element of originalArray) {
952
+ if (!usedSet.has(element)) {
953
+ array.push(element);
954
+ }
955
+ }
956
+ return array;
957
+ };
958
+ class DefaultStatsPrinterPlugin {
959
+ apply(compiler) {
960
+ compiler.hooks.compilation.tap("DefaultStatsPrinterPlugin", compilation => {
961
+ compilation.hooks.statsPrinter.tap("DefaultStatsPrinterPlugin", (stats, options) => {
962
+ // Put colors into context
963
+ stats.hooks.print.for("compilation").tap("DefaultStatsPrinterPlugin",
964
+ // @ts-expect-error
965
+ (compilation, context) => {
966
+ for (const color of Object.keys(AVAILABLE_COLORS)) {
967
+ let start;
968
+ if (options.colors) {
969
+ if (typeof options.colors === "object" &&
970
+ typeof options.colors[color] === "string") {
971
+ start = options.colors[color];
972
+ }
973
+ else {
974
+ // @ts-expect-error
975
+ start = AVAILABLE_COLORS[color];
976
+ }
977
+ }
978
+ if (start) {
979
+ context[color] = (str) => `${start}${typeof str === "string"
980
+ ? str.replace(/((\u001b\[39m|\u001b\[22m|\u001b\[0m)+)/g, `$1${start}`)
981
+ : str}\u001b[39m\u001b[22m`;
982
+ }
983
+ else {
984
+ context[color] = (str) => str;
985
+ }
986
+ }
987
+ for (const format of Object.keys(AVAILABLE_FORMATS)) {
988
+ // @ts-ignore
989
+ context[format] = (content, ...args) =>
990
+ // @ts-ignore
991
+ AVAILABLE_FORMATS[format](content, context, ...args);
992
+ }
993
+ context.timeReference = compilation.time;
994
+ });
995
+ for (const key of Object.keys(SIMPLE_PRINTERS)) {
996
+ stats.hooks.print
997
+ .for(key)
998
+ .tap("DefaultStatsPrinterPlugin", (obj, ctx) =>
999
+ // @ts-expect-error
1000
+ SIMPLE_PRINTERS[key](obj, ctx, stats));
1001
+ }
1002
+ for (const key of Object.keys(PREFERRED_ORDERS)) {
1003
+ const preferredOrder = PREFERRED_ORDERS[key];
1004
+ stats.hooks.sortElements
1005
+ .for(key)
1006
+ .tap("DefaultStatsPrinterPlugin", elements => {
1007
+ createOrder(elements, preferredOrder);
1008
+ });
1009
+ }
1010
+ for (const key of Object.keys(ITEM_NAMES)) {
1011
+ const itemName = ITEM_NAMES[key];
1012
+ stats.hooks.getItemName
1013
+ .for(key)
1014
+ .tap("DefaultStatsPrinterPlugin", typeof itemName === "string" ? () => itemName : itemName);
1015
+ }
1016
+ for (const key of Object.keys(SIMPLE_ITEMS_JOINER)) {
1017
+ const joiner = SIMPLE_ITEMS_JOINER[key];
1018
+ stats.hooks.printItems
1019
+ .for(key)
1020
+ // @ts-expect-error
1021
+ .tap("DefaultStatsPrinterPlugin", joiner);
1022
+ }
1023
+ for (const key of Object.keys(SIMPLE_ELEMENT_JOINERS)) {
1024
+ const joiner = SIMPLE_ELEMENT_JOINERS[key];
1025
+ stats.hooks.printElements
1026
+ .for(key)
1027
+ // @ts-expect-error
1028
+ .tap("DefaultStatsPrinterPlugin", joiner);
1029
+ }
1030
+ for (const key of Object.keys(RESULT_MODIFIER)) {
1031
+ const modifier = RESULT_MODIFIER[key];
1032
+ stats.hooks.result
1033
+ .for(key)
1034
+ .tap("DefaultStatsPrinterPlugin", modifier);
1035
+ }
1036
+ });
1037
+ });
1038
+ }
1039
+ }
1040
+ exports.DefaultStatsPrinterPlugin = DefaultStatsPrinterPlugin;
1041
+ //# sourceMappingURL=DefaultStatsPrinterPlugin.js.map