webpack 4.1.0 → 4.4.0

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 (118) hide show
  1. package/README.md +719 -721
  2. package/bin/webpack.js +69 -10
  3. package/lib/APIPlugin.js +84 -84
  4. package/lib/AmdMainTemplatePlugin.js +75 -77
  5. package/lib/AsyncDependencyToInitialChunkError.js +21 -23
  6. package/lib/BannerPlugin.js +101 -101
  7. package/lib/Chunk.js +477 -469
  8. package/lib/ChunkTemplate.js +51 -53
  9. package/lib/Compilation.js +1858 -1851
  10. package/lib/Compiler.js +493 -478
  11. package/lib/ConcurrentCompilationError.js +19 -0
  12. package/lib/ContextModule.js +696 -685
  13. package/lib/ContextModuleFactory.js +245 -243
  14. package/lib/DefinePlugin.js +197 -197
  15. package/lib/DelegatedModule.js +101 -101
  16. package/lib/DependenciesBlockVariable.js +51 -52
  17. package/lib/Dependency.js +53 -52
  18. package/lib/DllModule.js +54 -54
  19. package/lib/DllModuleFactory.js +29 -29
  20. package/lib/EnvironmentPlugin.js +65 -67
  21. package/lib/EvalDevToolModuleTemplatePlugin.js +60 -60
  22. package/lib/EvalSourceMapDevToolModuleTemplatePlugin.js +105 -105
  23. package/lib/ExportPropertyMainTemplatePlugin.js +40 -40
  24. package/lib/ExternalModule.js +159 -159
  25. package/lib/FunctionModuleTemplatePlugin.js +98 -98
  26. package/lib/HotModuleReplacement.runtime.js +631 -631
  27. package/lib/HotModuleReplacementPlugin.js +407 -406
  28. package/lib/HotUpdateChunkTemplate.js +78 -80
  29. package/lib/JavascriptGenerator.js +228 -229
  30. package/lib/JavascriptModulesPlugin.js +184 -158
  31. package/lib/JsonGenerator.js +42 -42
  32. package/lib/MainTemplate.js +406 -402
  33. package/lib/Module.js +343 -340
  34. package/lib/ModuleBuildError.js +42 -42
  35. package/lib/ModuleError.js +28 -28
  36. package/lib/ModuleFilenameHelpers.js +166 -166
  37. package/lib/ModuleTemplate.js +77 -79
  38. package/lib/ModuleWarning.js +30 -30
  39. package/lib/MultiCompiler.js +271 -259
  40. package/lib/MultiModule.js +78 -75
  41. package/lib/MultiModuleFactory.js +23 -23
  42. package/lib/MultiWatching.js +38 -37
  43. package/lib/NoModeWarning.js +23 -21
  44. package/lib/NormalModule.js +478 -470
  45. package/lib/NormalModuleFactory.js +483 -481
  46. package/lib/OptionsDefaulter.js +80 -86
  47. package/lib/Parser.js +2074 -2071
  48. package/lib/ProgressPlugin.js +231 -231
  49. package/lib/RawModule.js +54 -55
  50. package/lib/RecordIdsPlugin.js +160 -160
  51. package/lib/RemovedPluginError.js +13 -13
  52. package/lib/ResolverFactory.js +64 -67
  53. package/lib/RuntimeTemplate.js +267 -297
  54. package/lib/SetVarMainTemplatePlugin.js +57 -57
  55. package/lib/SourceMapDevToolPlugin.js +302 -308
  56. package/lib/Stats.js +1234 -1212
  57. package/lib/Template.js +205 -205
  58. package/lib/TemplatedPathPlugin.js +170 -143
  59. package/lib/UmdMainTemplatePlugin.js +264 -269
  60. package/lib/Watching.js +193 -193
  61. package/lib/WebAssemblyParser.js +50 -54
  62. package/lib/WebpackOptionsApply.js +401 -401
  63. package/lib/WebpackOptionsDefaulter.js +337 -317
  64. package/lib/WebpackOptionsValidationError.js +316 -319
  65. package/lib/debug/ProfilingPlugin.js +409 -405
  66. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +328 -311
  67. package/lib/dependencies/AMDRequireContextDependency.js +20 -20
  68. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +270 -241
  69. package/lib/dependencies/HarmonyAcceptImportDependency.js +23 -23
  70. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +620 -606
  71. package/lib/dependencies/HarmonyExportSpecifierDependency.js +53 -53
  72. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +214 -214
  73. package/lib/dependencies/HarmonyImportSpecifierDependency.js +154 -156
  74. package/lib/dependencies/ImportDependenciesBlock.js +17 -17
  75. package/lib/dependencies/ImportDependency.js +34 -34
  76. package/lib/dependencies/ImportEagerDependency.js +32 -32
  77. package/lib/dependencies/ImportParserPlugin.js +175 -179
  78. package/lib/dependencies/ImportWeakDependency.js +34 -34
  79. package/lib/dependencies/JsonExportsDependency.js +25 -25
  80. package/lib/dependencies/ModuleDependency.js +20 -20
  81. package/lib/dependencies/NullDependency.js +20 -20
  82. package/lib/dependencies/RequireContextDependency.js +22 -22
  83. package/lib/dependencies/RequireIncludeDependency.js +40 -40
  84. package/lib/dependencies/WebpackMissingModule.js +20 -22
  85. package/lib/node/NodeChunkTemplatePlugin.js +31 -31
  86. package/lib/node/NodeHotUpdateChunkTemplatePlugin.js +36 -36
  87. package/lib/node/NodeMainTemplatePlugin.js +320 -273
  88. package/lib/node/ReadFileCompileWasmMainTemplatePlugin.js +113 -115
  89. package/lib/optimize/AggressiveSplittingPlugin.js +281 -281
  90. package/lib/optimize/ConcatenatedModule.js +1364 -1366
  91. package/lib/optimize/RemoveParentModulesPlugin.js +114 -114
  92. package/lib/optimize/SplitChunksPlugin.js +519 -491
  93. package/lib/performance/SizeLimitsPlugin.js +105 -105
  94. package/lib/util/TrackingSet.js +35 -35
  95. package/lib/util/objectToMap.js +10 -10
  96. package/lib/wasm/WasmModuleTemplatePlugin.js +106 -106
  97. package/lib/web/JsonpChunkTemplatePlugin.js +47 -47
  98. package/lib/web/JsonpExportMainTemplatePlugin.js +47 -47
  99. package/lib/web/JsonpHotUpdateChunkTemplatePlugin.js +39 -39
  100. package/lib/web/JsonpMainTemplatePlugin.js +425 -403
  101. package/lib/webpack.js +182 -179
  102. package/lib/webworker/WebWorkerChunkTemplatePlugin.js +35 -35
  103. package/lib/webworker/WebWorkerHotUpdateChunkTemplatePlugin.js +40 -40
  104. package/lib/webworker/WebWorkerMainTemplatePlugin.js +177 -154
  105. package/package.json +9 -8
  106. package/schemas/WebpackOptions.json +1973 -1951
  107. package/schemas/ajv.absolutePath.js +55 -29
  108. package/schemas/plugins/BannerPlugin.json +85 -85
  109. package/schemas/plugins/DllPlugin.json +28 -28
  110. package/schemas/plugins/DllReferencePlugin.json +99 -99
  111. package/schemas/plugins/HashedModuleIdsPlugin.json +24 -24
  112. package/schemas/plugins/LoaderOptionsPlugin.json +26 -26
  113. package/schemas/plugins/SourceMapDevToolPlugin.json +187 -187
  114. package/schemas/plugins/WatchIgnorePlugin.json +16 -16
  115. package/schemas/plugins/debug/ProfilingPlugin.json +12 -12
  116. package/schemas/plugins/optimize/AggressiveSplittingPlugin.json +22 -22
  117. package/schemas/plugins/optimize/LimitChunkCountPlugin.json +15 -15
  118. package/schemas/plugins/optimize/MinChunkSizePlugin.json +13 -13
package/lib/Stats.js CHANGED
@@ -1,1212 +1,1234 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Tobias Koppers @sokra
4
- */
5
- "use strict";
6
-
7
- const RequestShortener = require("./RequestShortener");
8
- const SizeFormatHelpers = require("./SizeFormatHelpers");
9
- const formatLocation = require("./formatLocation");
10
- const identifierUtils = require("./util/identifier");
11
-
12
- const optionsOrFallback = (...args) => {
13
- let optionValues = [];
14
- optionValues.push(...args);
15
- return optionValues.find(optionValue => typeof optionValue !== "undefined");
16
- };
17
-
18
- class Stats {
19
- constructor(compilation) {
20
- this.compilation = compilation;
21
- this.hash = compilation.hash;
22
- }
23
-
24
- static filterWarnings(warnings, warningsFilter) {
25
- // we dont have anything to filter so all warnings can be shown
26
- if (!warningsFilter) {
27
- return warnings;
28
- }
29
-
30
- // create a chain of filters
31
- // if they return "true" a warning should be suppressed
32
- const normalizedWarningsFilters = [].concat(warningsFilter).map(filter => {
33
- if (typeof filter === "string") {
34
- return warning => warning.includes(filter);
35
- }
36
-
37
- if (filter instanceof RegExp) {
38
- return warning => filter.test(warning);
39
- }
40
-
41
- if (typeof filter === "function") {
42
- return filter;
43
- }
44
-
45
- throw new Error(
46
- `Can only filter warnings with Strings or RegExps. (Given: ${filter})`
47
- );
48
- });
49
- return warnings.filter(warning => {
50
- return !normalizedWarningsFilters.some(check => check(warning));
51
- });
52
- }
53
-
54
- hasWarnings() {
55
- return (
56
- this.compilation.warnings.length > 0 ||
57
- this.compilation.children.some(child => child.getStats().hasWarnings())
58
- );
59
- }
60
-
61
- hasErrors() {
62
- return (
63
- this.compilation.errors.length > 0 ||
64
- this.compilation.children.some(child => child.getStats().hasErrors())
65
- );
66
- }
67
-
68
- // remove a prefixed "!" that can be specified to reverse sort order
69
- normalizeFieldKey(field) {
70
- if (field[0] === "!") {
71
- return field.substr(1);
72
- }
73
- return field;
74
- }
75
-
76
- // if a field is prefixed by a "!" reverse sort order
77
- sortOrderRegular(field) {
78
- if (field[0] === "!") {
79
- return false;
80
- }
81
- return true;
82
- }
83
-
84
- toJson(options, forToString) {
85
- if (typeof options === "boolean" || typeof options === "string") {
86
- options = Stats.presetToOptions(options);
87
- } else if (!options) {
88
- options = {};
89
- }
90
-
91
- const optionOrLocalFallback = (v, def) =>
92
- typeof v !== "undefined"
93
- ? v
94
- : typeof options.all !== "undefined" ? options.all : def;
95
-
96
- const testAgainstGivenOption = item => {
97
- if (typeof item === "string") {
98
- const regExp = new RegExp(
99
- `[\\\\/]${item.replace(
100
- /[-[\]{}()*+?.\\^$|]/g,
101
- "\\$&"
102
- )}([\\\\/]|$|!|\\?)`
103
- ); // eslint-disable-line no-useless-escape
104
- return ident => regExp.test(ident);
105
- }
106
- if (item && typeof item === "object" && typeof item.test === "function")
107
- return ident => item.test(ident);
108
- if (typeof item === "function") return item;
109
- };
110
-
111
- const compilation = this.compilation;
112
- const context = optionsOrFallback(
113
- options.context,
114
- compilation.compiler.context
115
- );
116
- const requestShortener =
117
- compilation.compiler.context === context
118
- ? compilation.requestShortener
119
- : new RequestShortener(context);
120
- const showPerformance = optionOrLocalFallback(options.performance, true);
121
- const showHash = optionOrLocalFallback(options.hash, true);
122
- const showEnv = optionOrLocalFallback(options.env, false);
123
- const showVersion = optionOrLocalFallback(options.version, true);
124
- const showTimings = optionOrLocalFallback(options.timings, true);
125
- const showBuiltAt = optionOrLocalFallback(options.builtAt, true);
126
- const showAssets = optionOrLocalFallback(options.assets, true);
127
- const showEntrypoints = optionOrLocalFallback(options.entrypoints, true);
128
- const showChunks = optionOrLocalFallback(options.chunks, !forToString);
129
- const showChunkModules = optionOrLocalFallback(options.chunkModules, true);
130
- const showChunkOrigins = optionOrLocalFallback(
131
- options.chunkOrigins,
132
- !forToString
133
- );
134
- const showModules = optionOrLocalFallback(options.modules, true);
135
- const showNestedModules = optionOrLocalFallback(
136
- options.nestedModules,
137
- true
138
- );
139
- const showDepth = optionOrLocalFallback(options.depth, !forToString);
140
- const showCachedModules = optionOrLocalFallback(options.cached, true);
141
- const showCachedAssets = optionOrLocalFallback(options.cachedAssets, true);
142
- const showReasons = optionOrLocalFallback(options.reasons, !forToString);
143
- const showUsedExports = optionOrLocalFallback(
144
- options.usedExports,
145
- !forToString
146
- );
147
- const showProvidedExports = optionOrLocalFallback(
148
- options.providedExports,
149
- !forToString
150
- );
151
- const showOptimizationBailout = optionOrLocalFallback(
152
- options.optimizationBailout,
153
- !forToString
154
- );
155
- const showChildren = optionOrLocalFallback(options.children, true);
156
- const showSource = optionOrLocalFallback(options.source, !forToString);
157
- const showModuleTrace = optionOrLocalFallback(options.moduleTrace, true);
158
- const showErrors = optionOrLocalFallback(options.errors, true);
159
- const showErrorDetails = optionOrLocalFallback(
160
- options.errorDetails,
161
- !forToString
162
- );
163
- const showWarnings = optionOrLocalFallback(options.warnings, true);
164
- const warningsFilter = optionsOrFallback(options.warningsFilter, null);
165
- const showPublicPath = optionOrLocalFallback(
166
- options.publicPath,
167
- !forToString
168
- );
169
- const excludeModules = []
170
- .concat(optionsOrFallback(options.excludeModules, options.exclude, []))
171
- .map(testAgainstGivenOption);
172
- const excludeAssets = []
173
- .concat(optionsOrFallback(options.excludeAssets, []))
174
- .map(testAgainstGivenOption);
175
- const maxModules = optionsOrFallback(
176
- options.maxModules,
177
- forToString ? 15 : Infinity
178
- );
179
- const sortModules = optionsOrFallback(options.modulesSort, "id");
180
- const sortChunks = optionsOrFallback(options.chunksSort, "id");
181
- const sortAssets = optionsOrFallback(options.assetsSort, "");
182
- const showOutputPath = optionOrLocalFallback(
183
- options.outputPath,
184
- !forToString
185
- );
186
-
187
- if (!showCachedModules) {
188
- excludeModules.push((ident, module) => !module.built);
189
- }
190
-
191
- const createModuleFilter = () => {
192
- let i = 0;
193
- return module => {
194
- if (excludeModules.length > 0) {
195
- const ident = requestShortener.shorten(module.resource);
196
- const excluded = excludeModules.some(fn => fn(ident, module));
197
- if (excluded) return false;
198
- }
199
- const result = i < maxModules;
200
- i++;
201
- return result;
202
- };
203
- };
204
-
205
- const createAssetFilter = () => {
206
- return asset => {
207
- if (excludeAssets.length > 0) {
208
- const ident = asset.name;
209
- const excluded = excludeAssets.some(fn => fn(ident, asset));
210
- if (excluded) return false;
211
- }
212
- return showCachedAssets || asset.emitted;
213
- };
214
- };
215
-
216
- const sortByFieldAndOrder = (fieldKey, a, b) => {
217
- if (a[fieldKey] === null && b[fieldKey] === null) return 0;
218
- if (a[fieldKey] === null) return 1;
219
- if (b[fieldKey] === null) return -1;
220
- if (a[fieldKey] === b[fieldKey]) return 0;
221
- return a[fieldKey] < b[fieldKey] ? -1 : 1;
222
- };
223
-
224
- const sortByField = field => (a, b) => {
225
- if (!field) {
226
- return 0;
227
- }
228
-
229
- const fieldKey = this.normalizeFieldKey(field);
230
-
231
- // if a field is prefixed with a "!" the sort is reversed!
232
- const sortIsRegular = this.sortOrderRegular(field);
233
-
234
- return sortByFieldAndOrder(
235
- fieldKey,
236
- sortIsRegular ? a : b,
237
- sortIsRegular ? b : a
238
- );
239
- };
240
-
241
- const formatError = e => {
242
- let text = "";
243
- if (typeof e === "string")
244
- e = {
245
- message: e
246
- };
247
- if (e.chunk) {
248
- text += `chunk ${e.chunk.name || e.chunk.id}${
249
- e.chunk.hasRuntime()
250
- ? " [entry]"
251
- : e.chunk.canBeInitial() ? " [initial]" : ""
252
- }\n`;
253
- }
254
- if (e.file) {
255
- text += `${e.file}\n`;
256
- }
257
- if (
258
- e.module &&
259
- e.module.readableIdentifier &&
260
- typeof e.module.readableIdentifier === "function"
261
- ) {
262
- text += `${e.module.readableIdentifier(requestShortener)}\n`;
263
- }
264
- text += e.message;
265
- if (showErrorDetails && e.details) text += `\n${e.details}`;
266
- if (showErrorDetails && e.missing)
267
- text += e.missing.map(item => `\n[${item}]`).join("");
268
- if (showModuleTrace && e.origin) {
269
- text += `\n @ ${e.origin.readableIdentifier(requestShortener)}`;
270
- if (typeof e.originLoc === "object") {
271
- const locInfo = formatLocation(e.originLoc);
272
- if (locInfo) text += ` ${locInfo}`;
273
- }
274
- if (e.dependencies) {
275
- for (const dep of e.dependencies) {
276
- if (!dep.loc) continue;
277
- if (typeof dep.loc === "string") continue;
278
- const locInfo = formatLocation(dep.loc);
279
- if (!locInfo) continue;
280
- text += ` ${locInfo}`;
281
- }
282
- }
283
- let current = e.origin;
284
- while (current.issuer) {
285
- current = current.issuer;
286
- text += `\n @ ${current.readableIdentifier(requestShortener)}`;
287
- }
288
- }
289
- return text;
290
- };
291
-
292
- const obj = {
293
- errors: compilation.errors.map(formatError),
294
- warnings: Stats.filterWarnings(
295
- compilation.warnings.map(formatError),
296
- warningsFilter
297
- )
298
- };
299
-
300
- //We just hint other renderers since actually omitting
301
- //errors/warnings from the JSON would be kind of weird.
302
- Object.defineProperty(obj, "_showWarnings", {
303
- value: showWarnings,
304
- enumerable: false
305
- });
306
- Object.defineProperty(obj, "_showErrors", {
307
- value: showErrors,
308
- enumerable: false
309
- });
310
-
311
- if (showVersion) {
312
- obj.version = require("../package.json").version;
313
- }
314
-
315
- if (showHash) obj.hash = this.hash;
316
- if (showTimings && this.startTime && this.endTime) {
317
- obj.time = this.endTime - this.startTime;
318
- }
319
-
320
- if (showBuiltAt && this.endTime) {
321
- obj.builtAt = this.endTime;
322
- }
323
-
324
- if (showEnv && options._env) {
325
- obj.env = options._env;
326
- }
327
-
328
- if (compilation.needAdditionalPass) {
329
- obj.needAdditionalPass = true;
330
- }
331
- if (showPublicPath) {
332
- obj.publicPath = this.compilation.mainTemplate.getPublicPath({
333
- hash: this.compilation.hash
334
- });
335
- }
336
- if (showOutputPath) {
337
- obj.outputPath = this.compilation.mainTemplate.outputOptions.path;
338
- }
339
- if (showAssets) {
340
- const assetsByFile = {};
341
- const compilationAssets = Object.keys(compilation.assets);
342
- obj.assetsByChunkName = {};
343
- obj.assets = compilationAssets
344
- .map(asset => {
345
- const obj = {
346
- name: asset,
347
- size: compilation.assets[asset].size(),
348
- chunks: [],
349
- chunkNames: [],
350
- emitted: compilation.assets[asset].emitted
351
- };
352
-
353
- if (showPerformance) {
354
- obj.isOverSizeLimit = compilation.assets[asset].isOverSizeLimit;
355
- }
356
-
357
- assetsByFile[asset] = obj;
358
- return obj;
359
- })
360
- .filter(createAssetFilter());
361
- obj.filteredAssets = compilationAssets.length - obj.assets.length;
362
-
363
- for (const chunk of compilation.chunks) {
364
- for (const asset of chunk.files) {
365
- if (assetsByFile[asset]) {
366
- for (const id of chunk.ids) {
367
- assetsByFile[asset].chunks.push(id);
368
- }
369
- if (chunk.name) {
370
- assetsByFile[asset].chunkNames.push(chunk.name);
371
- if (obj.assetsByChunkName[chunk.name])
372
- obj.assetsByChunkName[chunk.name] = []
373
- .concat(obj.assetsByChunkName[chunk.name])
374
- .concat([asset]);
375
- else obj.assetsByChunkName[chunk.name] = asset;
376
- }
377
- }
378
- }
379
- }
380
- obj.assets.sort(sortByField(sortAssets));
381
- }
382
-
383
- if (showEntrypoints) {
384
- obj.entrypoints = {};
385
- for (const keyValuePair of compilation.entrypoints) {
386
- const name = keyValuePair[0];
387
- const ep = keyValuePair[1];
388
- obj.entrypoints[name] = {
389
- chunks: ep.chunks.map(c => c.id),
390
- assets: ep.chunks.reduce(
391
- (array, c) => array.concat(c.files || []),
392
- []
393
- )
394
- };
395
- if (showPerformance) {
396
- obj.entrypoints[name].isOverSizeLimit = ep.isOverSizeLimit;
397
- }
398
- }
399
- }
400
-
401
- const fnModule = module => {
402
- const path = [];
403
- let current = module;
404
- while (current.issuer) {
405
- path.push((current = current.issuer));
406
- }
407
- path.reverse();
408
- const obj = {
409
- id: module.id,
410
- identifier: module.identifier(),
411
- name: module.readableIdentifier(requestShortener),
412
- index: module.index,
413
- index2: module.index2,
414
- size: module.size(),
415
- cacheable: module.buildInfo.cacheable,
416
- built: !!module.built,
417
- optional: module.optional,
418
- prefetched: module.prefetched,
419
- chunks: Array.from(module.chunksIterable, chunk => chunk.id),
420
- assets: Object.keys(module.assets || {}),
421
- issuer: module.issuer && module.issuer.identifier(),
422
- issuerId: module.issuer && module.issuer.id,
423
- issuerName:
424
- module.issuer && module.issuer.readableIdentifier(requestShortener),
425
- issuerPath:
426
- module.issuer &&
427
- path.map(module => ({
428
- id: module.id,
429
- identifier: module.identifier(),
430
- name: module.readableIdentifier(requestShortener),
431
- profile: module.profile
432
- })),
433
- profile: module.profile,
434
- failed: !!module.error,
435
- errors: module.errors ? module.errors.length : 0,
436
- warnings: module.warnings ? module.warnings.length : 0
437
- };
438
- if (showReasons) {
439
- obj.reasons = module.reasons
440
- .map(reason => {
441
- const obj = {
442
- moduleId: reason.module ? reason.module.id : null,
443
- moduleIdentifier: reason.module
444
- ? reason.module.identifier()
445
- : null,
446
- module: reason.module
447
- ? reason.module.readableIdentifier(requestShortener)
448
- : null,
449
- moduleName: reason.module
450
- ? reason.module.readableIdentifier(requestShortener)
451
- : null,
452
- type: reason.dependency ? reason.dependency.type : null,
453
- userRequest: reason.dependency
454
- ? reason.dependency.userRequest
455
- : null
456
- };
457
- if (reason.dependency) {
458
- const locInfo = formatLocation(reason.dependency.loc);
459
- if (locInfo) obj.loc = locInfo;
460
- }
461
- return obj;
462
- })
463
- .sort((a, b) => a.moduleId - b.moduleId);
464
- }
465
- if (showUsedExports) {
466
- if (module.used === true) obj.usedExports = module.usedExports;
467
- else if (module.used === false) obj.usedExports = false;
468
- }
469
- if (showProvidedExports) {
470
- obj.providedExports = Array.isArray(module.buildMeta.providedExports)
471
- ? module.buildMeta.providedExports
472
- : null;
473
- }
474
- if (showOptimizationBailout) {
475
- obj.optimizationBailout = module.optimizationBailout.map(item => {
476
- if (typeof item === "function") return item(requestShortener);
477
- return item;
478
- });
479
- }
480
- if (showDepth) {
481
- obj.depth = module.depth;
482
- }
483
- if (showNestedModules) {
484
- if (module.modules) {
485
- const modules = module.modules;
486
- obj.modules = modules
487
- .sort(sortByField("depth"))
488
- .filter(createModuleFilter())
489
- .map(fnModule);
490
- obj.filteredModules = modules.length - obj.modules.length;
491
- obj.modules.sort(sortByField(sortModules));
492
- }
493
- }
494
- if (showSource && module._source) {
495
- obj.source = module._source.source();
496
- }
497
- return obj;
498
- };
499
- if (showChunks) {
500
- obj.chunks = compilation.chunks.map(chunk => {
501
- const parents = new Set();
502
- const children = new Set();
503
- const siblings = new Set();
504
- for (const chunkGroup of chunk.groupsIterable) {
505
- for (const parentGroup of chunkGroup.parentsIterable) {
506
- for (const chunk of parentGroup.chunks) {
507
- parents.add(chunk.id);
508
- }
509
- }
510
- for (const childGroup of chunkGroup.childrenIterable) {
511
- for (const chunk of childGroup.chunks) {
512
- children.add(chunk.id);
513
- }
514
- }
515
- for (const sibling of chunkGroup.chunks) {
516
- if (sibling !== chunk) siblings.add(sibling.id);
517
- }
518
- }
519
- const obj = {
520
- id: chunk.id,
521
- rendered: chunk.rendered,
522
- initial: chunk.canBeInitial(),
523
- entry: chunk.hasRuntime(),
524
- recorded: chunk.recorded,
525
- reason: chunk.chunkReason,
526
- size: chunk.modulesSize(),
527
- names: chunk.name ? [chunk.name] : [],
528
- files: chunk.files.slice(),
529
- hash: chunk.renderedHash,
530
- siblings: Array.from(siblings).sort(),
531
- parents: Array.from(parents).sort(),
532
- children: Array.from(children).sort()
533
- };
534
- if (showChunkModules) {
535
- obj.modules = chunk
536
- .getModules()
537
- .sort(sortByField("depth"))
538
- .filter(createModuleFilter())
539
- .map(fnModule);
540
- obj.filteredModules = chunk.getNumberOfModules() - obj.modules.length;
541
- obj.modules.sort(sortByField(sortModules));
542
- }
543
- if (showChunkOrigins) {
544
- obj.origins = Array.from(chunk.groupsIterable, g => g.origins)
545
- .reduce((a, b) => a.concat(b), [])
546
- .map(origin => ({
547
- moduleId: origin.module ? origin.module.id : undefined,
548
- module: origin.module ? origin.module.identifier() : "",
549
- moduleIdentifier: origin.module ? origin.module.identifier() : "",
550
- moduleName: origin.module
551
- ? origin.module.readableIdentifier(requestShortener)
552
- : "",
553
- loc: formatLocation(origin.loc),
554
- request: origin.request,
555
- reasons: origin.reasons || []
556
- }))
557
- .sort((a, b) => {
558
- if (
559
- typeof a.moduleId === "number" &&
560
- typeof b.moduleId !== "number"
561
- )
562
- return 1;
563
- if (
564
- typeof a.moduleId !== "number" &&
565
- typeof b.moduleId === "number"
566
- )
567
- return -1;
568
- if (
569
- typeof a.moduleId === "number" &&
570
- typeof b.moduleId === "number"
571
- ) {
572
- const diffId = a.moduleId - b.moduleId;
573
- if (diffId !== 0) return diffId;
574
- }
575
- if (a.loc < b.loc) return -1;
576
- if (a.loc > b.loc) return 1;
577
- return 0;
578
- });
579
- }
580
- return obj;
581
- });
582
- obj.chunks.sort(sortByField(sortChunks));
583
- }
584
- if (showModules) {
585
- obj.modules = compilation.modules
586
- .slice()
587
- .sort(sortByField("depth"))
588
- .filter(createModuleFilter())
589
- .map(fnModule);
590
- obj.filteredModules = compilation.modules.length - obj.modules.length;
591
- obj.modules.sort(sortByField(sortModules));
592
- }
593
- if (showChildren) {
594
- obj.children = compilation.children.map((child, idx) => {
595
- const childOptions = Stats.getChildOptions(options, idx);
596
- const obj = new Stats(child).toJson(childOptions, forToString);
597
- delete obj.hash;
598
- delete obj.version;
599
- if (child.name)
600
- obj.name = identifierUtils.makePathsRelative(
601
- context,
602
- child.name,
603
- compilation.cache
604
- );
605
- return obj;
606
- });
607
- }
608
-
609
- return obj;
610
- }
611
-
612
- toString(options) {
613
- if (typeof options === "boolean" || typeof options === "string") {
614
- options = Stats.presetToOptions(options);
615
- } else if (!options) {
616
- options = {};
617
- }
618
-
619
- const useColors = optionsOrFallback(options.colors, false);
620
-
621
- const obj = this.toJson(options, true);
622
-
623
- return Stats.jsonToString(obj, useColors);
624
- }
625
-
626
- static jsonToString(obj, useColors) {
627
- const buf = [];
628
-
629
- const defaultColors = {
630
- bold: "\u001b[1m",
631
- yellow: "\u001b[1m\u001b[33m",
632
- red: "\u001b[1m\u001b[31m",
633
- green: "\u001b[1m\u001b[32m",
634
- cyan: "\u001b[1m\u001b[36m",
635
- magenta: "\u001b[1m\u001b[35m"
636
- };
637
-
638
- const colors = Object.keys(defaultColors).reduce(
639
- (obj, color) => {
640
- obj[color] = str => {
641
- if (useColors) {
642
- buf.push(
643
- useColors === true || useColors[color] === undefined
644
- ? defaultColors[color]
645
- : useColors[color]
646
- );
647
- }
648
- buf.push(str);
649
- if (useColors) {
650
- buf.push("\u001b[39m\u001b[22m");
651
- }
652
- };
653
- return obj;
654
- },
655
- {
656
- normal: str => buf.push(str)
657
- }
658
- );
659
-
660
- const coloredTime = time => {
661
- let times = [800, 400, 200, 100];
662
- if (obj.time) {
663
- times = [obj.time / 2, obj.time / 4, obj.time / 8, obj.time / 16];
664
- }
665
- if (time < times[3]) colors.normal(`${time}ms`);
666
- else if (time < times[2]) colors.bold(`${time}ms`);
667
- else if (time < times[1]) colors.green(`${time}ms`);
668
- else if (time < times[0]) colors.yellow(`${time}ms`);
669
- else colors.red(`${time}ms`);
670
- };
671
-
672
- const newline = () => buf.push("\n");
673
-
674
- const getText = (arr, row, col) => {
675
- return arr[row][col].value;
676
- };
677
-
678
- const table = (array, align, splitter) => {
679
- const rows = array.length;
680
- const cols = array[0].length;
681
- const colSizes = new Array(cols);
682
- for (let col = 0; col < cols; col++) colSizes[col] = 0;
683
- for (let row = 0; row < rows; row++) {
684
- for (let col = 0; col < cols; col++) {
685
- const value = `${getText(array, row, col)}`;
686
- if (value.length > colSizes[col]) {
687
- colSizes[col] = value.length;
688
- }
689
- }
690
- }
691
- for (let row = 0; row < rows; row++) {
692
- for (let col = 0; col < cols; col++) {
693
- const format = array[row][col].color;
694
- const value = `${getText(array, row, col)}`;
695
- let l = value.length;
696
- if (align[col] === "l") format(value);
697
- for (; l < colSizes[col] && col !== cols - 1; l++) colors.normal(" ");
698
- if (align[col] === "r") format(value);
699
- if (col + 1 < cols && colSizes[col] !== 0)
700
- colors.normal(splitter || " ");
701
- }
702
- newline();
703
- }
704
- };
705
-
706
- const getAssetColor = (asset, defaultColor) => {
707
- if (asset.isOverSizeLimit) {
708
- return colors.yellow;
709
- }
710
-
711
- return defaultColor;
712
- };
713
-
714
- if (obj.hash) {
715
- colors.normal("Hash: ");
716
- colors.bold(obj.hash);
717
- newline();
718
- }
719
- if (obj.version) {
720
- colors.normal("Version: webpack ");
721
- colors.bold(obj.version);
722
- newline();
723
- }
724
- if (typeof obj.time === "number") {
725
- colors.normal("Time: ");
726
- colors.bold(obj.time);
727
- colors.normal("ms");
728
- newline();
729
- }
730
- if (typeof obj.builtAt === "number") {
731
- const builtAtDate = new Date(obj.builtAt);
732
- colors.normal("Built at: ");
733
- colors.normal(builtAtDate.toLocaleDateString());
734
- colors.normal(" ");
735
- colors.bold(builtAtDate.toLocaleTimeString());
736
- newline();
737
- }
738
- if (obj.env) {
739
- colors.normal("Environment (--env): ");
740
- colors.bold(JSON.stringify(obj.env, null, 2));
741
- newline();
742
- }
743
- if (obj.publicPath) {
744
- colors.normal("PublicPath: ");
745
- colors.bold(obj.publicPath);
746
- newline();
747
- }
748
-
749
- if (obj.assets && obj.assets.length > 0) {
750
- const t = [
751
- [
752
- {
753
- value: "Asset",
754
- color: colors.bold
755
- },
756
- {
757
- value: "Size",
758
- color: colors.bold
759
- },
760
- {
761
- value: "Chunks",
762
- color: colors.bold
763
- },
764
- {
765
- value: "",
766
- color: colors.bold
767
- },
768
- {
769
- value: "",
770
- color: colors.bold
771
- },
772
- {
773
- value: "Chunk Names",
774
- color: colors.bold
775
- }
776
- ]
777
- ];
778
- for (const asset of obj.assets) {
779
- t.push([
780
- {
781
- value: asset.name,
782
- color: getAssetColor(asset, colors.green)
783
- },
784
- {
785
- value: SizeFormatHelpers.formatSize(asset.size),
786
- color: getAssetColor(asset, colors.normal)
787
- },
788
- {
789
- value: asset.chunks.join(", "),
790
- color: colors.bold
791
- },
792
- {
793
- value: asset.emitted ? "[emitted]" : "",
794
- color: colors.green
795
- },
796
- {
797
- value: asset.isOverSizeLimit ? "[big]" : "",
798
- color: getAssetColor(asset, colors.normal)
799
- },
800
- {
801
- value: asset.chunkNames.join(", "),
802
- color: colors.normal
803
- }
804
- ]);
805
- }
806
- table(t, "rrrlll");
807
- }
808
- if (obj.filteredAssets > 0) {
809
- colors.normal(" ");
810
- if (obj.assets.length > 0) colors.normal("+ ");
811
- colors.normal(obj.filteredAssets);
812
- if (obj.assets.length > 0) colors.normal(" hidden");
813
- colors.normal(obj.filteredAssets !== 1 ? " assets" : " asset");
814
- newline();
815
- }
816
- if (obj.entrypoints) {
817
- for (const name of Object.keys(obj.entrypoints)) {
818
- const ep = obj.entrypoints[name];
819
- colors.normal("Entrypoint ");
820
- colors.bold(name);
821
- if (ep.isOverSizeLimit) {
822
- colors.normal(" ");
823
- colors.yellow("[big]");
824
- }
825
- colors.normal(" =");
826
- for (const asset of ep.assets) {
827
- colors.normal(" ");
828
- colors.green(asset);
829
- }
830
- newline();
831
- }
832
- }
833
- const modulesByIdentifier = {};
834
- if (obj.modules) {
835
- for (const module of obj.modules) {
836
- modulesByIdentifier[`$${module.identifier}`] = module;
837
- }
838
- } else if (obj.chunks) {
839
- for (const chunk of obj.chunks) {
840
- if (chunk.modules) {
841
- for (const module of chunk.modules) {
842
- modulesByIdentifier[`$${module.identifier}`] = module;
843
- }
844
- }
845
- }
846
- }
847
-
848
- const processModuleAttributes = module => {
849
- colors.normal(" ");
850
- colors.normal(SizeFormatHelpers.formatSize(module.size));
851
- if (module.chunks) {
852
- for (const chunk of module.chunks) {
853
- colors.normal(" {");
854
- colors.yellow(chunk);
855
- colors.normal("}");
856
- }
857
- }
858
- if (typeof module.depth === "number") {
859
- colors.normal(` [depth ${module.depth}]`);
860
- }
861
- if (module.cacheable === false) {
862
- colors.red(" [not cacheable]");
863
- }
864
- if (module.optional) {
865
- colors.yellow(" [optional]");
866
- }
867
- if (module.built) {
868
- colors.green(" [built]");
869
- }
870
- if (module.prefetched) {
871
- colors.magenta(" [prefetched]");
872
- }
873
- if (module.failed) colors.red(" [failed]");
874
- if (module.warnings)
875
- colors.yellow(
876
- ` [${module.warnings} warning${module.warnings === 1 ? "" : "s"}]`
877
- );
878
- if (module.errors)
879
- colors.red(
880
- ` [${module.errors} error${module.errors === 1 ? "" : "s"}]`
881
- );
882
- };
883
-
884
- const processModuleContent = (module, prefix) => {
885
- if (Array.isArray(module.providedExports)) {
886
- colors.normal(prefix);
887
- if (module.providedExports.length === 0) colors.cyan("[no exports]");
888
- else colors.cyan(`[exports: ${module.providedExports.join(", ")}]`);
889
- newline();
890
- }
891
- if (module.usedExports !== undefined) {
892
- if (module.usedExports !== true) {
893
- colors.normal(prefix);
894
- if (module.usedExports === null)
895
- colors.cyan("[used exports unknown]");
896
- else if (module.usedExports === false)
897
- colors.cyan("[no exports used]");
898
- else if (
899
- Array.isArray(module.usedExports) &&
900
- module.usedExports.length === 0
901
- )
902
- colors.cyan("[no exports used]");
903
- else if (Array.isArray(module.usedExports))
904
- colors.cyan(
905
- `[only some exports used: ${module.usedExports.join(", ")}]`
906
- );
907
- newline();
908
- }
909
- }
910
- if (Array.isArray(module.optimizationBailout)) {
911
- for (const item of module.optimizationBailout) {
912
- colors.normal(prefix);
913
- colors.yellow(item);
914
- newline();
915
- }
916
- }
917
- if (module.reasons) {
918
- for (const reason of module.reasons) {
919
- colors.normal(prefix);
920
- if (reason.type) {
921
- colors.normal(reason.type);
922
- colors.normal(" ");
923
- }
924
- if (reason.userRequest) {
925
- colors.cyan(reason.userRequest);
926
- colors.normal(" ");
927
- }
928
- if (reason.moduleId !== null) {
929
- colors.normal("[");
930
- colors.normal(reason.moduleId);
931
- colors.normal("]");
932
- }
933
- if (reason.module && reason.module !== reason.moduleId) {
934
- colors.normal(" ");
935
- colors.magenta(reason.module);
936
- }
937
- if (reason.loc) {
938
- colors.normal(" ");
939
- colors.normal(reason.loc);
940
- }
941
- newline();
942
- }
943
- }
944
- if (module.profile) {
945
- colors.normal(prefix);
946
- let sum = 0;
947
- if (module.issuerPath) {
948
- for (const m of module.issuerPath) {
949
- colors.normal("[");
950
- colors.normal(m.id);
951
- colors.normal("] ");
952
- if (m.profile) {
953
- const time = (m.profile.factory || 0) + (m.profile.building || 0);
954
- coloredTime(time);
955
- sum += time;
956
- colors.normal(" ");
957
- }
958
- colors.normal("-> ");
959
- }
960
- }
961
- for (const key of Object.keys(module.profile)) {
962
- colors.normal(`${key}:`);
963
- const time = module.profile[key];
964
- coloredTime(time);
965
- colors.normal(" ");
966
- sum += time;
967
- }
968
- colors.normal("= ");
969
- coloredTime(sum);
970
- newline();
971
- }
972
- if (module.modules) {
973
- processModulesList(module, prefix + "| ");
974
- }
975
- };
976
-
977
- const processModulesList = (obj, prefix) => {
978
- if (obj.modules) {
979
- for (const module of obj.modules) {
980
- colors.normal(prefix);
981
- const name = module.name || module.identifier;
982
- let contentPrefix = prefix + " ";
983
- if (typeof module.id === "string" || typeof module.id === "number") {
984
- contentPrefix += " ";
985
- if (module.id < 1000) colors.normal(" ");
986
- if (module.id < 100) colors.normal(" ");
987
- if (module.id < 10) colors.normal(" ");
988
- colors.normal("[");
989
- colors.normal(module.id);
990
- colors.normal("]");
991
- if (name !== module.id) colors.normal(" ");
992
- }
993
- if (name !== module.id) {
994
- colors.bold(name);
995
- }
996
- processModuleAttributes(module);
997
- newline();
998
- processModuleContent(module, contentPrefix);
999
- }
1000
- if (obj.filteredModules > 0) {
1001
- colors.normal(prefix);
1002
- colors.normal(" ");
1003
- if (obj.modules.length > 0) colors.normal(" + ");
1004
- colors.normal(obj.filteredModules);
1005
- if (obj.modules.length > 0) colors.normal(" hidden");
1006
- colors.normal(obj.filteredModules !== 1 ? " modules" : " module");
1007
- newline();
1008
- }
1009
- }
1010
- };
1011
-
1012
- if (obj.chunks) {
1013
- for (const chunk of obj.chunks) {
1014
- colors.normal("chunk ");
1015
- if (chunk.id < 1000) colors.normal(" ");
1016
- if (chunk.id < 100) colors.normal(" ");
1017
- if (chunk.id < 10) colors.normal(" ");
1018
- colors.normal("{");
1019
- colors.yellow(chunk.id);
1020
- colors.normal("} ");
1021
- colors.green(chunk.files.join(", "));
1022
- if (chunk.names && chunk.names.length > 0) {
1023
- colors.normal(" (");
1024
- colors.normal(chunk.names.join(", "));
1025
- colors.normal(")");
1026
- }
1027
- colors.normal(" ");
1028
- colors.normal(SizeFormatHelpers.formatSize(chunk.size));
1029
- for (const id of chunk.parents) {
1030
- colors.normal(" <{");
1031
- colors.yellow(id);
1032
- colors.normal("}>");
1033
- }
1034
- for (const id of chunk.siblings) {
1035
- colors.normal(" ={");
1036
- colors.yellow(id);
1037
- colors.normal("}=");
1038
- }
1039
- for (const id of chunk.children) {
1040
- colors.normal(" >{");
1041
- colors.yellow(id);
1042
- colors.normal("}<");
1043
- }
1044
- if (chunk.entry) {
1045
- colors.yellow(" [entry]");
1046
- } else if (chunk.initial) {
1047
- colors.yellow(" [initial]");
1048
- }
1049
- if (chunk.rendered) {
1050
- colors.green(" [rendered]");
1051
- }
1052
- if (chunk.recorded) {
1053
- colors.green(" [recorded]");
1054
- }
1055
- if (chunk.reason) {
1056
- colors.yellow(` ${chunk.reason}`);
1057
- }
1058
- newline();
1059
- if (chunk.origins) {
1060
- for (const origin of chunk.origins) {
1061
- colors.normal(" > ");
1062
- if (origin.reasons && origin.reasons.length) {
1063
- colors.yellow(origin.reasons.join(" "));
1064
- colors.normal(" ");
1065
- }
1066
- if (origin.request) {
1067
- colors.normal(origin.request);
1068
- colors.normal(" ");
1069
- }
1070
- if (origin.module) {
1071
- colors.normal("[");
1072
- colors.normal(origin.moduleId);
1073
- colors.normal("] ");
1074
- const module = modulesByIdentifier[`$${origin.module}`];
1075
- if (module) {
1076
- colors.bold(module.name);
1077
- colors.normal(" ");
1078
- }
1079
- }
1080
- if (origin.loc) {
1081
- colors.normal(origin.loc);
1082
- }
1083
- newline();
1084
- }
1085
- }
1086
- processModulesList(chunk, " ");
1087
- }
1088
- }
1089
-
1090
- processModulesList(obj, "");
1091
-
1092
- if (obj._showWarnings && obj.warnings) {
1093
- for (const warning of obj.warnings) {
1094
- newline();
1095
- colors.yellow(`WARNING in ${warning}`);
1096
- newline();
1097
- }
1098
- }
1099
- if (obj._showErrors && obj.errors) {
1100
- for (const error of obj.errors) {
1101
- newline();
1102
- colors.red(`ERROR in ${error}`);
1103
- newline();
1104
- }
1105
- }
1106
- if (obj.children) {
1107
- for (const child of obj.children) {
1108
- const childString = Stats.jsonToString(child, useColors);
1109
- if (childString) {
1110
- if (child.name) {
1111
- colors.normal("Child ");
1112
- colors.bold(child.name);
1113
- colors.normal(":");
1114
- } else {
1115
- colors.normal("Child");
1116
- }
1117
- newline();
1118
- buf.push(" ");
1119
- buf.push(childString.replace(/\n/g, "\n "));
1120
- newline();
1121
- }
1122
- }
1123
- }
1124
- if (obj.needAdditionalPass) {
1125
- colors.yellow(
1126
- "Compilation needs an additional pass and will compile again."
1127
- );
1128
- }
1129
-
1130
- while (buf[buf.length - 1] === "\n") buf.pop();
1131
- return buf.join("");
1132
- }
1133
-
1134
- static presetToOptions(name) {
1135
- // Accepted values: none, errors-only, minimal, normal, detailed, verbose
1136
- // Any other falsy value will behave as 'none', truthy values as 'normal'
1137
- const pn =
1138
- (typeof name === "string" && name.toLowerCase()) || name || "none";
1139
- switch (pn) {
1140
- case "none":
1141
- return {
1142
- all: false
1143
- };
1144
- case "verbose":
1145
- return {
1146
- entrypoints: true,
1147
- modules: false,
1148
- chunks: true,
1149
- chunkModules: true,
1150
- chunkOrigins: true,
1151
- depth: true,
1152
- env: true,
1153
- reasons: true,
1154
- usedExports: true,
1155
- providedExports: true,
1156
- optimizationBailout: true,
1157
- errorDetails: true,
1158
- publicPath: true,
1159
- exclude: () => false,
1160
- maxModules: Infinity
1161
- };
1162
- case "detailed":
1163
- return {
1164
- entrypoints: true,
1165
- chunks: true,
1166
- chunkModules: false,
1167
- chunkOrigins: true,
1168
- depth: true,
1169
- usedExports: true,
1170
- providedExports: true,
1171
- optimizationBailout: true,
1172
- errorDetails: true,
1173
- publicPath: true,
1174
- exclude: () => false,
1175
- maxModules: Infinity
1176
- };
1177
- case "minimal":
1178
- return {
1179
- all: false,
1180
- modules: true,
1181
- maxModules: 0,
1182
- errors: true,
1183
- warnings: true
1184
- };
1185
- case "errors-only":
1186
- return {
1187
- all: false,
1188
- errors: true,
1189
- moduleTrace: true
1190
- };
1191
- default:
1192
- return {};
1193
- }
1194
- }
1195
-
1196
- static getChildOptions(options, idx) {
1197
- let innerOptions;
1198
- if (Array.isArray(options.children)) {
1199
- if (idx < options.children.length) innerOptions = options.children[idx];
1200
- } else if (typeof options.children === "object" && options.children) {
1201
- innerOptions = options.children;
1202
- }
1203
- if (typeof innerOptions === "boolean" || typeof innerOptions === "string")
1204
- innerOptions = Stats.presetToOptions(innerOptions);
1205
- if (!innerOptions) return options;
1206
- const childOptions = Object.assign({}, options);
1207
- delete childOptions.children; // do not inherit children
1208
- return Object.assign(childOptions, innerOptions);
1209
- }
1210
- }
1211
-
1212
- module.exports = Stats;
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+ "use strict";
6
+
7
+ const RequestShortener = require("./RequestShortener");
8
+ const SizeFormatHelpers = require("./SizeFormatHelpers");
9
+ const formatLocation = require("./formatLocation");
10
+ const identifierUtils = require("./util/identifier");
11
+
12
+ const optionsOrFallback = (...args) => {
13
+ let optionValues = [];
14
+ optionValues.push(...args);
15
+ return optionValues.find(optionValue => typeof optionValue !== "undefined");
16
+ };
17
+
18
+ class Stats {
19
+ constructor(compilation) {
20
+ this.compilation = compilation;
21
+ this.hash = compilation.hash;
22
+ this.startTime = undefined;
23
+ this.endTime = undefined;
24
+ }
25
+
26
+ static filterWarnings(warnings, warningsFilter) {
27
+ // we dont have anything to filter so all warnings can be shown
28
+ if (!warningsFilter) {
29
+ return warnings;
30
+ }
31
+
32
+ // create a chain of filters
33
+ // if they return "true" a warning should be suppressed
34
+ const normalizedWarningsFilters = [].concat(warningsFilter).map(filter => {
35
+ if (typeof filter === "string") {
36
+ return warning => warning.includes(filter);
37
+ }
38
+
39
+ if (filter instanceof RegExp) {
40
+ return warning => filter.test(warning);
41
+ }
42
+
43
+ if (typeof filter === "function") {
44
+ return filter;
45
+ }
46
+
47
+ throw new Error(
48
+ `Can only filter warnings with Strings or RegExps. (Given: ${filter})`
49
+ );
50
+ });
51
+ return warnings.filter(warning => {
52
+ return !normalizedWarningsFilters.some(check => check(warning));
53
+ });
54
+ }
55
+
56
+ hasWarnings() {
57
+ return (
58
+ this.compilation.warnings.length > 0 ||
59
+ this.compilation.children.some(child => child.getStats().hasWarnings())
60
+ );
61
+ }
62
+
63
+ hasErrors() {
64
+ return (
65
+ this.compilation.errors.length > 0 ||
66
+ this.compilation.children.some(child => child.getStats().hasErrors())
67
+ );
68
+ }
69
+
70
+ // remove a prefixed "!" that can be specified to reverse sort order
71
+ normalizeFieldKey(field) {
72
+ if (field[0] === "!") {
73
+ return field.substr(1);
74
+ }
75
+ return field;
76
+ }
77
+
78
+ // if a field is prefixed by a "!" reverse sort order
79
+ sortOrderRegular(field) {
80
+ if (field[0] === "!") {
81
+ return false;
82
+ }
83
+ return true;
84
+ }
85
+
86
+ toJson(options, forToString) {
87
+ if (typeof options === "boolean" || typeof options === "string") {
88
+ options = Stats.presetToOptions(options);
89
+ } else if (!options) {
90
+ options = {};
91
+ }
92
+
93
+ const optionOrLocalFallback = (v, def) =>
94
+ typeof v !== "undefined"
95
+ ? v
96
+ : typeof options.all !== "undefined" ? options.all : def;
97
+
98
+ const testAgainstGivenOption = item => {
99
+ if (typeof item === "string") {
100
+ const regExp = new RegExp(
101
+ `[\\\\/]${item.replace(
102
+ /[-[\]{}()*+?.\\^$|]/g,
103
+ "\\$&"
104
+ )}([\\\\/]|$|!|\\?)`
105
+ ); // eslint-disable-line no-useless-escape
106
+ return ident => regExp.test(ident);
107
+ }
108
+ if (item && typeof item === "object" && typeof item.test === "function")
109
+ return ident => item.test(ident);
110
+ if (typeof item === "function") return item;
111
+ if (typeof item === "boolean") return () => item;
112
+ };
113
+
114
+ const compilation = this.compilation;
115
+ const context = optionsOrFallback(
116
+ options.context,
117
+ compilation.compiler.context
118
+ );
119
+ const requestShortener =
120
+ compilation.compiler.context === context
121
+ ? compilation.requestShortener
122
+ : new RequestShortener(context);
123
+ const showPerformance = optionOrLocalFallback(options.performance, true);
124
+ const showHash = optionOrLocalFallback(options.hash, true);
125
+ const showEnv = optionOrLocalFallback(options.env, false);
126
+ const showVersion = optionOrLocalFallback(options.version, true);
127
+ const showTimings = optionOrLocalFallback(options.timings, true);
128
+ const showBuiltAt = optionOrLocalFallback(options.builtAt, true);
129
+ const showAssets = optionOrLocalFallback(options.assets, true);
130
+ const showEntrypoints = optionOrLocalFallback(options.entrypoints, true);
131
+ const showChunks = optionOrLocalFallback(options.chunks, !forToString);
132
+ const showChunkModules = optionOrLocalFallback(options.chunkModules, true);
133
+ const showChunkOrigins = optionOrLocalFallback(
134
+ options.chunkOrigins,
135
+ !forToString
136
+ );
137
+ const showModules = optionOrLocalFallback(options.modules, true);
138
+ const showNestedModules = optionOrLocalFallback(
139
+ options.nestedModules,
140
+ true
141
+ );
142
+ const showModuleAssets = optionOrLocalFallback(
143
+ options.moduleAssets,
144
+ !forToString
145
+ );
146
+ const showDepth = optionOrLocalFallback(options.depth, !forToString);
147
+ const showCachedModules = optionOrLocalFallback(options.cached, true);
148
+ const showCachedAssets = optionOrLocalFallback(options.cachedAssets, true);
149
+ const showReasons = optionOrLocalFallback(options.reasons, !forToString);
150
+ const showUsedExports = optionOrLocalFallback(
151
+ options.usedExports,
152
+ !forToString
153
+ );
154
+ const showProvidedExports = optionOrLocalFallback(
155
+ options.providedExports,
156
+ !forToString
157
+ );
158
+ const showOptimizationBailout = optionOrLocalFallback(
159
+ options.optimizationBailout,
160
+ !forToString
161
+ );
162
+ const showChildren = optionOrLocalFallback(options.children, true);
163
+ const showSource = optionOrLocalFallback(options.source, !forToString);
164
+ const showModuleTrace = optionOrLocalFallback(options.moduleTrace, true);
165
+ const showErrors = optionOrLocalFallback(options.errors, true);
166
+ const showErrorDetails = optionOrLocalFallback(
167
+ options.errorDetails,
168
+ !forToString
169
+ );
170
+ const showWarnings = optionOrLocalFallback(options.warnings, true);
171
+ const warningsFilter = optionsOrFallback(options.warningsFilter, null);
172
+ const showPublicPath = optionOrLocalFallback(
173
+ options.publicPath,
174
+ !forToString
175
+ );
176
+ const excludeModules = []
177
+ .concat(optionsOrFallback(options.excludeModules, options.exclude, []))
178
+ .map(testAgainstGivenOption);
179
+ const excludeAssets = []
180
+ .concat(optionsOrFallback(options.excludeAssets, []))
181
+ .map(testAgainstGivenOption);
182
+ const maxModules = optionsOrFallback(
183
+ options.maxModules,
184
+ forToString ? 15 : Infinity
185
+ );
186
+ const sortModules = optionsOrFallback(options.modulesSort, "id");
187
+ const sortChunks = optionsOrFallback(options.chunksSort, "id");
188
+ const sortAssets = optionsOrFallback(options.assetsSort, "");
189
+ const showOutputPath = optionOrLocalFallback(
190
+ options.outputPath,
191
+ !forToString
192
+ );
193
+
194
+ if (!showCachedModules) {
195
+ excludeModules.push((ident, module) => !module.built);
196
+ }
197
+
198
+ const createModuleFilter = () => {
199
+ let i = 0;
200
+ return module => {
201
+ if (excludeModules.length > 0) {
202
+ const ident = requestShortener.shorten(module.resource);
203
+ const excluded = excludeModules.some(fn => fn(ident, module));
204
+ if (excluded) return false;
205
+ }
206
+ const result = i < maxModules;
207
+ i++;
208
+ return result;
209
+ };
210
+ };
211
+
212
+ const createAssetFilter = () => {
213
+ return asset => {
214
+ if (excludeAssets.length > 0) {
215
+ const ident = asset.name;
216
+ const excluded = excludeAssets.some(fn => fn(ident, asset));
217
+ if (excluded) return false;
218
+ }
219
+ return showCachedAssets || asset.emitted;
220
+ };
221
+ };
222
+
223
+ const sortByFieldAndOrder = (fieldKey, a, b) => {
224
+ if (a[fieldKey] === null && b[fieldKey] === null) return 0;
225
+ if (a[fieldKey] === null) return 1;
226
+ if (b[fieldKey] === null) return -1;
227
+ if (a[fieldKey] === b[fieldKey]) return 0;
228
+ return a[fieldKey] < b[fieldKey] ? -1 : 1;
229
+ };
230
+
231
+ const sortByField = field => (a, b) => {
232
+ if (!field) {
233
+ return 0;
234
+ }
235
+
236
+ const fieldKey = this.normalizeFieldKey(field);
237
+
238
+ // if a field is prefixed with a "!" the sort is reversed!
239
+ const sortIsRegular = this.sortOrderRegular(field);
240
+
241
+ return sortByFieldAndOrder(
242
+ fieldKey,
243
+ sortIsRegular ? a : b,
244
+ sortIsRegular ? b : a
245
+ );
246
+ };
247
+
248
+ const formatError = e => {
249
+ let text = "";
250
+ if (typeof e === "string")
251
+ e = {
252
+ message: e
253
+ };
254
+ if (e.chunk) {
255
+ text += `chunk ${e.chunk.name || e.chunk.id}${
256
+ e.chunk.hasRuntime()
257
+ ? " [entry]"
258
+ : e.chunk.canBeInitial() ? " [initial]" : ""
259
+ }\n`;
260
+ }
261
+ if (e.file) {
262
+ text += `${e.file}\n`;
263
+ }
264
+ if (
265
+ e.module &&
266
+ e.module.readableIdentifier &&
267
+ typeof e.module.readableIdentifier === "function"
268
+ ) {
269
+ text += `${e.module.readableIdentifier(requestShortener)}\n`;
270
+ }
271
+ text += e.message;
272
+ if (showErrorDetails && e.details) text += `\n${e.details}`;
273
+ if (showErrorDetails && e.missing)
274
+ text += e.missing.map(item => `\n[${item}]`).join("");
275
+ if (showModuleTrace && e.origin) {
276
+ text += `\n @ ${e.origin.readableIdentifier(requestShortener)}`;
277
+ if (typeof e.originLoc === "object") {
278
+ const locInfo = formatLocation(e.originLoc);
279
+ if (locInfo) text += ` ${locInfo}`;
280
+ }
281
+ if (e.dependencies) {
282
+ for (const dep of e.dependencies) {
283
+ if (!dep.loc) continue;
284
+ if (typeof dep.loc === "string") continue;
285
+ const locInfo = formatLocation(dep.loc);
286
+ if (!locInfo) continue;
287
+ text += ` ${locInfo}`;
288
+ }
289
+ }
290
+ let current = e.origin;
291
+ while (current.issuer) {
292
+ current = current.issuer;
293
+ text += `\n @ ${current.readableIdentifier(requestShortener)}`;
294
+ }
295
+ }
296
+ return text;
297
+ };
298
+
299
+ const obj = {
300
+ errors: compilation.errors.map(formatError),
301
+ warnings: Stats.filterWarnings(
302
+ compilation.warnings.map(formatError),
303
+ warningsFilter
304
+ )
305
+ };
306
+
307
+ //We just hint other renderers since actually omitting
308
+ //errors/warnings from the JSON would be kind of weird.
309
+ Object.defineProperty(obj, "_showWarnings", {
310
+ value: showWarnings,
311
+ enumerable: false
312
+ });
313
+ Object.defineProperty(obj, "_showErrors", {
314
+ value: showErrors,
315
+ enumerable: false
316
+ });
317
+
318
+ if (showVersion) {
319
+ obj.version = require("../package.json").version;
320
+ }
321
+
322
+ if (showHash) obj.hash = this.hash;
323
+ if (showTimings && this.startTime && this.endTime) {
324
+ obj.time = this.endTime - this.startTime;
325
+ }
326
+
327
+ if (showBuiltAt && this.endTime) {
328
+ obj.builtAt = this.endTime;
329
+ }
330
+
331
+ if (showEnv && options._env) {
332
+ obj.env = options._env;
333
+ }
334
+
335
+ if (compilation.needAdditionalPass) {
336
+ obj.needAdditionalPass = true;
337
+ }
338
+ if (showPublicPath) {
339
+ obj.publicPath = this.compilation.mainTemplate.getPublicPath({
340
+ hash: this.compilation.hash
341
+ });
342
+ }
343
+ if (showOutputPath) {
344
+ obj.outputPath = this.compilation.mainTemplate.outputOptions.path;
345
+ }
346
+ if (showAssets) {
347
+ const assetsByFile = {};
348
+ const compilationAssets = Object.keys(compilation.assets);
349
+ obj.assetsByChunkName = {};
350
+ obj.assets = compilationAssets
351
+ .map(asset => {
352
+ const obj = {
353
+ name: asset,
354
+ size: compilation.assets[asset].size(),
355
+ chunks: [],
356
+ chunkNames: [],
357
+ emitted: compilation.assets[asset].emitted
358
+ };
359
+
360
+ if (showPerformance) {
361
+ obj.isOverSizeLimit = compilation.assets[asset].isOverSizeLimit;
362
+ }
363
+
364
+ assetsByFile[asset] = obj;
365
+ return obj;
366
+ })
367
+ .filter(createAssetFilter());
368
+ obj.filteredAssets = compilationAssets.length - obj.assets.length;
369
+
370
+ for (const chunk of compilation.chunks) {
371
+ for (const asset of chunk.files) {
372
+ if (assetsByFile[asset]) {
373
+ for (const id of chunk.ids) {
374
+ assetsByFile[asset].chunks.push(id);
375
+ }
376
+ if (chunk.name) {
377
+ assetsByFile[asset].chunkNames.push(chunk.name);
378
+ if (obj.assetsByChunkName[chunk.name])
379
+ obj.assetsByChunkName[chunk.name] = []
380
+ .concat(obj.assetsByChunkName[chunk.name])
381
+ .concat([asset]);
382
+ else obj.assetsByChunkName[chunk.name] = asset;
383
+ }
384
+ }
385
+ }
386
+ }
387
+ obj.assets.sort(sortByField(sortAssets));
388
+ }
389
+
390
+ if (showEntrypoints) {
391
+ obj.entrypoints = {};
392
+ for (const keyValuePair of compilation.entrypoints) {
393
+ const name = keyValuePair[0];
394
+ const ep = keyValuePair[1];
395
+ obj.entrypoints[name] = {
396
+ chunks: ep.chunks.map(c => c.id),
397
+ assets: ep.chunks.reduce(
398
+ (array, c) => array.concat(c.files || []),
399
+ []
400
+ )
401
+ };
402
+ if (showPerformance) {
403
+ obj.entrypoints[name].isOverSizeLimit = ep.isOverSizeLimit;
404
+ }
405
+ }
406
+ }
407
+
408
+ const fnModule = module => {
409
+ const path = [];
410
+ let current = module;
411
+ while (current.issuer) {
412
+ path.push((current = current.issuer));
413
+ }
414
+ path.reverse();
415
+ const obj = {
416
+ id: module.id,
417
+ identifier: module.identifier(),
418
+ name: module.readableIdentifier(requestShortener),
419
+ index: module.index,
420
+ index2: module.index2,
421
+ size: module.size(),
422
+ cacheable: module.buildInfo.cacheable,
423
+ built: !!module.built,
424
+ optional: module.optional,
425
+ prefetched: module.prefetched,
426
+ chunks: Array.from(module.chunksIterable, chunk => chunk.id),
427
+ issuer: module.issuer && module.issuer.identifier(),
428
+ issuerId: module.issuer && module.issuer.id,
429
+ issuerName:
430
+ module.issuer && module.issuer.readableIdentifier(requestShortener),
431
+ issuerPath:
432
+ module.issuer &&
433
+ path.map(module => ({
434
+ id: module.id,
435
+ identifier: module.identifier(),
436
+ name: module.readableIdentifier(requestShortener),
437
+ profile: module.profile
438
+ })),
439
+ profile: module.profile,
440
+ failed: !!module.error,
441
+ errors: module.errors ? module.errors.length : 0,
442
+ warnings: module.warnings ? module.warnings.length : 0
443
+ };
444
+ if (showModuleAssets) {
445
+ obj.assets = Object.keys(module.buildInfo.assets || {});
446
+ }
447
+ if (showReasons) {
448
+ obj.reasons = module.reasons
449
+ .map(reason => {
450
+ const obj = {
451
+ moduleId: reason.module ? reason.module.id : null,
452
+ moduleIdentifier: reason.module
453
+ ? reason.module.identifier()
454
+ : null,
455
+ module: reason.module
456
+ ? reason.module.readableIdentifier(requestShortener)
457
+ : null,
458
+ moduleName: reason.module
459
+ ? reason.module.readableIdentifier(requestShortener)
460
+ : null,
461
+ type: reason.dependency ? reason.dependency.type : null,
462
+ userRequest: reason.dependency
463
+ ? reason.dependency.userRequest
464
+ : null
465
+ };
466
+ if (reason.dependency) {
467
+ const locInfo = formatLocation(reason.dependency.loc);
468
+ if (locInfo) obj.loc = locInfo;
469
+ }
470
+ return obj;
471
+ })
472
+ .sort((a, b) => a.moduleId - b.moduleId);
473
+ }
474
+ if (showUsedExports) {
475
+ if (module.used === true) obj.usedExports = module.usedExports;
476
+ else if (module.used === false) obj.usedExports = false;
477
+ }
478
+ if (showProvidedExports) {
479
+ obj.providedExports = Array.isArray(module.buildMeta.providedExports)
480
+ ? module.buildMeta.providedExports
481
+ : null;
482
+ }
483
+ if (showOptimizationBailout) {
484
+ obj.optimizationBailout = module.optimizationBailout.map(item => {
485
+ if (typeof item === "function") return item(requestShortener);
486
+ return item;
487
+ });
488
+ }
489
+ if (showDepth) {
490
+ obj.depth = module.depth;
491
+ }
492
+ if (showNestedModules) {
493
+ if (module.modules) {
494
+ const modules = module.modules;
495
+ obj.modules = modules
496
+ .sort(sortByField("depth"))
497
+ .filter(createModuleFilter())
498
+ .map(fnModule);
499
+ obj.filteredModules = modules.length - obj.modules.length;
500
+ obj.modules.sort(sortByField(sortModules));
501
+ }
502
+ }
503
+ if (showSource && module._source) {
504
+ obj.source = module._source.source();
505
+ }
506
+ return obj;
507
+ };
508
+ if (showChunks) {
509
+ obj.chunks = compilation.chunks.map(chunk => {
510
+ const parents = new Set();
511
+ const children = new Set();
512
+ const siblings = new Set();
513
+ for (const chunkGroup of chunk.groupsIterable) {
514
+ for (const parentGroup of chunkGroup.parentsIterable) {
515
+ for (const chunk of parentGroup.chunks) {
516
+ parents.add(chunk.id);
517
+ }
518
+ }
519
+ for (const childGroup of chunkGroup.childrenIterable) {
520
+ for (const chunk of childGroup.chunks) {
521
+ children.add(chunk.id);
522
+ }
523
+ }
524
+ for (const sibling of chunkGroup.chunks) {
525
+ if (sibling !== chunk) siblings.add(sibling.id);
526
+ }
527
+ }
528
+ const obj = {
529
+ id: chunk.id,
530
+ rendered: chunk.rendered,
531
+ initial: chunk.canBeInitial(),
532
+ entry: chunk.hasRuntime(),
533
+ recorded: chunk.recorded,
534
+ reason: chunk.chunkReason,
535
+ size: chunk.modulesSize(),
536
+ names: chunk.name ? [chunk.name] : [],
537
+ files: chunk.files.slice(),
538
+ hash: chunk.renderedHash,
539
+ siblings: Array.from(siblings).sort(),
540
+ parents: Array.from(parents).sort(),
541
+ children: Array.from(children).sort()
542
+ };
543
+ if (showChunkModules) {
544
+ obj.modules = chunk
545
+ .getModules()
546
+ .sort(sortByField("depth"))
547
+ .filter(createModuleFilter())
548
+ .map(fnModule);
549
+ obj.filteredModules = chunk.getNumberOfModules() - obj.modules.length;
550
+ obj.modules.sort(sortByField(sortModules));
551
+ }
552
+ if (showChunkOrigins) {
553
+ obj.origins = Array.from(chunk.groupsIterable, g => g.origins)
554
+ .reduce((a, b) => a.concat(b), [])
555
+ .map(origin => ({
556
+ moduleId: origin.module ? origin.module.id : undefined,
557
+ module: origin.module ? origin.module.identifier() : "",
558
+ moduleIdentifier: origin.module ? origin.module.identifier() : "",
559
+ moduleName: origin.module
560
+ ? origin.module.readableIdentifier(requestShortener)
561
+ : "",
562
+ loc: formatLocation(origin.loc),
563
+ request: origin.request,
564
+ reasons: origin.reasons || []
565
+ }))
566
+ .sort((a, b) => {
567
+ if (
568
+ typeof a.moduleId === "number" &&
569
+ typeof b.moduleId !== "number"
570
+ )
571
+ return 1;
572
+ if (
573
+ typeof a.moduleId !== "number" &&
574
+ typeof b.moduleId === "number"
575
+ )
576
+ return -1;
577
+ if (
578
+ typeof a.moduleId === "number" &&
579
+ typeof b.moduleId === "number"
580
+ ) {
581
+ const diffId = a.moduleId - b.moduleId;
582
+ if (diffId !== 0) return diffId;
583
+ }
584
+ if (a.loc < b.loc) return -1;
585
+ if (a.loc > b.loc) return 1;
586
+ return 0;
587
+ });
588
+ }
589
+ return obj;
590
+ });
591
+ obj.chunks.sort(sortByField(sortChunks));
592
+ }
593
+ if (showModules) {
594
+ obj.modules = compilation.modules
595
+ .slice()
596
+ .sort(sortByField("depth"))
597
+ .filter(createModuleFilter())
598
+ .map(fnModule);
599
+ obj.filteredModules = compilation.modules.length - obj.modules.length;
600
+ obj.modules.sort(sortByField(sortModules));
601
+ }
602
+ if (showChildren) {
603
+ obj.children = compilation.children.map((child, idx) => {
604
+ const childOptions = Stats.getChildOptions(options, idx);
605
+ const obj = new Stats(child).toJson(childOptions, forToString);
606
+ delete obj.hash;
607
+ delete obj.version;
608
+ if (child.name)
609
+ obj.name = identifierUtils.makePathsRelative(
610
+ context,
611
+ child.name,
612
+ compilation.cache
613
+ );
614
+ return obj;
615
+ });
616
+ }
617
+
618
+ return obj;
619
+ }
620
+
621
+ toString(options) {
622
+ if (typeof options === "boolean" || typeof options === "string") {
623
+ options = Stats.presetToOptions(options);
624
+ } else if (!options) {
625
+ options = {};
626
+ }
627
+
628
+ const useColors = optionsOrFallback(options.colors, false);
629
+
630
+ const obj = this.toJson(options, true);
631
+
632
+ return Stats.jsonToString(obj, useColors);
633
+ }
634
+
635
+ static jsonToString(obj, useColors) {
636
+ const buf = [];
637
+
638
+ const defaultColors = {
639
+ bold: "\u001b[1m",
640
+ yellow: "\u001b[1m\u001b[33m",
641
+ red: "\u001b[1m\u001b[31m",
642
+ green: "\u001b[1m\u001b[32m",
643
+ cyan: "\u001b[1m\u001b[36m",
644
+ magenta: "\u001b[1m\u001b[35m"
645
+ };
646
+
647
+ const colors = Object.keys(defaultColors).reduce(
648
+ (obj, color) => {
649
+ obj[color] = str => {
650
+ if (useColors) {
651
+ buf.push(
652
+ useColors === true || useColors[color] === undefined
653
+ ? defaultColors[color]
654
+ : useColors[color]
655
+ );
656
+ }
657
+ buf.push(str);
658
+ if (useColors) {
659
+ buf.push("\u001b[39m\u001b[22m");
660
+ }
661
+ };
662
+ return obj;
663
+ },
664
+ {
665
+ normal: str => buf.push(str)
666
+ }
667
+ );
668
+
669
+ const coloredTime = time => {
670
+ let times = [800, 400, 200, 100];
671
+ if (obj.time) {
672
+ times = [obj.time / 2, obj.time / 4, obj.time / 8, obj.time / 16];
673
+ }
674
+ if (time < times[3]) colors.normal(`${time}ms`);
675
+ else if (time < times[2]) colors.bold(`${time}ms`);
676
+ else if (time < times[1]) colors.green(`${time}ms`);
677
+ else if (time < times[0]) colors.yellow(`${time}ms`);
678
+ else colors.red(`${time}ms`);
679
+ };
680
+
681
+ const newline = () => buf.push("\n");
682
+
683
+ const getText = (arr, row, col) => {
684
+ return arr[row][col].value;
685
+ };
686
+
687
+ const table = (array, align, splitter) => {
688
+ const rows = array.length;
689
+ const cols = array[0].length;
690
+ const colSizes = new Array(cols);
691
+ for (let col = 0; col < cols; col++) colSizes[col] = 0;
692
+ for (let row = 0; row < rows; row++) {
693
+ for (let col = 0; col < cols; col++) {
694
+ const value = `${getText(array, row, col)}`;
695
+ if (value.length > colSizes[col]) {
696
+ colSizes[col] = value.length;
697
+ }
698
+ }
699
+ }
700
+ for (let row = 0; row < rows; row++) {
701
+ for (let col = 0; col < cols; col++) {
702
+ const format = array[row][col].color;
703
+ const value = `${getText(array, row, col)}`;
704
+ let l = value.length;
705
+ if (align[col] === "l") format(value);
706
+ for (; l < colSizes[col] && col !== cols - 1; l++) colors.normal(" ");
707
+ if (align[col] === "r") format(value);
708
+ if (col + 1 < cols && colSizes[col] !== 0)
709
+ colors.normal(splitter || " ");
710
+ }
711
+ newline();
712
+ }
713
+ };
714
+
715
+ const getAssetColor = (asset, defaultColor) => {
716
+ if (asset.isOverSizeLimit) {
717
+ return colors.yellow;
718
+ }
719
+
720
+ return defaultColor;
721
+ };
722
+
723
+ if (obj.hash) {
724
+ colors.normal("Hash: ");
725
+ colors.bold(obj.hash);
726
+ newline();
727
+ }
728
+ if (obj.version) {
729
+ colors.normal("Version: webpack ");
730
+ colors.bold(obj.version);
731
+ newline();
732
+ }
733
+ if (typeof obj.time === "number") {
734
+ colors.normal("Time: ");
735
+ colors.bold(obj.time);
736
+ colors.normal("ms");
737
+ newline();
738
+ }
739
+ if (typeof obj.builtAt === "number") {
740
+ const builtAtDate = new Date(obj.builtAt);
741
+ colors.normal("Built at: ");
742
+ colors.normal(
743
+ builtAtDate.toLocaleDateString({
744
+ day: "2-digit",
745
+ month: "2-digit",
746
+ year: "numeric"
747
+ })
748
+ );
749
+ colors.normal(" ");
750
+ colors.bold(builtAtDate.toLocaleTimeString());
751
+ newline();
752
+ }
753
+ if (obj.env) {
754
+ colors.normal("Environment (--env): ");
755
+ colors.bold(JSON.stringify(obj.env, null, 2));
756
+ newline();
757
+ }
758
+ if (obj.publicPath) {
759
+ colors.normal("PublicPath: ");
760
+ colors.bold(obj.publicPath);
761
+ newline();
762
+ }
763
+
764
+ if (obj.assets && obj.assets.length > 0) {
765
+ const t = [
766
+ [
767
+ {
768
+ value: "Asset",
769
+ color: colors.bold
770
+ },
771
+ {
772
+ value: "Size",
773
+ color: colors.bold
774
+ },
775
+ {
776
+ value: "Chunks",
777
+ color: colors.bold
778
+ },
779
+ {
780
+ value: "",
781
+ color: colors.bold
782
+ },
783
+ {
784
+ value: "",
785
+ color: colors.bold
786
+ },
787
+ {
788
+ value: "Chunk Names",
789
+ color: colors.bold
790
+ }
791
+ ]
792
+ ];
793
+ for (const asset of obj.assets) {
794
+ t.push([
795
+ {
796
+ value: asset.name,
797
+ color: getAssetColor(asset, colors.green)
798
+ },
799
+ {
800
+ value: SizeFormatHelpers.formatSize(asset.size),
801
+ color: getAssetColor(asset, colors.normal)
802
+ },
803
+ {
804
+ value: asset.chunks.join(", "),
805
+ color: colors.bold
806
+ },
807
+ {
808
+ value: asset.emitted ? "[emitted]" : "",
809
+ color: colors.green
810
+ },
811
+ {
812
+ value: asset.isOverSizeLimit ? "[big]" : "",
813
+ color: getAssetColor(asset, colors.normal)
814
+ },
815
+ {
816
+ value: asset.chunkNames.join(", "),
817
+ color: colors.normal
818
+ }
819
+ ]);
820
+ }
821
+ table(t, "rrrlll");
822
+ }
823
+ if (obj.filteredAssets > 0) {
824
+ colors.normal(" ");
825
+ if (obj.assets.length > 0) colors.normal("+ ");
826
+ colors.normal(obj.filteredAssets);
827
+ if (obj.assets.length > 0) colors.normal(" hidden");
828
+ colors.normal(obj.filteredAssets !== 1 ? " assets" : " asset");
829
+ newline();
830
+ }
831
+ if (obj.entrypoints) {
832
+ for (const name of Object.keys(obj.entrypoints)) {
833
+ const ep = obj.entrypoints[name];
834
+ colors.normal("Entrypoint ");
835
+ colors.bold(name);
836
+ if (ep.isOverSizeLimit) {
837
+ colors.normal(" ");
838
+ colors.yellow("[big]");
839
+ }
840
+ colors.normal(" =");
841
+ for (const asset of ep.assets) {
842
+ colors.normal(" ");
843
+ colors.green(asset);
844
+ }
845
+ newline();
846
+ }
847
+ }
848
+ const modulesByIdentifier = {};
849
+ if (obj.modules) {
850
+ for (const module of obj.modules) {
851
+ modulesByIdentifier[`$${module.identifier}`] = module;
852
+ }
853
+ } else if (obj.chunks) {
854
+ for (const chunk of obj.chunks) {
855
+ if (chunk.modules) {
856
+ for (const module of chunk.modules) {
857
+ modulesByIdentifier[`$${module.identifier}`] = module;
858
+ }
859
+ }
860
+ }
861
+ }
862
+
863
+ const processModuleAttributes = module => {
864
+ colors.normal(" ");
865
+ colors.normal(SizeFormatHelpers.formatSize(module.size));
866
+ if (module.chunks) {
867
+ for (const chunk of module.chunks) {
868
+ colors.normal(" {");
869
+ colors.yellow(chunk);
870
+ colors.normal("}");
871
+ }
872
+ }
873
+ if (typeof module.depth === "number") {
874
+ colors.normal(` [depth ${module.depth}]`);
875
+ }
876
+ if (module.cacheable === false) {
877
+ colors.red(" [not cacheable]");
878
+ }
879
+ if (module.optional) {
880
+ colors.yellow(" [optional]");
881
+ }
882
+ if (module.built) {
883
+ colors.green(" [built]");
884
+ }
885
+ if (module.assets && module.assets.length) {
886
+ colors.magenta(
887
+ ` [${module.assets.length} asset${
888
+ module.assets.length === 1 ? "" : "s"
889
+ }]`
890
+ );
891
+ }
892
+ if (module.prefetched) {
893
+ colors.magenta(" [prefetched]");
894
+ }
895
+ if (module.failed) colors.red(" [failed]");
896
+ if (module.warnings)
897
+ colors.yellow(
898
+ ` [${module.warnings} warning${module.warnings === 1 ? "" : "s"}]`
899
+ );
900
+ if (module.errors)
901
+ colors.red(
902
+ ` [${module.errors} error${module.errors === 1 ? "" : "s"}]`
903
+ );
904
+ };
905
+
906
+ const processModuleContent = (module, prefix) => {
907
+ if (Array.isArray(module.providedExports)) {
908
+ colors.normal(prefix);
909
+ if (module.providedExports.length === 0) colors.cyan("[no exports]");
910
+ else colors.cyan(`[exports: ${module.providedExports.join(", ")}]`);
911
+ newline();
912
+ }
913
+ if (module.usedExports !== undefined) {
914
+ if (module.usedExports !== true) {
915
+ colors.normal(prefix);
916
+ if (module.usedExports === null)
917
+ colors.cyan("[used exports unknown]");
918
+ else if (module.usedExports === false)
919
+ colors.cyan("[no exports used]");
920
+ else if (
921
+ Array.isArray(module.usedExports) &&
922
+ module.usedExports.length === 0
923
+ )
924
+ colors.cyan("[no exports used]");
925
+ else if (Array.isArray(module.usedExports))
926
+ colors.cyan(
927
+ `[only some exports used: ${module.usedExports.join(", ")}]`
928
+ );
929
+ newline();
930
+ }
931
+ }
932
+ if (Array.isArray(module.optimizationBailout)) {
933
+ for (const item of module.optimizationBailout) {
934
+ colors.normal(prefix);
935
+ colors.yellow(item);
936
+ newline();
937
+ }
938
+ }
939
+ if (module.reasons) {
940
+ for (const reason of module.reasons) {
941
+ colors.normal(prefix);
942
+ if (reason.type) {
943
+ colors.normal(reason.type);
944
+ colors.normal(" ");
945
+ }
946
+ if (reason.userRequest) {
947
+ colors.cyan(reason.userRequest);
948
+ colors.normal(" ");
949
+ }
950
+ if (reason.moduleId !== null) {
951
+ colors.normal("[");
952
+ colors.normal(reason.moduleId);
953
+ colors.normal("]");
954
+ }
955
+ if (reason.module && reason.module !== reason.moduleId) {
956
+ colors.normal(" ");
957
+ colors.magenta(reason.module);
958
+ }
959
+ if (reason.loc) {
960
+ colors.normal(" ");
961
+ colors.normal(reason.loc);
962
+ }
963
+ newline();
964
+ }
965
+ }
966
+ if (module.profile) {
967
+ colors.normal(prefix);
968
+ let sum = 0;
969
+ if (module.issuerPath) {
970
+ for (const m of module.issuerPath) {
971
+ colors.normal("[");
972
+ colors.normal(m.id);
973
+ colors.normal("] ");
974
+ if (m.profile) {
975
+ const time = (m.profile.factory || 0) + (m.profile.building || 0);
976
+ coloredTime(time);
977
+ sum += time;
978
+ colors.normal(" ");
979
+ }
980
+ colors.normal("-> ");
981
+ }
982
+ }
983
+ for (const key of Object.keys(module.profile)) {
984
+ colors.normal(`${key}:`);
985
+ const time = module.profile[key];
986
+ coloredTime(time);
987
+ colors.normal(" ");
988
+ sum += time;
989
+ }
990
+ colors.normal("= ");
991
+ coloredTime(sum);
992
+ newline();
993
+ }
994
+ if (module.modules) {
995
+ processModulesList(module, prefix + "| ");
996
+ }
997
+ };
998
+
999
+ const processModulesList = (obj, prefix) => {
1000
+ if (obj.modules) {
1001
+ for (const module of obj.modules) {
1002
+ colors.normal(prefix);
1003
+ const name = module.name || module.identifier;
1004
+ let contentPrefix = prefix + " ";
1005
+ if (typeof module.id === "string" || typeof module.id === "number") {
1006
+ contentPrefix += " ";
1007
+ if (module.id < 1000) colors.normal(" ");
1008
+ if (module.id < 100) colors.normal(" ");
1009
+ if (module.id < 10) colors.normal(" ");
1010
+ colors.normal("[");
1011
+ colors.normal(module.id);
1012
+ colors.normal("]");
1013
+ if (name !== module.id) colors.normal(" ");
1014
+ }
1015
+ if (name !== module.id) {
1016
+ colors.bold(name);
1017
+ }
1018
+ processModuleAttributes(module);
1019
+ newline();
1020
+ processModuleContent(module, contentPrefix);
1021
+ }
1022
+ if (obj.filteredModules > 0) {
1023
+ colors.normal(prefix);
1024
+ colors.normal(" ");
1025
+ if (obj.modules.length > 0) colors.normal(" + ");
1026
+ colors.normal(obj.filteredModules);
1027
+ if (obj.modules.length > 0) colors.normal(" hidden");
1028
+ colors.normal(obj.filteredModules !== 1 ? " modules" : " module");
1029
+ newline();
1030
+ }
1031
+ }
1032
+ };
1033
+
1034
+ if (obj.chunks) {
1035
+ for (const chunk of obj.chunks) {
1036
+ colors.normal("chunk ");
1037
+ if (chunk.id < 1000) colors.normal(" ");
1038
+ if (chunk.id < 100) colors.normal(" ");
1039
+ if (chunk.id < 10) colors.normal(" ");
1040
+ colors.normal("{");
1041
+ colors.yellow(chunk.id);
1042
+ colors.normal("} ");
1043
+ colors.green(chunk.files.join(", "));
1044
+ if (chunk.names && chunk.names.length > 0) {
1045
+ colors.normal(" (");
1046
+ colors.normal(chunk.names.join(", "));
1047
+ colors.normal(")");
1048
+ }
1049
+ colors.normal(" ");
1050
+ colors.normal(SizeFormatHelpers.formatSize(chunk.size));
1051
+ for (const id of chunk.parents) {
1052
+ colors.normal(" <{");
1053
+ colors.yellow(id);
1054
+ colors.normal("}>");
1055
+ }
1056
+ for (const id of chunk.siblings) {
1057
+ colors.normal(" ={");
1058
+ colors.yellow(id);
1059
+ colors.normal("}=");
1060
+ }
1061
+ for (const id of chunk.children) {
1062
+ colors.normal(" >{");
1063
+ colors.yellow(id);
1064
+ colors.normal("}<");
1065
+ }
1066
+ if (chunk.entry) {
1067
+ colors.yellow(" [entry]");
1068
+ } else if (chunk.initial) {
1069
+ colors.yellow(" [initial]");
1070
+ }
1071
+ if (chunk.rendered) {
1072
+ colors.green(" [rendered]");
1073
+ }
1074
+ if (chunk.recorded) {
1075
+ colors.green(" [recorded]");
1076
+ }
1077
+ if (chunk.reason) {
1078
+ colors.yellow(` ${chunk.reason}`);
1079
+ }
1080
+ newline();
1081
+ if (chunk.origins) {
1082
+ for (const origin of chunk.origins) {
1083
+ colors.normal(" > ");
1084
+ if (origin.reasons && origin.reasons.length) {
1085
+ colors.yellow(origin.reasons.join(" "));
1086
+ colors.normal(" ");
1087
+ }
1088
+ if (origin.request) {
1089
+ colors.normal(origin.request);
1090
+ colors.normal(" ");
1091
+ }
1092
+ if (origin.module) {
1093
+ colors.normal("[");
1094
+ colors.normal(origin.moduleId);
1095
+ colors.normal("] ");
1096
+ const module = modulesByIdentifier[`$${origin.module}`];
1097
+ if (module) {
1098
+ colors.bold(module.name);
1099
+ colors.normal(" ");
1100
+ }
1101
+ }
1102
+ if (origin.loc) {
1103
+ colors.normal(origin.loc);
1104
+ }
1105
+ newline();
1106
+ }
1107
+ }
1108
+ processModulesList(chunk, " ");
1109
+ }
1110
+ }
1111
+
1112
+ processModulesList(obj, "");
1113
+
1114
+ if (obj._showWarnings && obj.warnings) {
1115
+ for (const warning of obj.warnings) {
1116
+ newline();
1117
+ colors.yellow(`WARNING in ${warning}`);
1118
+ newline();
1119
+ }
1120
+ }
1121
+ if (obj._showErrors && obj.errors) {
1122
+ for (const error of obj.errors) {
1123
+ newline();
1124
+ colors.red(`ERROR in ${error}`);
1125
+ newline();
1126
+ }
1127
+ }
1128
+ if (obj.children) {
1129
+ for (const child of obj.children) {
1130
+ const childString = Stats.jsonToString(child, useColors);
1131
+ if (childString) {
1132
+ if (child.name) {
1133
+ colors.normal("Child ");
1134
+ colors.bold(child.name);
1135
+ colors.normal(":");
1136
+ } else {
1137
+ colors.normal("Child");
1138
+ }
1139
+ newline();
1140
+ buf.push(" ");
1141
+ buf.push(childString.replace(/\n/g, "\n "));
1142
+ newline();
1143
+ }
1144
+ }
1145
+ }
1146
+ if (obj.needAdditionalPass) {
1147
+ colors.yellow(
1148
+ "Compilation needs an additional pass and will compile again."
1149
+ );
1150
+ }
1151
+
1152
+ while (buf[buf.length - 1] === "\n") buf.pop();
1153
+ return buf.join("");
1154
+ }
1155
+
1156
+ static presetToOptions(name) {
1157
+ // Accepted values: none, errors-only, minimal, normal, detailed, verbose
1158
+ // Any other falsy value will behave as 'none', truthy values as 'normal'
1159
+ const pn =
1160
+ (typeof name === "string" && name.toLowerCase()) || name || "none";
1161
+ switch (pn) {
1162
+ case "none":
1163
+ return {
1164
+ all: false
1165
+ };
1166
+ case "verbose":
1167
+ return {
1168
+ entrypoints: true,
1169
+ modules: false,
1170
+ chunks: true,
1171
+ chunkModules: true,
1172
+ chunkOrigins: true,
1173
+ depth: true,
1174
+ env: true,
1175
+ reasons: true,
1176
+ usedExports: true,
1177
+ providedExports: true,
1178
+ optimizationBailout: true,
1179
+ errorDetails: true,
1180
+ publicPath: true,
1181
+ exclude: false,
1182
+ maxModules: Infinity
1183
+ };
1184
+ case "detailed":
1185
+ return {
1186
+ entrypoints: true,
1187
+ chunks: true,
1188
+ chunkModules: false,
1189
+ chunkOrigins: true,
1190
+ depth: true,
1191
+ usedExports: true,
1192
+ providedExports: true,
1193
+ optimizationBailout: true,
1194
+ errorDetails: true,
1195
+ publicPath: true,
1196
+ exclude: false,
1197
+ maxModules: Infinity
1198
+ };
1199
+ case "minimal":
1200
+ return {
1201
+ all: false,
1202
+ modules: true,
1203
+ maxModules: 0,
1204
+ errors: true,
1205
+ warnings: true
1206
+ };
1207
+ case "errors-only":
1208
+ return {
1209
+ all: false,
1210
+ errors: true,
1211
+ moduleTrace: true
1212
+ };
1213
+ default:
1214
+ return {};
1215
+ }
1216
+ }
1217
+
1218
+ static getChildOptions(options, idx) {
1219
+ let innerOptions;
1220
+ if (Array.isArray(options.children)) {
1221
+ if (idx < options.children.length) innerOptions = options.children[idx];
1222
+ } else if (typeof options.children === "object" && options.children) {
1223
+ innerOptions = options.children;
1224
+ }
1225
+ if (typeof innerOptions === "boolean" || typeof innerOptions === "string")
1226
+ innerOptions = Stats.presetToOptions(innerOptions);
1227
+ if (!innerOptions) return options;
1228
+ const childOptions = Object.assign({}, options);
1229
+ delete childOptions.children; // do not inherit children
1230
+ return Object.assign(childOptions, innerOptions);
1231
+ }
1232
+ }
1233
+
1234
+ module.exports = Stats;