Stats.js 38 KB

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