DefaultStatsPrinterPlugin.js 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. /** @typedef {import("../Compiler")} Compiler */
  7. /** @typedef {import("../logging/Logger").LogTypeEnum} LogTypeEnum */
  8. /** @typedef {import("./DefaultStatsFactoryPlugin").ChunkId} ChunkId */
  9. /** @typedef {import("./DefaultStatsFactoryPlugin").ChunkName} ChunkName */
  10. /** @typedef {import("./DefaultStatsFactoryPlugin").KnownStatsAsset} KnownStatsAsset */
  11. /** @typedef {import("./DefaultStatsFactoryPlugin").KnownStatsAssetChunk} KnownStatsAssetChunk */
  12. /** @typedef {import("./DefaultStatsFactoryPlugin").KnownStatsAssetChunkIdHint} KnownStatsAssetChunkIdHint */
  13. /** @typedef {import("./DefaultStatsFactoryPlugin").KnownStatsAssetChunkName} KnownStatsAssetChunkName */
  14. /** @typedef {import("./DefaultStatsFactoryPlugin").KnownStatsChunk} KnownStatsChunk */
  15. /** @typedef {import("./DefaultStatsFactoryPlugin").KnownStatsChunkGroup} KnownStatsChunkGroup */
  16. /** @typedef {import("./DefaultStatsFactoryPlugin").KnownStatsChunkOrigin} KnownStatsChunkOrigin */
  17. /** @typedef {import("./DefaultStatsFactoryPlugin").KnownStatsCompilation} KnownStatsCompilation */
  18. /** @typedef {import("./DefaultStatsFactoryPlugin").KnownStatsError} KnownStatsError */
  19. /** @typedef {import("./DefaultStatsFactoryPlugin").KnownStatsLogging} KnownStatsLogging */
  20. /** @typedef {import("./DefaultStatsFactoryPlugin").KnownStatsLoggingEntry} KnownStatsLoggingEntry */
  21. /** @typedef {import("./DefaultStatsFactoryPlugin").KnownStatsModule} KnownStatsModule */
  22. /** @typedef {import("./DefaultStatsFactoryPlugin").KnownStatsModuleIssuer} KnownStatsModuleIssuer */
  23. /** @typedef {import("./DefaultStatsFactoryPlugin").KnownStatsModuleReason} KnownStatsModuleReason */
  24. /** @typedef {import("./DefaultStatsFactoryPlugin").KnownStatsModuleTraceDependency} KnownStatsModuleTraceDependency */
  25. /** @typedef {import("./DefaultStatsFactoryPlugin").KnownStatsModuleTraceItem} KnownStatsModuleTraceItem */
  26. /** @typedef {import("./DefaultStatsFactoryPlugin").KnownStatsProfile} KnownStatsProfile */
  27. /** @typedef {import("./DefaultStatsFactoryPlugin").StatsCompilation} StatsCompilation */
  28. /** @typedef {import("./StatsPrinter")} StatsPrinter */
  29. /** @typedef {import("./StatsPrinter").ColorFunction} ColorFunction */
  30. /** @typedef {import("./StatsPrinter").KnownStatsPrinterColorFunctions} KnownStatsPrinterColorFunctions */
  31. /** @typedef {import("./StatsPrinter").KnownStatsPrinterContext} KnownStatsPrinterContext */
  32. /** @typedef {import("./StatsPrinter").KnownStatsPrinterFormatters} KnownStatsPrinterFormatters */
  33. /** @typedef {import("./StatsPrinter").StatsPrinterContext} StatsPrinterContext */
  34. /** @typedef {import("./StatsPrinter").StatsPrinterContextWithExtra} StatsPrinterContextWithExtra */
  35. const DATA_URI_CONTENT_LENGTH = 16;
  36. const MAX_MODULE_IDENTIFIER_LENGTH = 80;
  37. /**
  38. * @param {number} n a number
  39. * @param {string} singular singular
  40. * @param {string} plural plural
  41. * @returns {string} if n is 1, singular, else plural
  42. */
  43. const plural = (n, singular, plural) => (n === 1 ? singular : plural);
  44. /**
  45. * @param {Record<string, number>} sizes sizes by source type
  46. * @param {StatsPrinterContext} options options
  47. * @returns {string | undefined} text
  48. */
  49. const printSizes = (sizes, { formatSize = n => `${n}` }) => {
  50. const keys = Object.keys(sizes);
  51. if (keys.length > 1) {
  52. return keys.map(key => `${formatSize(sizes[key])} (${key})`).join(" ");
  53. } else if (keys.length === 1) {
  54. return formatSize(sizes[keys[0]]);
  55. }
  56. };
  57. /**
  58. * @param {string | null} resource resource
  59. * @returns {string} resource name for display
  60. */
  61. const getResourceName = resource => {
  62. if (!resource) return "";
  63. const dataUrl = /^data:[^,]+,/.exec(resource);
  64. if (!dataUrl) return resource;
  65. const len = dataUrl[0].length + DATA_URI_CONTENT_LENGTH;
  66. if (resource.length < len) return resource;
  67. return `${resource.slice(
  68. 0,
  69. Math.min(resource.length - /* '..'.length */ 2, len)
  70. )}..`;
  71. };
  72. /**
  73. * @param {string} name module name
  74. * @returns {[string,string]} prefix and module name
  75. */
  76. const getModuleName = name => {
  77. const [, prefix, resource] =
  78. /** @type {[string, string, string]} */
  79. (/** @type {unknown} */ (/^(.*!)?([^!]*)$/.exec(name)));
  80. if (resource.length > MAX_MODULE_IDENTIFIER_LENGTH) {
  81. const truncatedResource = `${resource.slice(
  82. 0,
  83. Math.min(
  84. resource.length - /* '...(truncated)'.length */ 14,
  85. MAX_MODULE_IDENTIFIER_LENGTH
  86. )
  87. )}...(truncated)`;
  88. return [prefix, getResourceName(truncatedResource)];
  89. }
  90. return [prefix, getResourceName(resource)];
  91. };
  92. /**
  93. * @param {string} str string
  94. * @param {(item: string) => string} fn function to apply to each line
  95. * @returns {string} joined string
  96. */
  97. const mapLines = (str, fn) => str.split("\n").map(fn).join("\n");
  98. /**
  99. * @param {number} n a number
  100. * @returns {string} number as two digit string, leading 0
  101. */
  102. const twoDigit = n => (n >= 10 ? `${n}` : `0${n}`);
  103. /**
  104. * @param {string | number | null} id an id
  105. * @returns {id is string | number} is i
  106. */
  107. const isValidId = id => {
  108. if (typeof id === "number" || id) {
  109. return true;
  110. }
  111. return false;
  112. };
  113. /**
  114. * @template T
  115. * @param {Array<T> | undefined} list of items
  116. * @param {number} count number of items to show
  117. * @returns {string} string representation of list
  118. */
  119. const moreCount = (list, count) =>
  120. list && list.length > 0 ? `+ ${count}` : `${count}`;
  121. /**
  122. * @template T
  123. * @template {keyof T} K
  124. * @typedef {{ [P in K]-?: T[P] }} WithRequired
  125. */
  126. /**
  127. * @template {keyof StatsPrinterContext} RequiredStatsPrinterContextKeys
  128. * @typedef {StatsPrinterContextWithExtra & WithRequired<StatsPrinterContext, "compilation" | RequiredStatsPrinterContextKeys>} DefineStatsPrinterContext
  129. */
  130. /**
  131. * @template T
  132. * @template {keyof StatsPrinterContext} RequiredStatsPrinterContextKeys
  133. * @typedef {(thing: Exclude<T, undefined>, context: DefineStatsPrinterContext<RequiredStatsPrinterContextKeys>, printer: StatsPrinter) => string | undefined} SimplePrinter
  134. */
  135. /**
  136. * @template T
  137. * @typedef {T extends (infer U)[] ? U : T} Unpacked
  138. */
  139. /**
  140. * @template {object} O
  141. * @template {keyof O} K
  142. * @template {string} B
  143. * @typedef {K extends string ? Exclude<O[K], undefined> extends EXPECTED_ANY[] ? never : `${B}.${K}` : never} PropertyName
  144. */
  145. /**
  146. * @template {object} O
  147. * @template {keyof O} K
  148. * @template {string} B
  149. * @typedef {K extends string ? NonNullable<O[K]> extends EXPECTED_ANY[] ? `${B}.${K}[]` : never : never} ArrayPropertyName
  150. */
  151. /**
  152. * @template {object} O
  153. * @template {keyof O} K
  154. * @template {string} B
  155. * @typedef {K extends string ? Exclude<O[K], undefined> extends EXPECTED_ANY[] ? `${B}.${K}` : never : never} MultiplePropertyName
  156. */
  157. /**
  158. * @template {object} O
  159. * @template {string} K
  160. * @template {string} E
  161. * @typedef {{ [property in `${K}!`]?: SimplePrinter<O, "compilation" | E> }} Exclamation
  162. */
  163. /**
  164. * @template {object} O
  165. * @template {string} B
  166. * @template {string} [R=B]
  167. * @typedef {{ [K in keyof O as PropertyName<O, K, B>]?: SimplePrinter<O[K], R> } &
  168. * { [K in keyof O as ArrayPropertyName<O, K, B>]?: Exclude<O[K], undefined> extends (infer I)[] ? SimplePrinter<I, R> : never } &
  169. * { [K in keyof O as MultiplePropertyName<O, K, B>]?: SimplePrinter<O[K], R> }
  170. * } Printers
  171. */
  172. /**
  173. * @typedef {Printers<KnownStatsCompilation, "compilation"> &
  174. * { ["compilation.summary!"]?: SimplePrinter<KnownStatsCompilation, "compilation"> } &
  175. * { ["compilation.errorsInChildren!"]?: SimplePrinter<KnownStatsCompilation, "compilation"> } &
  176. * { ["compilation.warningsInChildren!"]?: SimplePrinter<KnownStatsCompilation, "compilation"> }} CompilationSimplePrinters
  177. */
  178. /**
  179. * @type {CompilationSimplePrinters}
  180. */
  181. const COMPILATION_SIMPLE_PRINTERS = {
  182. "compilation.summary!": (
  183. _,
  184. {
  185. type,
  186. bold,
  187. green,
  188. red,
  189. yellow,
  190. formatDateTime,
  191. formatTime,
  192. compilation: {
  193. name,
  194. hash,
  195. version,
  196. time,
  197. builtAt,
  198. errorsCount,
  199. warningsCount
  200. }
  201. }
  202. ) => {
  203. const root = type === "compilation.summary!";
  204. const warningsMessage =
  205. /** @type {number} */ (warningsCount) > 0
  206. ? yellow(
  207. `${warningsCount} ${plural(/** @type {number} */ (warningsCount), "warning", "warnings")}`
  208. )
  209. : "";
  210. const errorsMessage =
  211. /** @type {number} */ (errorsCount) > 0
  212. ? red(
  213. `${errorsCount} ${plural(/** @type {number} */ (errorsCount), "error", "errors")}`
  214. )
  215. : "";
  216. const timeMessage = root && time ? ` in ${formatTime(time)}` : "";
  217. const hashMessage = hash ? ` (${hash})` : "";
  218. const builtAtMessage =
  219. root && builtAt ? `${formatDateTime(builtAt)}: ` : "";
  220. const versionMessage = root && version ? `webpack ${version}` : "";
  221. const nameMessage =
  222. root && name
  223. ? bold(name)
  224. : name
  225. ? `Child ${bold(name)}`
  226. : root
  227. ? ""
  228. : "Child";
  229. const subjectMessage =
  230. nameMessage && versionMessage
  231. ? `${nameMessage} (${versionMessage})`
  232. : versionMessage || nameMessage || "webpack";
  233. let statusMessage;
  234. if (errorsMessage && warningsMessage) {
  235. statusMessage = `compiled with ${errorsMessage} and ${warningsMessage}`;
  236. } else if (errorsMessage) {
  237. statusMessage = `compiled with ${errorsMessage}`;
  238. } else if (warningsMessage) {
  239. statusMessage = `compiled with ${warningsMessage}`;
  240. } else if (errorsCount === 0 && warningsCount === 0) {
  241. statusMessage = `compiled ${green("successfully")}`;
  242. } else {
  243. statusMessage = "compiled";
  244. }
  245. if (
  246. builtAtMessage ||
  247. versionMessage ||
  248. errorsMessage ||
  249. warningsMessage ||
  250. (errorsCount === 0 && warningsCount === 0) ||
  251. timeMessage ||
  252. hashMessage
  253. )
  254. return `${builtAtMessage}${subjectMessage} ${statusMessage}${timeMessage}${hashMessage}`;
  255. },
  256. "compilation.filteredWarningDetailsCount": count =>
  257. count
  258. ? `${count} ${plural(
  259. count,
  260. "warning has",
  261. "warnings have"
  262. )} detailed information that is not shown.\nUse 'stats.errorDetails: true' resp. '--stats-error-details' to show it.`
  263. : undefined,
  264. "compilation.filteredErrorDetailsCount": (count, { yellow }) =>
  265. count
  266. ? yellow(
  267. `${count} ${plural(
  268. count,
  269. "error has",
  270. "errors have"
  271. )} detailed information that is not shown.\nUse 'stats.errorDetails: true' resp. '--stats-error-details' to show it.`
  272. )
  273. : undefined,
  274. "compilation.env": (env, { bold }) =>
  275. env
  276. ? `Environment (--env): ${bold(JSON.stringify(env, null, 2))}`
  277. : undefined,
  278. "compilation.publicPath": (publicPath, { bold }) =>
  279. `PublicPath: ${bold(publicPath || "(none)")}`,
  280. "compilation.entrypoints": (entrypoints, context, printer) =>
  281. Array.isArray(entrypoints)
  282. ? undefined
  283. : printer.print(context.type, Object.values(entrypoints), {
  284. ...context,
  285. chunkGroupKind: "Entrypoint"
  286. }),
  287. "compilation.namedChunkGroups": (namedChunkGroups, context, printer) => {
  288. if (!Array.isArray(namedChunkGroups)) {
  289. const {
  290. compilation: { entrypoints }
  291. } = context;
  292. let chunkGroups = Object.values(namedChunkGroups);
  293. if (entrypoints) {
  294. chunkGroups = chunkGroups.filter(
  295. group =>
  296. !Object.prototype.hasOwnProperty.call(
  297. entrypoints,
  298. /** @type {string} */
  299. (group.name)
  300. )
  301. );
  302. }
  303. return printer.print(context.type, chunkGroups, {
  304. ...context,
  305. chunkGroupKind: "Chunk Group"
  306. });
  307. }
  308. },
  309. "compilation.assetsByChunkName": () => "",
  310. "compilation.filteredModules": (
  311. filteredModules,
  312. { compilation: { modules } }
  313. ) =>
  314. filteredModules > 0
  315. ? `${moreCount(modules, filteredModules)} ${plural(
  316. filteredModules,
  317. "module",
  318. "modules"
  319. )}`
  320. : undefined,
  321. "compilation.filteredAssets": (
  322. filteredAssets,
  323. { compilation: { assets } }
  324. ) =>
  325. filteredAssets > 0
  326. ? `${moreCount(assets, filteredAssets)} ${plural(
  327. filteredAssets,
  328. "asset",
  329. "assets"
  330. )}`
  331. : undefined,
  332. "compilation.logging": (logging, context, printer) =>
  333. Array.isArray(logging)
  334. ? undefined
  335. : printer.print(
  336. context.type,
  337. Object.entries(logging).map(([name, value]) => ({ ...value, name })),
  338. context
  339. ),
  340. "compilation.warningsInChildren!": (_, { yellow, compilation }) => {
  341. if (
  342. !compilation.children &&
  343. /** @type {number} */ (compilation.warningsCount) > 0 &&
  344. compilation.warnings
  345. ) {
  346. const childWarnings =
  347. /** @type {number} */ (compilation.warningsCount) -
  348. compilation.warnings.length;
  349. if (childWarnings > 0) {
  350. return yellow(
  351. `${childWarnings} ${plural(
  352. childWarnings,
  353. "WARNING",
  354. "WARNINGS"
  355. )} in child compilations${
  356. compilation.children
  357. ? ""
  358. : " (Use 'stats.children: true' resp. '--stats-children' for more details)"
  359. }`
  360. );
  361. }
  362. }
  363. },
  364. "compilation.errorsInChildren!": (_, { red, compilation }) => {
  365. if (
  366. !compilation.children &&
  367. /** @type {number} */ (compilation.errorsCount) > 0 &&
  368. compilation.errors
  369. ) {
  370. const childErrors =
  371. /** @type {number} */ (compilation.errorsCount) -
  372. compilation.errors.length;
  373. if (childErrors > 0) {
  374. return red(
  375. `${childErrors} ${plural(
  376. childErrors,
  377. "ERROR",
  378. "ERRORS"
  379. )} in child compilations${
  380. compilation.children
  381. ? ""
  382. : " (Use 'stats.children: true' resp. '--stats-children' for more details)"
  383. }`
  384. );
  385. }
  386. }
  387. }
  388. };
  389. /**
  390. * @typedef {Printers<KnownStatsAsset, "asset"> &
  391. * Printers<KnownStatsAsset["info"], "asset.info"> &
  392. * Exclamation<KnownStatsAsset, "asset.separator", "asset"> &
  393. * { ["asset.filteredChildren"]?: SimplePrinter<number, "asset"> } &
  394. * { assetChunk?: SimplePrinter<KnownStatsAssetChunk, "asset"> } &
  395. * { assetChunkName?: SimplePrinter<KnownStatsAssetChunkName, "asset"> } &
  396. * { assetChunkIdHint?: SimplePrinter<KnownStatsAssetChunkIdHint, "asset"> }} AssetSimplePrinters
  397. */
  398. /** @type {AssetSimplePrinters} */
  399. const ASSET_SIMPLE_PRINTERS = {
  400. "asset.type": type => type,
  401. "asset.name": (name, { formatFilename, asset: { isOverSizeLimit } }) =>
  402. formatFilename(name, isOverSizeLimit),
  403. "asset.size": (size, { asset: { isOverSizeLimit }, yellow, formatSize }) =>
  404. isOverSizeLimit ? yellow(formatSize(size)) : formatSize(size),
  405. "asset.emitted": (emitted, { green, formatFlag }) =>
  406. emitted ? green(formatFlag("emitted")) : undefined,
  407. "asset.comparedForEmit": (comparedForEmit, { yellow, formatFlag }) =>
  408. comparedForEmit ? yellow(formatFlag("compared for emit")) : undefined,
  409. "asset.cached": (cached, { green, formatFlag }) =>
  410. cached ? green(formatFlag("cached")) : undefined,
  411. "asset.isOverSizeLimit": (isOverSizeLimit, { yellow, formatFlag }) =>
  412. isOverSizeLimit ? yellow(formatFlag("big")) : undefined,
  413. "asset.info.immutable": (immutable, { green, formatFlag }) =>
  414. immutable ? green(formatFlag("immutable")) : undefined,
  415. "asset.info.javascriptModule": (javascriptModule, { formatFlag }) =>
  416. javascriptModule ? formatFlag("javascript module") : undefined,
  417. "asset.info.sourceFilename": (sourceFilename, { formatFlag }) =>
  418. sourceFilename ? formatFlag(`from: ${sourceFilename}`) : undefined,
  419. "asset.info.development": (development, { green, formatFlag }) =>
  420. development ? green(formatFlag("dev")) : undefined,
  421. "asset.info.hotModuleReplacement": (
  422. hotModuleReplacement,
  423. { green, formatFlag }
  424. ) => (hotModuleReplacement ? green(formatFlag("hmr")) : undefined),
  425. "asset.separator!": () => "\n",
  426. "asset.filteredRelated": (filteredRelated, { asset: { related } }) =>
  427. filteredRelated > 0
  428. ? `${moreCount(related, filteredRelated)} related ${plural(
  429. filteredRelated,
  430. "asset",
  431. "assets"
  432. )}`
  433. : undefined,
  434. "asset.filteredChildren": (filteredChildren, { asset: { children } }) =>
  435. filteredChildren > 0
  436. ? `${moreCount(children, filteredChildren)} ${plural(
  437. filteredChildren,
  438. "asset",
  439. "assets"
  440. )}`
  441. : undefined,
  442. assetChunk: (id, { formatChunkId }) => formatChunkId(id),
  443. assetChunkName: name => name || undefined,
  444. assetChunkIdHint: name => name || undefined
  445. };
  446. /**
  447. * @typedef {Printers<KnownStatsModule, "module"> &
  448. * Exclamation<KnownStatsModule, "module.separator", "module"> &
  449. * { ["module.filteredChildren"]?: SimplePrinter<number, "module"> } &
  450. * { ["module.filteredReasons"]?: SimplePrinter<number, "module"> }} ModuleSimplePrinters
  451. */
  452. /** @type {ModuleSimplePrinters} */
  453. const MODULE_SIMPLE_PRINTERS = {
  454. "module.type": type => (type !== "module" ? type : undefined),
  455. "module.id": (id, { formatModuleId }) =>
  456. isValidId(id) ? formatModuleId(id) : undefined,
  457. "module.name": (name, { bold }) => {
  458. const [prefix, resource] = getModuleName(name);
  459. return `${prefix || ""}${bold(resource || "")}`;
  460. },
  461. "module.identifier": identifier => undefined,
  462. "module.layer": (layer, { formatLayer }) =>
  463. layer ? formatLayer(layer) : undefined,
  464. "module.sizes": printSizes,
  465. "module.chunks[]": (id, { formatChunkId }) => formatChunkId(id),
  466. "module.depth": (depth, { formatFlag }) =>
  467. depth !== null ? formatFlag(`depth ${depth}`) : undefined,
  468. "module.cacheable": (cacheable, { formatFlag, red }) =>
  469. cacheable === false ? red(formatFlag("not cacheable")) : undefined,
  470. "module.orphan": (orphan, { formatFlag, yellow }) =>
  471. orphan ? yellow(formatFlag("orphan")) : undefined,
  472. // "module.runtime": (runtime, { formatFlag, yellow }) =>
  473. // runtime ? yellow(formatFlag("runtime")) : undefined,
  474. "module.optional": (optional, { formatFlag, yellow }) =>
  475. optional ? yellow(formatFlag("optional")) : undefined,
  476. "module.dependent": (dependent, { formatFlag, cyan }) =>
  477. dependent ? cyan(formatFlag("dependent")) : undefined,
  478. "module.built": (built, { formatFlag, yellow }) =>
  479. built ? yellow(formatFlag("built")) : undefined,
  480. "module.codeGenerated": (codeGenerated, { formatFlag, yellow }) =>
  481. codeGenerated ? yellow(formatFlag("code generated")) : undefined,
  482. "module.buildTimeExecuted": (buildTimeExecuted, { formatFlag, green }) =>
  483. buildTimeExecuted ? green(formatFlag("build time executed")) : undefined,
  484. "module.cached": (cached, { formatFlag, green }) =>
  485. cached ? green(formatFlag("cached")) : undefined,
  486. "module.assets": (assets, { formatFlag, magenta }) =>
  487. assets && assets.length
  488. ? magenta(
  489. formatFlag(
  490. `${assets.length} ${plural(assets.length, "asset", "assets")}`
  491. )
  492. )
  493. : undefined,
  494. "module.warnings": (warnings, { formatFlag, yellow }) =>
  495. warnings
  496. ? yellow(
  497. formatFlag(`${warnings} ${plural(warnings, "warning", "warnings")}`)
  498. )
  499. : undefined,
  500. "module.errors": (errors, { formatFlag, red }) =>
  501. errors
  502. ? red(formatFlag(`${errors} ${plural(errors, "error", "errors")}`))
  503. : undefined,
  504. "module.providedExports": (providedExports, { formatFlag, cyan }) => {
  505. if (Array.isArray(providedExports)) {
  506. if (providedExports.length === 0) return cyan(formatFlag("no exports"));
  507. return cyan(formatFlag(`exports: ${providedExports.join(", ")}`));
  508. }
  509. },
  510. "module.usedExports": (usedExports, { formatFlag, cyan, module }) => {
  511. if (usedExports !== true) {
  512. if (usedExports === null) return cyan(formatFlag("used exports unknown"));
  513. if (usedExports === false) return cyan(formatFlag("module unused"));
  514. if (Array.isArray(usedExports)) {
  515. if (usedExports.length === 0)
  516. return cyan(formatFlag("no exports used"));
  517. const providedExportsCount = Array.isArray(module.providedExports)
  518. ? module.providedExports.length
  519. : null;
  520. if (
  521. providedExportsCount !== null &&
  522. providedExportsCount === usedExports.length
  523. ) {
  524. return cyan(formatFlag("all exports used"));
  525. }
  526. return cyan(
  527. formatFlag(`only some exports used: ${usedExports.join(", ")}`)
  528. );
  529. }
  530. }
  531. },
  532. "module.optimizationBailout[]": (optimizationBailout, { yellow }) =>
  533. yellow(optimizationBailout),
  534. "module.issuerPath": (issuerPath, { module }) =>
  535. module.profile ? undefined : "",
  536. "module.profile": profile => undefined,
  537. "module.filteredModules": (filteredModules, { module: { modules } }) =>
  538. filteredModules > 0
  539. ? `${moreCount(modules, filteredModules)} nested ${plural(
  540. filteredModules,
  541. "module",
  542. "modules"
  543. )}`
  544. : undefined,
  545. "module.filteredReasons": (filteredReasons, { module: { reasons } }) =>
  546. filteredReasons > 0
  547. ? `${moreCount(reasons, filteredReasons)} ${plural(
  548. filteredReasons,
  549. "reason",
  550. "reasons"
  551. )}`
  552. : undefined,
  553. "module.filteredChildren": (filteredChildren, { module: { children } }) =>
  554. filteredChildren > 0
  555. ? `${moreCount(children, filteredChildren)} ${plural(
  556. filteredChildren,
  557. "module",
  558. "modules"
  559. )}`
  560. : undefined,
  561. "module.separator!": () => "\n"
  562. };
  563. /**
  564. * @typedef {Printers<KnownStatsModuleIssuer, "moduleIssuer"> &
  565. * Printers<KnownStatsModuleIssuer["profile"], "moduleIssuer.profile", "moduleIssuer">} ModuleIssuerPrinters
  566. */
  567. /** @type {ModuleIssuerPrinters} */
  568. const MODULE_ISSUER_PRINTERS = {
  569. "moduleIssuer.id": (id, { formatModuleId }) => formatModuleId(id),
  570. "moduleIssuer.profile.total": (value, { formatTime }) => formatTime(value)
  571. };
  572. /**
  573. * @typedef {Printers<KnownStatsModuleReason, "moduleReason"> &
  574. * { ["moduleReason.filteredChildren"]?: SimplePrinter<number, "moduleReason"> }} ModuleReasonsPrinters
  575. */
  576. /** @type {ModuleReasonsPrinters} */
  577. const MODULE_REASON_PRINTERS = {
  578. "moduleReason.type": type => type || undefined,
  579. "moduleReason.userRequest": (userRequest, { cyan }) =>
  580. cyan(getResourceName(userRequest)),
  581. "moduleReason.moduleId": (moduleId, { formatModuleId }) =>
  582. isValidId(moduleId) ? formatModuleId(moduleId) : undefined,
  583. "moduleReason.module": (module, { magenta }) =>
  584. module ? magenta(module) : undefined,
  585. "moduleReason.loc": loc => loc || undefined,
  586. "moduleReason.explanation": (explanation, { cyan }) =>
  587. explanation ? cyan(explanation) : undefined,
  588. "moduleReason.active": (active, { formatFlag }) =>
  589. active ? undefined : formatFlag("inactive"),
  590. "moduleReason.resolvedModule": (module, { magenta }) =>
  591. module ? magenta(module) : undefined,
  592. "moduleReason.filteredChildren": (
  593. filteredChildren,
  594. { moduleReason: { children } }
  595. ) =>
  596. filteredChildren > 0
  597. ? `${moreCount(children, filteredChildren)} ${plural(
  598. filteredChildren,
  599. "reason",
  600. "reasons"
  601. )}`
  602. : undefined
  603. };
  604. /** @typedef {Printers<KnownStatsProfile, "module.profile", "profile">} ModuleProfilePrinters */
  605. /** @type {ModuleProfilePrinters} */
  606. const MODULE_PROFILE_PRINTERS = {
  607. "module.profile.total": (value, { formatTime }) => formatTime(value),
  608. "module.profile.resolving": (value, { formatTime }) =>
  609. `resolving: ${formatTime(value)}`,
  610. "module.profile.restoring": (value, { formatTime }) =>
  611. `restoring: ${formatTime(value)}`,
  612. "module.profile.integration": (value, { formatTime }) =>
  613. `integration: ${formatTime(value)}`,
  614. "module.profile.building": (value, { formatTime }) =>
  615. `building: ${formatTime(value)}`,
  616. "module.profile.storing": (value, { formatTime }) =>
  617. `storing: ${formatTime(value)}`,
  618. "module.profile.additionalResolving": (value, { formatTime }) =>
  619. value ? `additional resolving: ${formatTime(value)}` : undefined,
  620. "module.profile.additionalIntegration": (value, { formatTime }) =>
  621. value ? `additional integration: ${formatTime(value)}` : undefined
  622. };
  623. /**
  624. * @typedef {Exclamation<KnownStatsChunkGroup, "chunkGroup.kind", "chunkGroupKind"> &
  625. * Exclamation<KnownStatsChunkGroup, "chunkGroup.separator", "chunkGroup"> &
  626. * Printers<KnownStatsChunkGroup, "chunkGroup"> &
  627. * Exclamation<KnownStatsChunkGroup, "chunkGroup.is", "chunkGroup"> &
  628. * Printers<Exclude<KnownStatsChunkGroup["assets"], undefined>[number], "chunkGroupAsset" | "chunkGroup"> &
  629. * { ['chunkGroupChildGroup.type']?: SimplePrinter<string, "chunkGroupAsset"> } &
  630. * { ['chunkGroupChild.assets[]']?: SimplePrinter<string, "chunkGroupAsset"> } &
  631. * { ['chunkGroupChild.chunks[]']?: SimplePrinter<ChunkId, "chunkGroupAsset"> } &
  632. * { ['chunkGroupChild.name']?: SimplePrinter<ChunkName, "chunkGroupAsset"> }} ChunkGroupPrinters
  633. */
  634. /** @type {ChunkGroupPrinters} */
  635. const CHUNK_GROUP_PRINTERS = {
  636. "chunkGroup.kind!": (_, { chunkGroupKind }) => chunkGroupKind,
  637. "chunkGroup.separator!": () => "\n",
  638. "chunkGroup.name": (name, { bold }) => (name ? bold(name) : undefined),
  639. "chunkGroup.isOverSizeLimit": (isOverSizeLimit, { formatFlag, yellow }) =>
  640. isOverSizeLimit ? yellow(formatFlag("big")) : undefined,
  641. "chunkGroup.assetsSize": (size, { formatSize }) =>
  642. size ? formatSize(size) : undefined,
  643. "chunkGroup.auxiliaryAssetsSize": (size, { formatSize }) =>
  644. size ? `(${formatSize(size)})` : undefined,
  645. "chunkGroup.filteredAssets": (n, { chunkGroup: { assets } }) =>
  646. n > 0
  647. ? `${moreCount(assets, n)} ${plural(n, "asset", "assets")}`
  648. : undefined,
  649. "chunkGroup.filteredAuxiliaryAssets": (
  650. n,
  651. { chunkGroup: { auxiliaryAssets } }
  652. ) =>
  653. n > 0
  654. ? `${moreCount(auxiliaryAssets, n)} auxiliary ${plural(
  655. n,
  656. "asset",
  657. "assets"
  658. )}`
  659. : undefined,
  660. "chunkGroup.is!": () => "=",
  661. "chunkGroupAsset.name": (asset, { green }) => green(asset),
  662. "chunkGroupAsset.size": (size, { formatSize, chunkGroup }) =>
  663. chunkGroup.assets &&
  664. (chunkGroup.assets.length > 1 ||
  665. (chunkGroup.auxiliaryAssets && chunkGroup.auxiliaryAssets.length > 0)
  666. ? formatSize(size)
  667. : undefined),
  668. "chunkGroup.children": (children, context, printer) =>
  669. Array.isArray(children)
  670. ? undefined
  671. : printer.print(
  672. context.type,
  673. Object.keys(children).map(key => ({
  674. type: key,
  675. children: children[key]
  676. })),
  677. context
  678. ),
  679. "chunkGroupChildGroup.type": type => `${type}:`,
  680. "chunkGroupChild.assets[]": (file, { formatFilename }) =>
  681. formatFilename(file),
  682. "chunkGroupChild.chunks[]": (id, { formatChunkId }) => formatChunkId(id),
  683. "chunkGroupChild.name": name => (name ? `(name: ${name})` : undefined)
  684. };
  685. /**
  686. * @typedef {Printers<KnownStatsChunk, "chunk"> &
  687. * { ["chunk.childrenByOrder[].type"]: SimplePrinter<string, "chunk"> } &
  688. * { ["chunk.childrenByOrder[].children[]"]: SimplePrinter<ChunkId, "chunk"> } &
  689. * Exclamation<KnownStatsChunk, "chunk.separator", "chunk"> &
  690. * Printers<KnownStatsChunkOrigin, "chunkOrigin">} ChunkPrinters
  691. */
  692. /** @type {ChunkPrinters} */
  693. const CHUNK_PRINTERS = {
  694. "chunk.id": (id, { formatChunkId }) => formatChunkId(id),
  695. "chunk.files[]": (file, { formatFilename }) => formatFilename(file),
  696. "chunk.names[]": name => name,
  697. "chunk.idHints[]": name => name,
  698. "chunk.runtime[]": name => name,
  699. "chunk.sizes": (sizes, context) => printSizes(sizes, context),
  700. "chunk.parents[]": (parents, context) =>
  701. context.formatChunkId(parents, "parent"),
  702. "chunk.siblings[]": (siblings, context) =>
  703. context.formatChunkId(siblings, "sibling"),
  704. "chunk.children[]": (children, context) =>
  705. context.formatChunkId(children, "child"),
  706. "chunk.childrenByOrder": (childrenByOrder, context, printer) =>
  707. Array.isArray(childrenByOrder)
  708. ? undefined
  709. : printer.print(
  710. context.type,
  711. Object.keys(childrenByOrder).map(key => ({
  712. type: key,
  713. children: childrenByOrder[key]
  714. })),
  715. context
  716. ),
  717. "chunk.childrenByOrder[].type": type => `${type}:`,
  718. "chunk.childrenByOrder[].children[]": (id, { formatChunkId }) =>
  719. isValidId(id) ? formatChunkId(id) : undefined,
  720. "chunk.entry": (entry, { formatFlag, yellow }) =>
  721. entry ? yellow(formatFlag("entry")) : undefined,
  722. "chunk.initial": (initial, { formatFlag, yellow }) =>
  723. initial ? yellow(formatFlag("initial")) : undefined,
  724. "chunk.rendered": (rendered, { formatFlag, green }) =>
  725. rendered ? green(formatFlag("rendered")) : undefined,
  726. "chunk.recorded": (recorded, { formatFlag, green }) =>
  727. recorded ? green(formatFlag("recorded")) : undefined,
  728. "chunk.reason": (reason, { yellow }) => (reason ? yellow(reason) : undefined),
  729. "chunk.filteredModules": (filteredModules, { chunk: { modules } }) =>
  730. filteredModules > 0
  731. ? `${moreCount(modules, filteredModules)} chunk ${plural(
  732. filteredModules,
  733. "module",
  734. "modules"
  735. )}`
  736. : undefined,
  737. "chunk.separator!": () => "\n",
  738. "chunkOrigin.request": request => request,
  739. "chunkOrigin.moduleId": (moduleId, { formatModuleId }) =>
  740. isValidId(moduleId) ? formatModuleId(moduleId) : undefined,
  741. "chunkOrigin.moduleName": (moduleName, { bold }) => bold(moduleName),
  742. "chunkOrigin.loc": loc => loc
  743. };
  744. /**
  745. * @typedef {Printers<KnownStatsError, "error"> &
  746. * { ["error.filteredDetails"]?: SimplePrinter<number, "error"> } &
  747. * Exclamation<KnownStatsError, "error.separator", "error">} ErrorPrinters
  748. */
  749. /**
  750. * @type {ErrorPrinters}
  751. */
  752. const ERROR_PRINTERS = {
  753. "error.compilerPath": (compilerPath, { bold }) =>
  754. compilerPath ? bold(`(${compilerPath})`) : undefined,
  755. "error.chunkId": (chunkId, { formatChunkId }) =>
  756. isValidId(chunkId) ? formatChunkId(chunkId) : undefined,
  757. "error.chunkEntry": (chunkEntry, { formatFlag }) =>
  758. chunkEntry ? formatFlag("entry") : undefined,
  759. "error.chunkInitial": (chunkInitial, { formatFlag }) =>
  760. chunkInitial ? formatFlag("initial") : undefined,
  761. "error.file": (file, { bold }) => bold(file),
  762. "error.moduleName": (moduleName, { bold }) =>
  763. moduleName.includes("!")
  764. ? `${bold(moduleName.replace(/^(\s|\S)*!/, ""))} (${moduleName})`
  765. : `${bold(moduleName)}`,
  766. "error.loc": (loc, { green }) => green(loc),
  767. "error.message": (message, { bold, formatError }) =>
  768. message.includes("\u001B[") ? message : bold(formatError(message)),
  769. "error.details": (details, { formatError }) => formatError(details),
  770. "error.filteredDetails": filteredDetails =>
  771. filteredDetails ? `+ ${filteredDetails} hidden lines` : undefined,
  772. "error.stack": stack => stack,
  773. "error.cause": (cause, context, printer) =>
  774. cause
  775. ? indent(
  776. `[cause]: ${
  777. /** @type {string} */
  778. (printer.print(`${context.type}.error`, cause, context))
  779. }`,
  780. " "
  781. )
  782. : undefined,
  783. "error.moduleTrace": moduleTrace => undefined,
  784. "error.separator!": () => "\n"
  785. };
  786. /**
  787. * @typedef {Printers<KnownStatsLoggingEntry, `loggingEntry(${LogTypeEnum}).loggingEntry`> &
  788. * { ["loggingEntry(clear).loggingEntry"]?: SimplePrinter<KnownStatsLoggingEntry, "logging"> } &
  789. * { ["loggingEntry.trace[]"]?: SimplePrinter<Exclude<KnownStatsLoggingEntry["trace"], undefined>[number], "logging"> } &
  790. * { loggingGroup?: SimplePrinter<KnownStatsLogging[], "logging"> } &
  791. * Printers<KnownStatsLogging & { name: string }, `loggingGroup`> &
  792. * Exclamation<KnownStatsLogging, "loggingGroup.separator", "loggingGroup">} LogEntryPrinters
  793. */
  794. /** @type {LogEntryPrinters} */
  795. const LOG_ENTRY_PRINTERS = {
  796. "loggingEntry(error).loggingEntry.message": (message, { red }) =>
  797. mapLines(message, x => `<e> ${red(x)}`),
  798. "loggingEntry(warn).loggingEntry.message": (message, { yellow }) =>
  799. mapLines(message, x => `<w> ${yellow(x)}`),
  800. "loggingEntry(info).loggingEntry.message": (message, { green }) =>
  801. mapLines(message, x => `<i> ${green(x)}`),
  802. "loggingEntry(log).loggingEntry.message": (message, { bold }) =>
  803. mapLines(message, x => ` ${bold(x)}`),
  804. "loggingEntry(debug).loggingEntry.message": message =>
  805. mapLines(message, x => ` ${x}`),
  806. "loggingEntry(trace).loggingEntry.message": message =>
  807. mapLines(message, x => ` ${x}`),
  808. "loggingEntry(status).loggingEntry.message": (message, { magenta }) =>
  809. mapLines(message, x => `<s> ${magenta(x)}`),
  810. "loggingEntry(profile).loggingEntry.message": (message, { magenta }) =>
  811. mapLines(message, x => `<p> ${magenta(x)}`),
  812. "loggingEntry(profileEnd).loggingEntry.message": (message, { magenta }) =>
  813. mapLines(message, x => `</p> ${magenta(x)}`),
  814. "loggingEntry(time).loggingEntry.message": (message, { magenta }) =>
  815. mapLines(message, x => `<t> ${magenta(x)}`),
  816. "loggingEntry(group).loggingEntry.message": (message, { cyan }) =>
  817. mapLines(message, x => `<-> ${cyan(x)}`),
  818. "loggingEntry(groupCollapsed).loggingEntry.message": (message, { cyan }) =>
  819. mapLines(message, x => `<+> ${cyan(x)}`),
  820. "loggingEntry(clear).loggingEntry": () => " -------",
  821. "loggingEntry(groupCollapsed).loggingEntry.children": () => "",
  822. "loggingEntry.trace[]": trace =>
  823. trace ? mapLines(trace, x => `| ${x}`) : undefined,
  824. loggingGroup: loggingGroup =>
  825. loggingGroup.entries.length === 0 ? "" : undefined,
  826. "loggingGroup.debug": (flag, { red }) => (flag ? red("DEBUG") : undefined),
  827. "loggingGroup.name": (name, { bold }) => bold(`LOG from ${name}`),
  828. "loggingGroup.separator!": () => "\n",
  829. "loggingGroup.filteredEntries": filteredEntries =>
  830. filteredEntries > 0 ? `+ ${filteredEntries} hidden lines` : undefined
  831. };
  832. /** @typedef {Printers<KnownStatsModuleTraceItem, "moduleTraceItem">} ModuleTraceItemPrinters */
  833. /** @type {ModuleTraceItemPrinters} */
  834. const MODULE_TRACE_ITEM_PRINTERS = {
  835. "moduleTraceItem.originName": originName => originName
  836. };
  837. /** @typedef {Printers<KnownStatsModuleTraceDependency, "moduleTraceDependency">} ModuleTraceDependencyPrinters */
  838. /** @type {ModuleTraceDependencyPrinters} */
  839. const MODULE_TRACE_DEPENDENCY_PRINTERS = {
  840. "moduleTraceDependency.loc": loc => loc
  841. };
  842. /**
  843. * @type {Record<string, string | ((item: KnownStatsLoggingEntry) => string)>}
  844. */
  845. const ITEM_NAMES = {
  846. "compilation.assets[]": "asset",
  847. "compilation.modules[]": "module",
  848. "compilation.chunks[]": "chunk",
  849. "compilation.entrypoints[]": "chunkGroup",
  850. "compilation.namedChunkGroups[]": "chunkGroup",
  851. "compilation.errors[]": "error",
  852. "compilation.warnings[]": "error",
  853. "compilation.logging[]": "loggingGroup",
  854. "compilation.children[]": "compilation",
  855. "asset.related[]": "asset",
  856. "asset.children[]": "asset",
  857. "asset.chunks[]": "assetChunk",
  858. "asset.auxiliaryChunks[]": "assetChunk",
  859. "asset.chunkNames[]": "assetChunkName",
  860. "asset.chunkIdHints[]": "assetChunkIdHint",
  861. "asset.auxiliaryChunkNames[]": "assetChunkName",
  862. "asset.auxiliaryChunkIdHints[]": "assetChunkIdHint",
  863. "chunkGroup.assets[]": "chunkGroupAsset",
  864. "chunkGroup.auxiliaryAssets[]": "chunkGroupAsset",
  865. "chunkGroupChild.assets[]": "chunkGroupAsset",
  866. "chunkGroupChild.auxiliaryAssets[]": "chunkGroupAsset",
  867. "chunkGroup.children[]": "chunkGroupChildGroup",
  868. "chunkGroupChildGroup.children[]": "chunkGroupChild",
  869. "module.modules[]": "module",
  870. "module.children[]": "module",
  871. "module.reasons[]": "moduleReason",
  872. "moduleReason.children[]": "moduleReason",
  873. "module.issuerPath[]": "moduleIssuer",
  874. "chunk.origins[]": "chunkOrigin",
  875. "chunk.modules[]": "module",
  876. "loggingGroup.entries[]": logEntry =>
  877. `loggingEntry(${logEntry.type}).loggingEntry`,
  878. "loggingEntry.children[]": logEntry =>
  879. `loggingEntry(${logEntry.type}).loggingEntry`,
  880. "error.moduleTrace[]": "moduleTraceItem",
  881. "error.errors[]": "error",
  882. "moduleTraceItem.dependencies[]": "moduleTraceDependency"
  883. };
  884. const ERROR_PREFERRED_ORDER = [
  885. "compilerPath",
  886. "chunkId",
  887. "chunkEntry",
  888. "chunkInitial",
  889. "file",
  890. "separator!",
  891. "moduleName",
  892. "loc",
  893. "separator!",
  894. "message",
  895. "separator!",
  896. "details",
  897. "separator!",
  898. "filteredDetails",
  899. "separator!",
  900. "stack",
  901. "separator!",
  902. "cause",
  903. "separator!",
  904. "missing",
  905. "separator!",
  906. "moduleTrace"
  907. ];
  908. /** @type {Record<string, string[]>} */
  909. const PREFERRED_ORDERS = {
  910. compilation: [
  911. "name",
  912. "hash",
  913. "version",
  914. "time",
  915. "builtAt",
  916. "env",
  917. "publicPath",
  918. "assets",
  919. "filteredAssets",
  920. "entrypoints",
  921. "namedChunkGroups",
  922. "chunks",
  923. "modules",
  924. "filteredModules",
  925. "children",
  926. "logging",
  927. "warnings",
  928. "warningsInChildren!",
  929. "filteredWarningDetailsCount",
  930. "errors",
  931. "errorsInChildren!",
  932. "filteredErrorDetailsCount",
  933. "summary!",
  934. "needAdditionalPass"
  935. ],
  936. asset: [
  937. "type",
  938. "name",
  939. "size",
  940. "chunks",
  941. "auxiliaryChunks",
  942. "emitted",
  943. "comparedForEmit",
  944. "cached",
  945. "info",
  946. "isOverSizeLimit",
  947. "chunkNames",
  948. "auxiliaryChunkNames",
  949. "chunkIdHints",
  950. "auxiliaryChunkIdHints",
  951. "related",
  952. "filteredRelated",
  953. "children",
  954. "filteredChildren"
  955. ],
  956. "asset.info": [
  957. "immutable",
  958. "sourceFilename",
  959. "javascriptModule",
  960. "development",
  961. "hotModuleReplacement"
  962. ],
  963. chunkGroup: [
  964. "kind!",
  965. "name",
  966. "isOverSizeLimit",
  967. "assetsSize",
  968. "auxiliaryAssetsSize",
  969. "is!",
  970. "assets",
  971. "filteredAssets",
  972. "auxiliaryAssets",
  973. "filteredAuxiliaryAssets",
  974. "separator!",
  975. "children"
  976. ],
  977. chunkGroupAsset: ["name", "size"],
  978. chunkGroupChildGroup: ["type", "children"],
  979. chunkGroupChild: ["assets", "chunks", "name"],
  980. module: [
  981. "type",
  982. "name",
  983. "identifier",
  984. "id",
  985. "layer",
  986. "sizes",
  987. "chunks",
  988. "depth",
  989. "cacheable",
  990. "orphan",
  991. "runtime",
  992. "optional",
  993. "dependent",
  994. "built",
  995. "codeGenerated",
  996. "cached",
  997. "assets",
  998. "failed",
  999. "warnings",
  1000. "errors",
  1001. "children",
  1002. "filteredChildren",
  1003. "providedExports",
  1004. "usedExports",
  1005. "optimizationBailout",
  1006. "reasons",
  1007. "filteredReasons",
  1008. "issuerPath",
  1009. "profile",
  1010. "modules",
  1011. "filteredModules"
  1012. ],
  1013. moduleReason: [
  1014. "active",
  1015. "type",
  1016. "userRequest",
  1017. "moduleId",
  1018. "module",
  1019. "resolvedModule",
  1020. "loc",
  1021. "explanation",
  1022. "children",
  1023. "filteredChildren"
  1024. ],
  1025. "module.profile": [
  1026. "total",
  1027. "separator!",
  1028. "resolving",
  1029. "restoring",
  1030. "integration",
  1031. "building",
  1032. "storing",
  1033. "additionalResolving",
  1034. "additionalIntegration"
  1035. ],
  1036. chunk: [
  1037. "id",
  1038. "runtime",
  1039. "files",
  1040. "names",
  1041. "idHints",
  1042. "sizes",
  1043. "parents",
  1044. "siblings",
  1045. "children",
  1046. "childrenByOrder",
  1047. "entry",
  1048. "initial",
  1049. "rendered",
  1050. "recorded",
  1051. "reason",
  1052. "separator!",
  1053. "origins",
  1054. "separator!",
  1055. "modules",
  1056. "separator!",
  1057. "filteredModules"
  1058. ],
  1059. chunkOrigin: ["request", "moduleId", "moduleName", "loc"],
  1060. error: ERROR_PREFERRED_ORDER,
  1061. warning: ERROR_PREFERRED_ORDER,
  1062. "chunk.childrenByOrder[]": ["type", "children"],
  1063. loggingGroup: [
  1064. "debug",
  1065. "name",
  1066. "separator!",
  1067. "entries",
  1068. "separator!",
  1069. "filteredEntries"
  1070. ],
  1071. loggingEntry: ["message", "trace", "children"]
  1072. };
  1073. /** @typedef {(items: string[]) => string | undefined} SimpleItemsJoiner */
  1074. /** @type {SimpleItemsJoiner} */
  1075. const itemsJoinOneLine = items => items.filter(Boolean).join(" ");
  1076. /** @type {SimpleItemsJoiner} */
  1077. const itemsJoinOneLineBrackets = items =>
  1078. items.length > 0 ? `(${items.filter(Boolean).join(" ")})` : undefined;
  1079. /** @type {SimpleItemsJoiner} */
  1080. const itemsJoinMoreSpacing = items => items.filter(Boolean).join("\n\n");
  1081. /** @type {SimpleItemsJoiner} */
  1082. const itemsJoinComma = items => items.filter(Boolean).join(", ");
  1083. /** @type {SimpleItemsJoiner} */
  1084. const itemsJoinCommaBrackets = items =>
  1085. items.length > 0 ? `(${items.filter(Boolean).join(", ")})` : undefined;
  1086. /** @type {(item: string) => SimpleItemsJoiner} */
  1087. const itemsJoinCommaBracketsWithName = name => items =>
  1088. items.length > 0
  1089. ? `(${name}: ${items.filter(Boolean).join(", ")})`
  1090. : undefined;
  1091. /** @type {Record<string, SimpleItemsJoiner>} */
  1092. const SIMPLE_ITEMS_JOINER = {
  1093. "chunk.parents": itemsJoinOneLine,
  1094. "chunk.siblings": itemsJoinOneLine,
  1095. "chunk.children": itemsJoinOneLine,
  1096. "chunk.names": itemsJoinCommaBrackets,
  1097. "chunk.idHints": itemsJoinCommaBracketsWithName("id hint"),
  1098. "chunk.runtime": itemsJoinCommaBracketsWithName("runtime"),
  1099. "chunk.files": itemsJoinComma,
  1100. "chunk.childrenByOrder": itemsJoinOneLine,
  1101. "chunk.childrenByOrder[].children": itemsJoinOneLine,
  1102. "chunkGroup.assets": itemsJoinOneLine,
  1103. "chunkGroup.auxiliaryAssets": itemsJoinOneLineBrackets,
  1104. "chunkGroupChildGroup.children": itemsJoinComma,
  1105. "chunkGroupChild.assets": itemsJoinOneLine,
  1106. "chunkGroupChild.auxiliaryAssets": itemsJoinOneLineBrackets,
  1107. "asset.chunks": itemsJoinComma,
  1108. "asset.auxiliaryChunks": itemsJoinCommaBrackets,
  1109. "asset.chunkNames": itemsJoinCommaBracketsWithName("name"),
  1110. "asset.auxiliaryChunkNames": itemsJoinCommaBracketsWithName("auxiliary name"),
  1111. "asset.chunkIdHints": itemsJoinCommaBracketsWithName("id hint"),
  1112. "asset.auxiliaryChunkIdHints":
  1113. itemsJoinCommaBracketsWithName("auxiliary id hint"),
  1114. "module.chunks": itemsJoinOneLine,
  1115. "module.issuerPath": items =>
  1116. items
  1117. .filter(Boolean)
  1118. .map(item => `${item} ->`)
  1119. .join(" "),
  1120. "compilation.errors": itemsJoinMoreSpacing,
  1121. "compilation.warnings": itemsJoinMoreSpacing,
  1122. "compilation.logging": itemsJoinMoreSpacing,
  1123. "compilation.children": items =>
  1124. indent(/** @type {string} */ (itemsJoinMoreSpacing(items)), " "),
  1125. "moduleTraceItem.dependencies": itemsJoinOneLine,
  1126. "loggingEntry.children": items =>
  1127. indent(items.filter(Boolean).join("\n"), " ", false)
  1128. };
  1129. /**
  1130. * @param {Item[]} items items
  1131. * @returns {string} result
  1132. */
  1133. const joinOneLine = items =>
  1134. items
  1135. .map(item => item.content)
  1136. .filter(Boolean)
  1137. .join(" ");
  1138. /**
  1139. * @param {Item[]} items items
  1140. * @returns {string} result
  1141. */
  1142. const joinInBrackets = items => {
  1143. const res = [];
  1144. let mode = 0;
  1145. for (const item of items) {
  1146. if (item.element === "separator!") {
  1147. switch (mode) {
  1148. case 0:
  1149. case 1:
  1150. mode += 2;
  1151. break;
  1152. case 4:
  1153. res.push(")");
  1154. mode = 3;
  1155. break;
  1156. }
  1157. }
  1158. if (!item.content) continue;
  1159. switch (mode) {
  1160. case 0:
  1161. mode = 1;
  1162. break;
  1163. case 1:
  1164. res.push(" ");
  1165. break;
  1166. case 2:
  1167. res.push("(");
  1168. mode = 4;
  1169. break;
  1170. case 3:
  1171. res.push(" (");
  1172. mode = 4;
  1173. break;
  1174. case 4:
  1175. res.push(", ");
  1176. break;
  1177. }
  1178. res.push(item.content);
  1179. }
  1180. if (mode === 4) res.push(")");
  1181. return res.join("");
  1182. };
  1183. /**
  1184. * @param {string} str a string
  1185. * @param {string} prefix prefix
  1186. * @param {boolean=} noPrefixInFirstLine need prefix in the first line?
  1187. * @returns {string} result
  1188. */
  1189. const indent = (str, prefix, noPrefixInFirstLine) => {
  1190. const rem = str.replace(/\n([^\n])/g, `\n${prefix}$1`);
  1191. if (noPrefixInFirstLine) return rem;
  1192. const ind = str[0] === "\n" ? "" : prefix;
  1193. return ind + rem;
  1194. };
  1195. /**
  1196. * @param {(false | Item)[]} items items
  1197. * @param {string} indenter indenter
  1198. * @returns {string} result
  1199. */
  1200. const joinExplicitNewLine = (items, indenter) => {
  1201. let firstInLine = true;
  1202. let first = true;
  1203. return items
  1204. .map(item => {
  1205. if (!item || !item.content) return;
  1206. let content = indent(item.content, first ? "" : indenter, !firstInLine);
  1207. if (firstInLine) {
  1208. content = content.replace(/^\n+/, "");
  1209. }
  1210. if (!content) return;
  1211. first = false;
  1212. const noJoiner = firstInLine || content.startsWith("\n");
  1213. firstInLine = content.endsWith("\n");
  1214. return noJoiner ? content : ` ${content}`;
  1215. })
  1216. .filter(Boolean)
  1217. .join("")
  1218. .trim();
  1219. };
  1220. /**
  1221. * @param {boolean} error is an error
  1222. * @returns {SimpleElementJoiner} joiner
  1223. */
  1224. const joinError =
  1225. error =>
  1226. /**
  1227. * @param {Item[]} items items
  1228. * @param {StatsPrinterContextWithExtra} ctx context
  1229. * @returns {string} result
  1230. */
  1231. (items, { red, yellow }) =>
  1232. `${error ? red("ERROR") : yellow("WARNING")} in ${joinExplicitNewLine(
  1233. items,
  1234. ""
  1235. )}`;
  1236. /** @typedef {{ element: string, content: string | undefined }} Item */
  1237. /** @typedef {(items: Item[], context: StatsPrinterContextWithExtra & Required<KnownStatsPrinterContext>) => string} SimpleElementJoiner */
  1238. /** @type {Record<string, SimpleElementJoiner>} */
  1239. const SIMPLE_ELEMENT_JOINERS = {
  1240. compilation: items => {
  1241. const result = [];
  1242. let lastNeedMore = false;
  1243. for (const item of items) {
  1244. if (!item.content) continue;
  1245. const needMoreSpace =
  1246. item.element === "warnings" ||
  1247. item.element === "filteredWarningDetailsCount" ||
  1248. item.element === "errors" ||
  1249. item.element === "filteredErrorDetailsCount" ||
  1250. item.element === "logging";
  1251. if (result.length !== 0) {
  1252. result.push(needMoreSpace || lastNeedMore ? "\n\n" : "\n");
  1253. }
  1254. result.push(item.content);
  1255. lastNeedMore = needMoreSpace;
  1256. }
  1257. if (lastNeedMore) result.push("\n");
  1258. return result.join("");
  1259. },
  1260. asset: items =>
  1261. joinExplicitNewLine(
  1262. items.map(item => {
  1263. if (
  1264. (item.element === "related" || item.element === "children") &&
  1265. item.content
  1266. ) {
  1267. return {
  1268. ...item,
  1269. content: `\n${item.content}\n`
  1270. };
  1271. }
  1272. return item;
  1273. }),
  1274. " "
  1275. ),
  1276. "asset.info": joinOneLine,
  1277. module: (items, { module }) => {
  1278. let hasName = false;
  1279. return joinExplicitNewLine(
  1280. items.map(item => {
  1281. switch (item.element) {
  1282. case "id":
  1283. if (module.id === module.name) {
  1284. if (hasName) return false;
  1285. if (item.content) hasName = true;
  1286. }
  1287. break;
  1288. case "name":
  1289. if (hasName) return false;
  1290. if (item.content) hasName = true;
  1291. break;
  1292. case "providedExports":
  1293. case "usedExports":
  1294. case "optimizationBailout":
  1295. case "reasons":
  1296. case "issuerPath":
  1297. case "profile":
  1298. case "children":
  1299. case "modules":
  1300. if (item.content) {
  1301. return {
  1302. ...item,
  1303. content: `\n${item.content}\n`
  1304. };
  1305. }
  1306. break;
  1307. }
  1308. return item;
  1309. }),
  1310. " "
  1311. );
  1312. },
  1313. chunk: items => {
  1314. let hasEntry = false;
  1315. return `chunk ${joinExplicitNewLine(
  1316. items.filter(item => {
  1317. switch (item.element) {
  1318. case "entry":
  1319. if (item.content) hasEntry = true;
  1320. break;
  1321. case "initial":
  1322. if (hasEntry) return false;
  1323. break;
  1324. }
  1325. return true;
  1326. }),
  1327. " "
  1328. )}`;
  1329. },
  1330. "chunk.childrenByOrder[]": items => `(${joinOneLine(items)})`,
  1331. chunkGroup: items => joinExplicitNewLine(items, " "),
  1332. chunkGroupAsset: joinOneLine,
  1333. chunkGroupChildGroup: joinOneLine,
  1334. chunkGroupChild: joinOneLine,
  1335. moduleReason: (items, { moduleReason }) => {
  1336. let hasName = false;
  1337. return joinExplicitNewLine(
  1338. items.map(item => {
  1339. switch (item.element) {
  1340. case "moduleId":
  1341. if (moduleReason.moduleId === moduleReason.module && item.content)
  1342. hasName = true;
  1343. break;
  1344. case "module":
  1345. if (hasName) return false;
  1346. break;
  1347. case "resolvedModule":
  1348. if (moduleReason.module === moduleReason.resolvedModule)
  1349. return false;
  1350. break;
  1351. case "children":
  1352. if (item.content) {
  1353. return {
  1354. ...item,
  1355. content: `\n${item.content}\n`
  1356. };
  1357. }
  1358. break;
  1359. }
  1360. return item;
  1361. }),
  1362. " "
  1363. );
  1364. },
  1365. "module.profile": joinInBrackets,
  1366. moduleIssuer: joinOneLine,
  1367. chunkOrigin: items => `> ${joinOneLine(items)}`,
  1368. "errors[].error": joinError(true),
  1369. "warnings[].error": joinError(false),
  1370. error: items => joinExplicitNewLine(items, ""),
  1371. "error.errors[].error": items =>
  1372. indent(`[errors]: ${joinExplicitNewLine(items, "")}`, " "),
  1373. loggingGroup: items => joinExplicitNewLine(items, "").trimEnd(),
  1374. moduleTraceItem: items => ` @ ${joinOneLine(items)}`,
  1375. moduleTraceDependency: joinOneLine
  1376. };
  1377. /** @type {Record<keyof KnownStatsPrinterColorFunctions, string>} */
  1378. const AVAILABLE_COLORS = {
  1379. bold: "\u001B[1m",
  1380. yellow: "\u001B[1m\u001B[33m",
  1381. red: "\u001B[1m\u001B[31m",
  1382. green: "\u001B[1m\u001B[32m",
  1383. cyan: "\u001B[1m\u001B[36m",
  1384. magenta: "\u001B[1m\u001B[35m"
  1385. };
  1386. /** @typedef {Required<{ [Key in keyof KnownStatsPrinterFormatters]: (value: Parameters<NonNullable<KnownStatsPrinterFormatters[Key]>>[0], options: Required<KnownStatsPrinterColorFunctions> & StatsPrinterContext, ...args: TODO[]) => string }>} AvailableFormats */
  1387. /** @type {AvailableFormats} */
  1388. const AVAILABLE_FORMATS = {
  1389. formatChunkId: (id, { yellow }, direction) => {
  1390. switch (direction) {
  1391. case "parent":
  1392. return `<{${yellow(id)}}>`;
  1393. case "sibling":
  1394. return `={${yellow(id)}}=`;
  1395. case "child":
  1396. return `>{${yellow(id)}}<`;
  1397. default:
  1398. return `{${yellow(id)}}`;
  1399. }
  1400. },
  1401. formatModuleId: id => `[${id}]`,
  1402. formatFilename: (filename, { green, yellow }, oversize) =>
  1403. (oversize ? yellow : green)(filename),
  1404. formatFlag: flag => `[${flag}]`,
  1405. formatLayer: layer => `(in ${layer})`,
  1406. formatSize: require("../SizeFormatHelpers").formatSize,
  1407. formatDateTime: (dateTime, { bold }) => {
  1408. const d = new Date(dateTime);
  1409. const x = twoDigit;
  1410. const date = `${d.getFullYear()}-${x(d.getMonth() + 1)}-${x(d.getDate())}`;
  1411. const time = `${x(d.getHours())}:${x(d.getMinutes())}:${x(d.getSeconds())}`;
  1412. return `${date} ${bold(time)}`;
  1413. },
  1414. formatTime: (
  1415. time,
  1416. { timeReference, bold, green, yellow, red },
  1417. boldQuantity
  1418. ) => {
  1419. const unit = " ms";
  1420. if (timeReference && time !== timeReference) {
  1421. const times = [
  1422. timeReference / 2,
  1423. timeReference / 4,
  1424. timeReference / 8,
  1425. timeReference / 16
  1426. ];
  1427. if (time < times[3]) return `${time}${unit}`;
  1428. else if (time < times[2]) return bold(`${time}${unit}`);
  1429. else if (time < times[1]) return green(`${time}${unit}`);
  1430. else if (time < times[0]) return yellow(`${time}${unit}`);
  1431. return red(`${time}${unit}`);
  1432. }
  1433. return `${boldQuantity ? bold(time) : time}${unit}`;
  1434. },
  1435. formatError: (message, { green, yellow, red }) => {
  1436. if (message.includes("\u001B[")) return message;
  1437. const highlights = [
  1438. { regExp: /(Did you mean .+)/g, format: green },
  1439. {
  1440. regExp: /(Set 'mode' option to 'development' or 'production')/g,
  1441. format: green
  1442. },
  1443. { regExp: /(\(module has no exports\))/g, format: red },
  1444. { regExp: /\(possible exports: (.+)\)/g, format: green },
  1445. { regExp: /(?:^|\n)(.* doesn't exist)/g, format: red },
  1446. { regExp: /('\w+' option has not been set)/g, format: red },
  1447. {
  1448. regExp: /(Emitted value instead of an instance of Error)/g,
  1449. format: yellow
  1450. },
  1451. { regExp: /(Used? .+ instead)/gi, format: yellow },
  1452. { regExp: /\b(deprecated|must|required)\b/g, format: yellow },
  1453. {
  1454. regExp: /\b(BREAKING CHANGE)\b/gi,
  1455. format: red
  1456. },
  1457. {
  1458. regExp:
  1459. /\b(error|failed|unexpected|invalid|not found|not supported|not available|not possible|not implemented|doesn't support|conflict|conflicting|not existing|duplicate)\b/gi,
  1460. format: red
  1461. }
  1462. ];
  1463. for (const { regExp, format } of highlights) {
  1464. message = message.replace(
  1465. regExp,
  1466. /**
  1467. * @param {string} match match
  1468. * @param {string} content content
  1469. * @returns {string} result
  1470. */
  1471. (match, content) => match.replace(content, format(content))
  1472. );
  1473. }
  1474. return message;
  1475. }
  1476. };
  1477. /** @typedef {(result: string) => string} ResultModifierFn */
  1478. /** @type {Record<string, ResultModifierFn>} */
  1479. const RESULT_MODIFIER = {
  1480. "module.modules": result => indent(result, "| ")
  1481. };
  1482. /**
  1483. * @param {string[]} array array
  1484. * @param {string[]} preferredOrder preferred order
  1485. * @returns {string[]} result
  1486. */
  1487. const createOrder = (array, preferredOrder) => {
  1488. const originalArray = array.slice();
  1489. /** @type {Set<string>} */
  1490. const set = new Set(array);
  1491. /** @type {Set<string>} */
  1492. const usedSet = new Set();
  1493. array.length = 0;
  1494. for (const element of preferredOrder) {
  1495. if (element.endsWith("!") || set.has(element)) {
  1496. array.push(element);
  1497. usedSet.add(element);
  1498. }
  1499. }
  1500. for (const element of originalArray) {
  1501. if (!usedSet.has(element)) {
  1502. array.push(element);
  1503. }
  1504. }
  1505. return array;
  1506. };
  1507. const PLUGIN_NAME = "DefaultStatsPrinterPlugin";
  1508. class DefaultStatsPrinterPlugin {
  1509. /**
  1510. * Apply the plugin
  1511. * @param {Compiler} compiler the compiler instance
  1512. * @returns {void}
  1513. */
  1514. apply(compiler) {
  1515. compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
  1516. compilation.hooks.statsPrinter.tap(PLUGIN_NAME, (stats, options) => {
  1517. // Put colors into context
  1518. stats.hooks.print
  1519. .for("compilation")
  1520. .tap(PLUGIN_NAME, (compilation, context) => {
  1521. for (const color of Object.keys(AVAILABLE_COLORS)) {
  1522. const name =
  1523. /** @type {keyof KnownStatsPrinterColorFunctions} */
  1524. (color);
  1525. /** @type {string | undefined} */
  1526. let start;
  1527. if (options.colors) {
  1528. if (
  1529. typeof options.colors === "object" &&
  1530. typeof options.colors[name] === "string"
  1531. ) {
  1532. start = options.colors[name];
  1533. } else {
  1534. start = AVAILABLE_COLORS[name];
  1535. }
  1536. }
  1537. if (start) {
  1538. /** @type {ColorFunction} */
  1539. context[color] = str =>
  1540. `${start}${
  1541. typeof str === "string"
  1542. ? str.replace(
  1543. /((\u001B\[39m|\u001B\[22m|\u001B\[0m)+)/g,
  1544. `$1${start}`
  1545. )
  1546. : str
  1547. }\u001B[39m\u001B[22m`;
  1548. } else {
  1549. /**
  1550. * @param {string} str string
  1551. * @returns {string} str string
  1552. */
  1553. context[color] = str => str;
  1554. }
  1555. }
  1556. for (const format of Object.keys(AVAILABLE_FORMATS)) {
  1557. context[format] =
  1558. /**
  1559. * @param {string | number} content content
  1560. * @param {...TODO} args args
  1561. * @returns {string} result
  1562. */
  1563. (content, ...args) =>
  1564. /** @type {TODO} */
  1565. (
  1566. AVAILABLE_FORMATS[
  1567. /** @type {keyof AvailableFormats} */
  1568. (format)
  1569. ]
  1570. )(
  1571. content,
  1572. /** @type {StatsPrinterContext & Required<KnownStatsPrinterColorFunctions>} */
  1573. (context),
  1574. ...args
  1575. );
  1576. }
  1577. context.timeReference = compilation.time;
  1578. });
  1579. for (const key of Object.keys(COMPILATION_SIMPLE_PRINTERS)) {
  1580. stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) =>
  1581. /** @type {TODO} */
  1582. (
  1583. COMPILATION_SIMPLE_PRINTERS[
  1584. /** @type {keyof CompilationSimplePrinters} */
  1585. (key)
  1586. ]
  1587. )(
  1588. obj,
  1589. /** @type {DefineStatsPrinterContext<"compilation">} */
  1590. (ctx),
  1591. stats
  1592. )
  1593. );
  1594. }
  1595. for (const key of Object.keys(ASSET_SIMPLE_PRINTERS)) {
  1596. stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) =>
  1597. /** @type {NonNullable<AssetSimplePrinters[keyof AssetSimplePrinters]>} */
  1598. (
  1599. ASSET_SIMPLE_PRINTERS[
  1600. /** @type {keyof AssetSimplePrinters} */
  1601. (key)
  1602. ]
  1603. )(
  1604. obj,
  1605. /** @type {DefineStatsPrinterContext<"asset" | "asset.info">} */
  1606. (ctx),
  1607. stats
  1608. )
  1609. );
  1610. }
  1611. for (const key of Object.keys(MODULE_SIMPLE_PRINTERS)) {
  1612. stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) =>
  1613. /** @type {TODO} */
  1614. (
  1615. MODULE_SIMPLE_PRINTERS[
  1616. /** @type {keyof ModuleSimplePrinters} */
  1617. (key)
  1618. ]
  1619. )(
  1620. obj,
  1621. /** @type {DefineStatsPrinterContext<"module">} */
  1622. (ctx),
  1623. stats
  1624. )
  1625. );
  1626. }
  1627. for (const key of Object.keys(MODULE_ISSUER_PRINTERS)) {
  1628. stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) =>
  1629. /** @type {NonNullable<ModuleIssuerPrinters[keyof ModuleIssuerPrinters]>} */
  1630. (
  1631. MODULE_ISSUER_PRINTERS[
  1632. /** @type {keyof ModuleIssuerPrinters} */
  1633. (key)
  1634. ]
  1635. )(
  1636. obj,
  1637. /** @type {DefineStatsPrinterContext<"moduleIssuer">} */
  1638. (ctx),
  1639. stats
  1640. )
  1641. );
  1642. }
  1643. for (const key of Object.keys(MODULE_REASON_PRINTERS)) {
  1644. stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) =>
  1645. /** @type {TODO} */
  1646. (
  1647. MODULE_REASON_PRINTERS[
  1648. /** @type {keyof ModuleReasonsPrinters} */
  1649. (key)
  1650. ]
  1651. )(
  1652. obj,
  1653. /** @type {DefineStatsPrinterContext<"moduleReason">} */
  1654. (ctx),
  1655. stats
  1656. )
  1657. );
  1658. }
  1659. for (const key of Object.keys(MODULE_PROFILE_PRINTERS)) {
  1660. stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) =>
  1661. /** @type {NonNullable<ModuleProfilePrinters[keyof ModuleProfilePrinters]>} */
  1662. (
  1663. MODULE_PROFILE_PRINTERS[
  1664. /** @type {keyof ModuleProfilePrinters} */
  1665. (key)
  1666. ]
  1667. )(
  1668. obj,
  1669. /** @type {DefineStatsPrinterContext<"profile">} */
  1670. (ctx),
  1671. stats
  1672. )
  1673. );
  1674. }
  1675. for (const key of Object.keys(CHUNK_GROUP_PRINTERS)) {
  1676. stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) =>
  1677. /** @type {TODO} */
  1678. (
  1679. CHUNK_GROUP_PRINTERS[
  1680. /** @type {keyof ChunkGroupPrinters} */
  1681. (key)
  1682. ]
  1683. )(
  1684. obj,
  1685. /** @type {DefineStatsPrinterContext<"chunkGroupKind" | "chunkGroup">} */
  1686. (ctx),
  1687. stats
  1688. )
  1689. );
  1690. }
  1691. for (const key of Object.keys(CHUNK_PRINTERS)) {
  1692. stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) =>
  1693. /** @type {TODO} */
  1694. (CHUNK_PRINTERS[/** @type {keyof ChunkPrinters} */ (key)])(
  1695. obj,
  1696. /** @type {DefineStatsPrinterContext<"chunk">} */
  1697. (ctx),
  1698. stats
  1699. )
  1700. );
  1701. }
  1702. for (const key of Object.keys(ERROR_PRINTERS)) {
  1703. stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) =>
  1704. /** @type {TODO} */
  1705. (ERROR_PRINTERS[/** @type {keyof ErrorPrinters} */ (key)])(
  1706. obj,
  1707. /** @type {DefineStatsPrinterContext<"error">} */
  1708. (ctx),
  1709. stats
  1710. )
  1711. );
  1712. }
  1713. for (const key of Object.keys(LOG_ENTRY_PRINTERS)) {
  1714. stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) =>
  1715. /** @type {TODO} */
  1716. (
  1717. LOG_ENTRY_PRINTERS[
  1718. /** @type {keyof LogEntryPrinters} */
  1719. (key)
  1720. ]
  1721. )(
  1722. obj,
  1723. /** @type {DefineStatsPrinterContext<"logging">} */
  1724. (ctx),
  1725. stats
  1726. )
  1727. );
  1728. }
  1729. for (const key of Object.keys(MODULE_TRACE_DEPENDENCY_PRINTERS)) {
  1730. stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) =>
  1731. /** @type {NonNullable<ModuleTraceDependencyPrinters[keyof ModuleTraceDependencyPrinters]>} */
  1732. (
  1733. MODULE_TRACE_DEPENDENCY_PRINTERS[
  1734. /** @type {keyof ModuleTraceDependencyPrinters} */
  1735. (key)
  1736. ]
  1737. )(
  1738. obj,
  1739. /** @type {DefineStatsPrinterContext<"moduleTraceDependency">} */
  1740. (ctx),
  1741. stats
  1742. )
  1743. );
  1744. }
  1745. for (const key of Object.keys(MODULE_TRACE_ITEM_PRINTERS)) {
  1746. stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) =>
  1747. /** @type {NonNullable<ModuleTraceItemPrinters[keyof ModuleTraceItemPrinters]>} */
  1748. (
  1749. MODULE_TRACE_ITEM_PRINTERS[
  1750. /** @type {keyof ModuleTraceItemPrinters} */
  1751. (key)
  1752. ]
  1753. )(
  1754. obj,
  1755. /** @type {DefineStatsPrinterContext<"moduleTraceItem">} */
  1756. (ctx),
  1757. stats
  1758. )
  1759. );
  1760. }
  1761. for (const key of Object.keys(PREFERRED_ORDERS)) {
  1762. const preferredOrder = PREFERRED_ORDERS[key];
  1763. stats.hooks.sortElements
  1764. .for(key)
  1765. .tap(PLUGIN_NAME, (elements, context) => {
  1766. createOrder(elements, preferredOrder);
  1767. });
  1768. }
  1769. for (const key of Object.keys(ITEM_NAMES)) {
  1770. const itemName = ITEM_NAMES[key];
  1771. stats.hooks.getItemName
  1772. .for(key)
  1773. .tap(
  1774. PLUGIN_NAME,
  1775. typeof itemName === "string" ? () => itemName : itemName
  1776. );
  1777. }
  1778. for (const key of Object.keys(SIMPLE_ITEMS_JOINER)) {
  1779. const joiner = SIMPLE_ITEMS_JOINER[key];
  1780. stats.hooks.printItems.for(key).tap(PLUGIN_NAME, joiner);
  1781. }
  1782. for (const key of Object.keys(SIMPLE_ELEMENT_JOINERS)) {
  1783. const joiner = SIMPLE_ELEMENT_JOINERS[key];
  1784. stats.hooks.printElements
  1785. .for(key)
  1786. .tap(PLUGIN_NAME, /** @type {TODO} */ (joiner));
  1787. }
  1788. for (const key of Object.keys(RESULT_MODIFIER)) {
  1789. const modifier = RESULT_MODIFIER[key];
  1790. stats.hooks.result.for(key).tap(PLUGIN_NAME, modifier);
  1791. }
  1792. });
  1793. });
  1794. }
  1795. }
  1796. module.exports = DefaultStatsPrinterPlugin;