Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

Stats.js 38 KiB

3 lat temu
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 (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. v !== undefined ? v : options.all !== undefined ? options.all : def;
  93. const testAgainstGivenOption = item => {
  94. if (typeof item === "string") {
  95. const regExp = new RegExp(
  96. `[\\\\/]${item.replace(
  97. // eslint-disable-next-line no-useless-escape
  98. /[-[\]{}()*+?.\\^$|]/g,
  99. "\\$&"
  100. )}([\\\\/]|$|!|\\?)`
  101. );
  102. return ident => regExp.test(ident);
  103. }
  104. if (item && typeof item === "object" && typeof item.test === "function") {
  105. return ident => item.test(ident);
  106. }
  107. if (typeof item === "function") {
  108. return item;
  109. }
  110. if (typeof item === "boolean") {
  111. return () => item;
  112. }
  113. };
  114. const compilation = this.compilation;
  115. const context = optionsOrFallback(
  116. options.context,
  117. compilation.compiler.context
  118. );
  119. const requestShortener =
  120. compilation.compiler.context === context
  121. ? compilation.requestShortener
  122. : new RequestShortener(context);
  123. const showPerformance = optionOrLocalFallback(options.performance, true);
  124. const showHash = optionOrLocalFallback(options.hash, true);
  125. const showEnv = optionOrLocalFallback(options.env, false);
  126. const showVersion = optionOrLocalFallback(options.version, true);
  127. const showTimings = optionOrLocalFallback(options.timings, true);
  128. const showBuiltAt = optionOrLocalFallback(options.builtAt, true);
  129. const showAssets = optionOrLocalFallback(options.assets, true);
  130. const showEntrypoints = optionOrLocalFallback(options.entrypoints, true);
  131. const showChunkGroups = optionOrLocalFallback(
  132. options.chunkGroups,
  133. !forToString
  134. );
  135. const showChunks = optionOrLocalFallback(options.chunks, !forToString);
  136. const showChunkModules = optionOrLocalFallback(options.chunkModules, true);
  137. const showChunkOrigins = optionOrLocalFallback(
  138. options.chunkOrigins,
  139. !forToString
  140. );
  141. const showModules = optionOrLocalFallback(options.modules, true);
  142. const showNestedModules = optionOrLocalFallback(
  143. options.nestedModules,
  144. true
  145. );
  146. const showModuleAssets = optionOrLocalFallback(
  147. options.moduleAssets,
  148. !forToString
  149. );
  150. const showDepth = optionOrLocalFallback(options.depth, !forToString);
  151. const showCachedModules = optionOrLocalFallback(options.cached, true);
  152. const showCachedAssets = optionOrLocalFallback(options.cachedAssets, true);
  153. const showReasons = optionOrLocalFallback(options.reasons, !forToString);
  154. const showUsedExports = optionOrLocalFallback(
  155. options.usedExports,
  156. !forToString
  157. );
  158. const showProvidedExports = optionOrLocalFallback(
  159. options.providedExports,
  160. !forToString
  161. );
  162. const showOptimizationBailout = optionOrLocalFallback(
  163. options.optimizationBailout,
  164. !forToString
  165. );
  166. const showChildren = optionOrLocalFallback(options.children, true);
  167. const showSource = optionOrLocalFallback(options.source, !forToString);
  168. const showModuleTrace = optionOrLocalFallback(options.moduleTrace, true);
  169. const showErrors = optionOrLocalFallback(options.errors, true);
  170. const showErrorDetails = optionOrLocalFallback(
  171. options.errorDetails,
  172. !forToString
  173. );
  174. const showWarnings = optionOrLocalFallback(options.warnings, true);
  175. const warningsFilter = optionsOrFallback(options.warningsFilter, null);
  176. const showPublicPath = optionOrLocalFallback(
  177. options.publicPath,
  178. !forToString
  179. );
  180. const excludeModules = []
  181. .concat(optionsOrFallback(options.excludeModules, options.exclude, []))
  182. .map(testAgainstGivenOption);
  183. const excludeAssets = []
  184. .concat(optionsOrFallback(options.excludeAssets, []))
  185. .map(testAgainstGivenOption);
  186. const maxModules = optionsOrFallback(
  187. options.maxModules,
  188. forToString ? 15 : Infinity
  189. );
  190. const sortModules = optionsOrFallback(options.modulesSort, "id");
  191. const sortChunks = optionsOrFallback(options.chunksSort, "id");
  192. const sortAssets = optionsOrFallback(options.assetsSort, "");
  193. const showOutputPath = optionOrLocalFallback(
  194. options.outputPath,
  195. !forToString
  196. );
  197. if (!showCachedModules) {
  198. excludeModules.push((ident, module) => !module.built);
  199. }
  200. const createModuleFilter = () => {
  201. let i = 0;
  202. return module => {
  203. if (excludeModules.length > 0) {
  204. const ident = requestShortener.shorten(module.resource);
  205. const excluded = excludeModules.some(fn => fn(ident, module));
  206. if (excluded) return false;
  207. }
  208. const result = i < maxModules;
  209. i++;
  210. return result;
  211. };
  212. };
  213. const createAssetFilter = () => {
  214. return asset => {
  215. if (excludeAssets.length > 0) {
  216. const ident = asset.name;
  217. const excluded = excludeAssets.some(fn => fn(ident, asset));
  218. if (excluded) return false;
  219. }
  220. return showCachedAssets || asset.emitted;
  221. };
  222. };
  223. const sortByFieldAndOrder = (fieldKey, a, b) => {
  224. if (a[fieldKey] === null && b[fieldKey] === null) return 0;
  225. if (a[fieldKey] === null) return 1;
  226. if (b[fieldKey] === null) return -1;
  227. if (a[fieldKey] === b[fieldKey]) return 0;
  228. return a[fieldKey] < b[fieldKey] ? -1 : 1;
  229. };
  230. const sortByField = field => (a, b) => {
  231. if (!field) {
  232. return 0;
  233. }
  234. const fieldKey = this.normalizeFieldKey(field);
  235. // if a field is prefixed with a "!" the sort is reversed!
  236. const sortIsRegular = this.sortOrderRegular(field);
  237. return sortByFieldAndOrder(
  238. fieldKey,
  239. sortIsRegular ? a : b,
  240. sortIsRegular ? b : a
  241. );
  242. };
  243. const formatError = e => {
  244. let text = "";
  245. if (typeof e === "string") {
  246. e = { message: e };
  247. }
  248. if (e.chunk) {
  249. text += `chunk ${e.chunk.name || e.chunk.id}${
  250. e.chunk.hasRuntime()
  251. ? " [entry]"
  252. : e.chunk.canBeInitial()
  253. ? " [initial]"
  254. : ""
  255. }\n`;
  256. }
  257. if (e.file) {
  258. text += `${e.file}\n`;
  259. }
  260. if (
  261. e.module &&
  262. e.module.readableIdentifier &&
  263. typeof e.module.readableIdentifier === "function"
  264. ) {
  265. text += this.formatFilePath(
  266. e.module.readableIdentifier(requestShortener)
  267. );
  268. if (typeof e.loc === "object") {
  269. const locInfo = formatLocation(e.loc);
  270. if (locInfo) text += ` ${locInfo}`;
  271. }
  272. text += "\n";
  273. }
  274. text += e.message;
  275. if (showErrorDetails && e.details) {
  276. text += `\n${e.details}`;
  277. }
  278. if (showErrorDetails && e.missing) {
  279. text += e.missing.map(item => `\n[${item}]`).join("");
  280. }
  281. if (showModuleTrace && e.origin) {
  282. text += `\n @ ${this.formatFilePath(
  283. e.origin.readableIdentifier(requestShortener)
  284. )}`;
  285. if (typeof e.originLoc === "object") {
  286. const locInfo = formatLocation(e.originLoc);
  287. if (locInfo) text += ` ${locInfo}`;
  288. }
  289. if (e.dependencies) {
  290. for (const dep of e.dependencies) {
  291. if (!dep.loc) continue;
  292. if (typeof dep.loc === "string") continue;
  293. const locInfo = formatLocation(dep.loc);
  294. if (!locInfo) continue;
  295. text += ` ${locInfo}`;
  296. }
  297. }
  298. let current = e.origin;
  299. while (current.issuer) {
  300. current = current.issuer;
  301. text += `\n @ ${current.readableIdentifier(requestShortener)}`;
  302. }
  303. }
  304. return text;
  305. };
  306. const obj = {
  307. errors: compilation.errors.map(formatError),
  308. warnings: Stats.filterWarnings(
  309. compilation.warnings.map(formatError),
  310. warningsFilter
  311. )
  312. };
  313. //We just hint other renderers since actually omitting
  314. //errors/warnings from the JSON would be kind of weird.
  315. Object.defineProperty(obj, "_showWarnings", {
  316. value: showWarnings,
  317. enumerable: false
  318. });
  319. Object.defineProperty(obj, "_showErrors", {
  320. value: showErrors,
  321. enumerable: false
  322. });
  323. if (showVersion) {
  324. obj.version = require("../package.json").version;
  325. }
  326. if (showHash) obj.hash = this.hash;
  327. if (showTimings && this.startTime && this.endTime) {
  328. obj.time = this.endTime - this.startTime;
  329. }
  330. if (showBuiltAt && this.endTime) {
  331. obj.builtAt = this.endTime;
  332. }
  333. if (showEnv && options._env) {
  334. obj.env = options._env;
  335. }
  336. if (compilation.needAdditionalPass) {
  337. obj.needAdditionalPass = true;
  338. }
  339. if (showPublicPath) {
  340. obj.publicPath = this.compilation.mainTemplate.getPublicPath({
  341. hash: this.compilation.hash
  342. });
  343. }
  344. if (showOutputPath) {
  345. obj.outputPath = this.compilation.mainTemplate.outputOptions.path;
  346. }
  347. if (showAssets) {
  348. const assetsByFile = {};
  349. const compilationAssets = Object.keys(compilation.assets);
  350. obj.assetsByChunkName = {};
  351. obj.assets = compilationAssets
  352. .map(asset => {
  353. const obj = {
  354. name: asset,
  355. size: compilation.assets[asset].size(),
  356. chunks: [],
  357. chunkNames: [],
  358. emitted: compilation.assets[asset].emitted
  359. };
  360. if (showPerformance) {
  361. obj.isOverSizeLimit = compilation.assets[asset].isOverSizeLimit;
  362. }
  363. assetsByFile[asset] = obj;
  364. return obj;
  365. })
  366. .filter(createAssetFilter());
  367. obj.filteredAssets = compilationAssets.length - obj.assets.length;
  368. for (const chunk of compilation.chunks) {
  369. for (const asset of chunk.files) {
  370. if (assetsByFile[asset]) {
  371. for (const id of chunk.ids) {
  372. assetsByFile[asset].chunks.push(id);
  373. }
  374. if (chunk.name) {
  375. assetsByFile[asset].chunkNames.push(chunk.name);
  376. if (obj.assetsByChunkName[chunk.name]) {
  377. obj.assetsByChunkName[chunk.name] = []
  378. .concat(obj.assetsByChunkName[chunk.name])
  379. .concat([asset]);
  380. } else {
  381. obj.assetsByChunkName[chunk.name] = asset;
  382. }
  383. }
  384. }
  385. }
  386. }
  387. obj.assets.sort(sortByField(sortAssets));
  388. }
  389. const fnChunkGroup = groupMap => {
  390. const obj = {};
  391. for (const keyValuePair of groupMap) {
  392. const name = keyValuePair[0];
  393. const cg = keyValuePair[1];
  394. const children = cg.getChildrenByOrders();
  395. obj[name] = {
  396. chunks: cg.chunks.map(c => c.id),
  397. assets: cg.chunks.reduce(
  398. (array, c) => array.concat(c.files || []),
  399. []
  400. ),
  401. children: Object.keys(children).reduce((obj, key) => {
  402. const groups = children[key];
  403. obj[key] = groups.map(group => ({
  404. name: group.name,
  405. chunks: group.chunks.map(c => c.id),
  406. assets: group.chunks.reduce(
  407. (array, c) => array.concat(c.files || []),
  408. []
  409. )
  410. }));
  411. return obj;
  412. }, Object.create(null)),
  413. childAssets: Object.keys(children).reduce((obj, key) => {
  414. const groups = children[key];
  415. obj[key] = Array.from(
  416. groups.reduce((set, group) => {
  417. for (const chunk of group.chunks) {
  418. for (const asset of chunk.files) {
  419. set.add(asset);
  420. }
  421. }
  422. return set;
  423. }, new Set())
  424. );
  425. return obj;
  426. }, Object.create(null))
  427. };
  428. if (showPerformance) {
  429. obj[name].isOverSizeLimit = cg.isOverSizeLimit;
  430. }
  431. }
  432. return obj;
  433. };
  434. if (showEntrypoints) {
  435. obj.entrypoints = fnChunkGroup(compilation.entrypoints);
  436. }
  437. if (showChunkGroups) {
  438. obj.namedChunkGroups = fnChunkGroup(compilation.namedChunkGroups);
  439. }
  440. const fnModule = module => {
  441. const path = [];
  442. let current = module;
  443. while (current.issuer) {
  444. path.push((current = current.issuer));
  445. }
  446. path.reverse();
  447. const obj = {
  448. id: module.id,
  449. identifier: module.identifier(),
  450. name: module.readableIdentifier(requestShortener),
  451. index: module.index,
  452. index2: module.index2,
  453. size: module.size(),
  454. cacheable: module.buildInfo.cacheable,
  455. built: !!module.built,
  456. optional: module.optional,
  457. prefetched: module.prefetched,
  458. chunks: Array.from(module.chunksIterable, chunk => chunk.id),
  459. issuer: module.issuer && module.issuer.identifier(),
  460. issuerId: module.issuer && module.issuer.id,
  461. issuerName:
  462. module.issuer && module.issuer.readableIdentifier(requestShortener),
  463. issuerPath:
  464. module.issuer &&
  465. path.map(module => ({
  466. id: module.id,
  467. identifier: module.identifier(),
  468. name: module.readableIdentifier(requestShortener),
  469. profile: module.profile
  470. })),
  471. profile: module.profile,
  472. failed: !!module.error,
  473. errors: module.errors ? module.errors.length : 0,
  474. warnings: module.warnings ? module.warnings.length : 0
  475. };
  476. if (showModuleAssets) {
  477. obj.assets = Object.keys(module.buildInfo.assets || {});
  478. }
  479. if (showReasons) {
  480. obj.reasons = module.reasons
  481. .sort((a, b) => {
  482. if (a.module && !b.module) return -1;
  483. if (!a.module && b.module) return 1;
  484. if (a.module && b.module) {
  485. const cmp = compareId(a.module.id, b.module.id);
  486. if (cmp) return cmp;
  487. }
  488. if (a.dependency && !b.dependency) return -1;
  489. if (!a.dependency && b.dependency) return 1;
  490. if (a.dependency && b.dependency) {
  491. const cmp = compareLocations(a.dependency.loc, b.dependency.loc);
  492. if (cmp) return cmp;
  493. if (a.dependency.type < b.dependency.type) return -1;
  494. if (a.dependency.type > b.dependency.type) return 1;
  495. }
  496. return 0;
  497. })
  498. .map(reason => {
  499. const obj = {
  500. moduleId: reason.module ? reason.module.id : null,
  501. moduleIdentifier: reason.module
  502. ? reason.module.identifier()
  503. : null,
  504. module: reason.module
  505. ? reason.module.readableIdentifier(requestShortener)
  506. : null,
  507. moduleName: reason.module
  508. ? reason.module.readableIdentifier(requestShortener)
  509. : null,
  510. type: reason.dependency ? reason.dependency.type : null,
  511. explanation: reason.explanation,
  512. userRequest: reason.dependency
  513. ? reason.dependency.userRequest
  514. : null
  515. };
  516. if (reason.dependency) {
  517. const locInfo = formatLocation(reason.dependency.loc);
  518. if (locInfo) {
  519. obj.loc = locInfo;
  520. }
  521. }
  522. return obj;
  523. });
  524. }
  525. if (showUsedExports) {
  526. if (module.used === true) {
  527. obj.usedExports = module.usedExports;
  528. } else if (module.used === false) {
  529. obj.usedExports = false;
  530. }
  531. }
  532. if (showProvidedExports) {
  533. obj.providedExports = Array.isArray(module.buildMeta.providedExports)
  534. ? module.buildMeta.providedExports
  535. : null;
  536. }
  537. if (showOptimizationBailout) {
  538. obj.optimizationBailout = module.optimizationBailout.map(item => {
  539. if (typeof item === "function") return item(requestShortener);
  540. return item;
  541. });
  542. }
  543. if (showDepth) {
  544. obj.depth = module.depth;
  545. }
  546. if (showNestedModules) {
  547. if (module.modules) {
  548. const modules = module.modules;
  549. obj.modules = modules
  550. .sort(sortByField("depth"))
  551. .filter(createModuleFilter())
  552. .map(fnModule);
  553. obj.filteredModules = modules.length - obj.modules.length;
  554. obj.modules.sort(sortByField(sortModules));
  555. }
  556. }
  557. if (showSource && module._source) {
  558. obj.source = module._source.source();
  559. }
  560. return obj;
  561. };
  562. if (showChunks) {
  563. obj.chunks = compilation.chunks.map(chunk => {
  564. const parents = new Set();
  565. const children = new Set();
  566. const siblings = new Set();
  567. const childIdByOrder = chunk.getChildIdsByOrders();
  568. for (const chunkGroup of chunk.groupsIterable) {
  569. for (const parentGroup of chunkGroup.parentsIterable) {
  570. for (const chunk of parentGroup.chunks) {
  571. parents.add(chunk.id);
  572. }
  573. }
  574. for (const childGroup of chunkGroup.childrenIterable) {
  575. for (const chunk of childGroup.chunks) {
  576. children.add(chunk.id);
  577. }
  578. }
  579. for (const sibling of chunkGroup.chunks) {
  580. if (sibling !== chunk) siblings.add(sibling.id);
  581. }
  582. }
  583. const obj = {
  584. id: chunk.id,
  585. rendered: chunk.rendered,
  586. initial: chunk.canBeInitial(),
  587. entry: chunk.hasRuntime(),
  588. recorded: chunk.recorded,
  589. reason: chunk.chunkReason,
  590. size: chunk.modulesSize(),
  591. names: chunk.name ? [chunk.name] : [],
  592. files: chunk.files.slice(),
  593. hash: chunk.renderedHash,
  594. siblings: Array.from(siblings).sort(compareId),
  595. parents: Array.from(parents).sort(compareId),
  596. children: Array.from(children).sort(compareId),
  597. childrenByOrder: childIdByOrder
  598. };
  599. if (showChunkModules) {
  600. obj.modules = chunk
  601. .getModules()
  602. .sort(sortByField("depth"))
  603. .filter(createModuleFilter())
  604. .map(fnModule);
  605. obj.filteredModules = chunk.getNumberOfModules() - obj.modules.length;
  606. obj.modules.sort(sortByField(sortModules));
  607. }
  608. if (showChunkOrigins) {
  609. obj.origins = Array.from(chunk.groupsIterable, g => g.origins)
  610. .reduce((a, b) => a.concat(b), [])
  611. .map(origin => ({
  612. moduleId: origin.module ? origin.module.id : undefined,
  613. module: origin.module ? origin.module.identifier() : "",
  614. moduleIdentifier: origin.module ? origin.module.identifier() : "",
  615. moduleName: origin.module
  616. ? origin.module.readableIdentifier(requestShortener)
  617. : "",
  618. loc: formatLocation(origin.loc),
  619. request: origin.request,
  620. reasons: origin.reasons || []
  621. }))
  622. .sort((a, b) => {
  623. if (
  624. typeof a.moduleId === "number" &&
  625. typeof b.moduleId !== "number"
  626. )
  627. return 1;
  628. if (
  629. typeof a.moduleId !== "number" &&
  630. typeof b.moduleId === "number"
  631. )
  632. return -1;
  633. if (
  634. typeof a.moduleId === "number" &&
  635. typeof b.moduleId === "number"
  636. ) {
  637. const diffId = a.moduleId - b.moduleId;
  638. if (diffId !== 0) return diffId;
  639. }
  640. if (a.loc < b.loc) return -1;
  641. if (a.loc > b.loc) return 1;
  642. return 0;
  643. });
  644. }
  645. return obj;
  646. });
  647. obj.chunks.sort(sortByField(sortChunks));
  648. }
  649. if (showModules) {
  650. obj.modules = compilation.modules
  651. .slice()
  652. .sort(sortByField("depth"))
  653. .filter(createModuleFilter())
  654. .map(fnModule);
  655. obj.filteredModules = compilation.modules.length - obj.modules.length;
  656. obj.modules.sort(sortByField(sortModules));
  657. }
  658. if (showChildren) {
  659. obj.children = compilation.children.map((child, idx) => {
  660. const childOptions = Stats.getChildOptions(options, idx);
  661. const obj = new Stats(child).toJson(childOptions, forToString);
  662. delete obj.hash;
  663. delete obj.version;
  664. if (child.name) {
  665. obj.name = identifierUtils.makePathsRelative(
  666. context,
  667. child.name,
  668. compilation.cache
  669. );
  670. }
  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;