webpack 4.9.1 → 4.10.2

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