Stats.js 38 KB

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