index.cjs 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834
  1. 'use strict';
  2. const Webpack = require('webpack');
  3. const stdEnv = require('std-env');
  4. const prettyTime = require('pretty-time');
  5. const path = require('path');
  6. const chalk = require('chalk');
  7. const _consola = require('consola');
  8. function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
  9. const Webpack__default = /*#__PURE__*/_interopDefaultLegacy(Webpack);
  10. const prettyTime__default = /*#__PURE__*/_interopDefaultLegacy(prettyTime);
  11. const path__default = /*#__PURE__*/_interopDefaultLegacy(path);
  12. const chalk__default = /*#__PURE__*/_interopDefaultLegacy(chalk);
  13. const _consola__default = /*#__PURE__*/_interopDefaultLegacy(_consola);
  14. function first(arr) {
  15. return arr[0];
  16. }
  17. function last(arr) {
  18. return arr.length ? arr[arr.length - 1] : null;
  19. }
  20. function startCase(str) {
  21. return str[0].toUpperCase() + str.substr(1);
  22. }
  23. function firstMatch(regex, str) {
  24. const m = regex.exec(str);
  25. return m ? m[0] : null;
  26. }
  27. function hasValue(s) {
  28. return s && s.length;
  29. }
  30. function removeAfter(delimiter, str) {
  31. return first(str.split(delimiter)) || "";
  32. }
  33. function removeBefore(delimiter, str) {
  34. return last(str.split(delimiter)) || "";
  35. }
  36. function range(len) {
  37. const arr = [];
  38. for (let i = 0; i < len; i++) {
  39. arr.push(i);
  40. }
  41. return arr;
  42. }
  43. function shortenPath(path$1 = "") {
  44. const cwd = process.cwd() + path.sep;
  45. return String(path$1).replace(cwd, "");
  46. }
  47. function objectValues(obj) {
  48. return Object.keys(obj).map((key) => obj[key]);
  49. }
  50. /**
  51. * @typedef MarkdownTableOptions
  52. * @property {string|null|Array.<string|null|undefined>} [align]
  53. * @property {boolean} [padding=true]
  54. * @property {boolean} [delimiterStart=true]
  55. * @property {boolean} [delimiterStart=true]
  56. * @property {boolean} [delimiterEnd=true]
  57. * @property {boolean} [alignDelimiters=true]
  58. * @property {(value: string) => number} [stringLength]
  59. */
  60. /**
  61. * Create a table from a matrix of strings.
  62. *
  63. * @param {Array.<Array.<string|null|undefined>>} table
  64. * @param {MarkdownTableOptions} [options]
  65. * @returns {string}
  66. */
  67. function markdownTable(table, options) {
  68. const settings = options || {};
  69. const align = (settings.align || []).concat();
  70. const stringLength = settings.stringLength || defaultStringLength;
  71. /** @type {number[]} Character codes as symbols for alignment per column. */
  72. const alignments = [];
  73. let rowIndex = -1;
  74. /** @type {string[][]} Cells per row. */
  75. const cellMatrix = [];
  76. /** @type {number[][]} Sizes of each cell per row. */
  77. const sizeMatrix = [];
  78. /** @type {number[]} */
  79. const longestCellByColumn = [];
  80. let mostCellsPerRow = 0;
  81. /** @type {number} */
  82. let columnIndex;
  83. /** @type {string[]} Cells of current row */
  84. let row;
  85. /** @type {number[]} Sizes of current row */
  86. let sizes;
  87. /** @type {number} Sizes of current cell */
  88. let size;
  89. /** @type {string} Current cell */
  90. let cell;
  91. /** @type {string[]} Chunks of current line. */
  92. let line;
  93. /** @type {string} */
  94. let before;
  95. /** @type {string} */
  96. let after;
  97. /** @type {number} */
  98. let code;
  99. // This is a superfluous loop if we don’t align delimiters, but otherwise we’d
  100. // do superfluous work when aligning, so optimize for aligning.
  101. while (++rowIndex < table.length) {
  102. columnIndex = -1;
  103. row = [];
  104. sizes = [];
  105. if (table[rowIndex].length > mostCellsPerRow) {
  106. mostCellsPerRow = table[rowIndex].length;
  107. }
  108. while (++columnIndex < table[rowIndex].length) {
  109. cell = serialize(table[rowIndex][columnIndex]);
  110. if (settings.alignDelimiters !== false) {
  111. size = stringLength(cell);
  112. sizes[columnIndex] = size;
  113. if (
  114. longestCellByColumn[columnIndex] === undefined ||
  115. size > longestCellByColumn[columnIndex]
  116. ) {
  117. longestCellByColumn[columnIndex] = size;
  118. }
  119. }
  120. row.push(cell);
  121. }
  122. cellMatrix[rowIndex] = row;
  123. sizeMatrix[rowIndex] = sizes;
  124. }
  125. // Figure out which alignments to use.
  126. columnIndex = -1;
  127. if (typeof align === 'object' && 'length' in align) {
  128. while (++columnIndex < mostCellsPerRow) {
  129. alignments[columnIndex] = toAlignment(align[columnIndex]);
  130. }
  131. } else {
  132. code = toAlignment(align);
  133. while (++columnIndex < mostCellsPerRow) {
  134. alignments[columnIndex] = code;
  135. }
  136. }
  137. // Inject the alignment row.
  138. columnIndex = -1;
  139. row = [];
  140. sizes = [];
  141. while (++columnIndex < mostCellsPerRow) {
  142. code = alignments[columnIndex];
  143. before = '';
  144. after = '';
  145. if (code === 99 /* `c` */) {
  146. before = ':';
  147. after = ':';
  148. } else if (code === 108 /* `l` */) {
  149. before = ':';
  150. } else if (code === 114 /* `r` */) {
  151. after = ':';
  152. }
  153. // There *must* be at least one hyphen-minus in each alignment cell.
  154. size =
  155. settings.alignDelimiters === false
  156. ? 1
  157. : Math.max(
  158. 1,
  159. longestCellByColumn[columnIndex] - before.length - after.length
  160. );
  161. cell = before + '-'.repeat(size) + after;
  162. if (settings.alignDelimiters !== false) {
  163. size = before.length + size + after.length;
  164. if (size > longestCellByColumn[columnIndex]) {
  165. longestCellByColumn[columnIndex] = size;
  166. }
  167. sizes[columnIndex] = size;
  168. }
  169. row[columnIndex] = cell;
  170. }
  171. // Inject the alignment row.
  172. cellMatrix.splice(1, 0, row);
  173. sizeMatrix.splice(1, 0, sizes);
  174. rowIndex = -1;
  175. /** @type {string[]} */
  176. const lines = [];
  177. while (++rowIndex < cellMatrix.length) {
  178. row = cellMatrix[rowIndex];
  179. sizes = sizeMatrix[rowIndex];
  180. columnIndex = -1;
  181. line = [];
  182. while (++columnIndex < mostCellsPerRow) {
  183. cell = row[columnIndex] || '';
  184. before = '';
  185. after = '';
  186. if (settings.alignDelimiters !== false) {
  187. size = longestCellByColumn[columnIndex] - (sizes[columnIndex] || 0);
  188. code = alignments[columnIndex];
  189. if (code === 114 /* `r` */) {
  190. before = ' '.repeat(size);
  191. } else if (code === 99 /* `c` */) {
  192. if (size % 2) {
  193. before = ' '.repeat(size / 2 + 0.5);
  194. after = ' '.repeat(size / 2 - 0.5);
  195. } else {
  196. before = ' '.repeat(size / 2);
  197. after = before;
  198. }
  199. } else {
  200. after = ' '.repeat(size);
  201. }
  202. }
  203. if (settings.delimiterStart !== false && !columnIndex) {
  204. line.push('|');
  205. }
  206. if (
  207. settings.padding !== false &&
  208. // Don’t add the opening space if we’re not aligning and the cell is
  209. // empty: there will be a closing space.
  210. !(settings.alignDelimiters === false && cell === '') &&
  211. (settings.delimiterStart !== false || columnIndex)
  212. ) {
  213. line.push(' ');
  214. }
  215. if (settings.alignDelimiters !== false) {
  216. line.push(before);
  217. }
  218. line.push(cell);
  219. if (settings.alignDelimiters !== false) {
  220. line.push(after);
  221. }
  222. if (settings.padding !== false) {
  223. line.push(' ');
  224. }
  225. if (
  226. settings.delimiterEnd !== false ||
  227. columnIndex !== mostCellsPerRow - 1
  228. ) {
  229. line.push('|');
  230. }
  231. }
  232. lines.push(
  233. settings.delimiterEnd === false
  234. ? line.join('').replace(/ +$/, '')
  235. : line.join('')
  236. );
  237. }
  238. return lines.join('\n')
  239. }
  240. /**
  241. * @param {string|null|undefined} [value]
  242. * @returns {string}
  243. */
  244. function serialize(value) {
  245. return value === null || value === undefined ? '' : String(value)
  246. }
  247. /**
  248. * @param {string} value
  249. * @returns {number}
  250. */
  251. function defaultStringLength(value) {
  252. return value.length
  253. }
  254. /**
  255. * @param {string|null|undefined} value
  256. * @returns {number}
  257. */
  258. function toAlignment(value) {
  259. const code = typeof value === 'string' ? value.charCodeAt(0) : 0;
  260. return code === 67 /* `C` */ || code === 99 /* `c` */
  261. ? 99 /* `c` */
  262. : code === 76 /* `L` */ || code === 108 /* `l` */
  263. ? 108 /* `l` */
  264. : code === 82 /* `R` */ || code === 114 /* `r` */
  265. ? 114 /* `r` */
  266. : 0
  267. }
  268. function isUnicodeSupported() {
  269. if (process.platform !== 'win32') {
  270. return process.env.TERM !== 'linux'; // Linux console (kernel)
  271. }
  272. return Boolean(process.env.CI) ||
  273. Boolean(process.env.WT_SESSION) || // Windows Terminal
  274. process.env.ConEmuTask === '{cmd::Cmder}' || // ConEmu and cmder
  275. process.env.TERM_PROGRAM === 'vscode' ||
  276. process.env.TERM === 'xterm-256color' ||
  277. process.env.TERM === 'alacritty';
  278. }
  279. const {platform} = process;
  280. const common = {
  281. square: '█',
  282. squareDarkShade: '▓',
  283. squareMediumShade: '▒',
  284. squareLightShade: '░',
  285. squareTop: '▀',
  286. squareBottom: '▄',
  287. squareLeft: '▌',
  288. squareRight: '▐',
  289. squareCenter: '■',
  290. bullet: '●',
  291. dot: '․',
  292. ellipsis: '…',
  293. pointerSmall: '›',
  294. triangleUp: '▲',
  295. triangleUpSmall: '▴',
  296. triangleDown: '▼',
  297. triangleDownSmall: '▾',
  298. triangleLeftSmall: '◂',
  299. triangleRightSmall: '▸',
  300. home: '⌂',
  301. heart: '♥',
  302. musicNote: '♪',
  303. musicNoteBeamed: '♫',
  304. arrowUp: '↑',
  305. arrowDown: '↓',
  306. arrowLeft: '←',
  307. arrowRight: '→',
  308. arrowLeftRight: '↔',
  309. arrowUpDown: '↕',
  310. almostEqual: '≈',
  311. notEqual: '≠',
  312. lessOrEqual: '≤',
  313. greaterOrEqual: '≥',
  314. identical: '≡',
  315. infinity: '∞',
  316. subscriptZero: '₀',
  317. subscriptOne: '₁',
  318. subscriptTwo: '₂',
  319. subscriptThree: '₃',
  320. subscriptFour: '₄',
  321. subscriptFive: '₅',
  322. subscriptSix: '₆',
  323. subscriptSeven: '₇',
  324. subscriptEight: '₈',
  325. subscriptNine: '₉',
  326. oneHalf: '½',
  327. oneThird: '⅓',
  328. oneQuarter: '¼',
  329. oneFifth: '⅕',
  330. oneSixth: '⅙',
  331. oneEighth: '⅛',
  332. twoThirds: '⅔',
  333. twoFifths: '⅖',
  334. threeQuarters: '¾',
  335. threeFifths: '⅗',
  336. threeEighths: '⅜',
  337. fourFifths: '⅘',
  338. fiveSixths: '⅚',
  339. fiveEighths: '⅝',
  340. sevenEighths: '⅞',
  341. line: '─',
  342. lineBold: '━',
  343. lineDouble: '═',
  344. lineDashed0: '┄',
  345. lineDashed1: '┅',
  346. lineDashed2: '┈',
  347. lineDashed3: '┉',
  348. lineDashed4: '╌',
  349. lineDashed5: '╍',
  350. lineDashed6: '╴',
  351. lineDashed7: '╶',
  352. lineDashed8: '╸',
  353. lineDashed9: '╺',
  354. lineDashed10: '╼',
  355. lineDashed11: '╾',
  356. lineDashed12: '−',
  357. lineDashed13: '–',
  358. lineDashed14: '‐',
  359. lineDashed15: '⁃',
  360. lineVertical: '│',
  361. lineVerticalBold: '┃',
  362. lineVerticalDouble: '║',
  363. lineVerticalDashed0: '┆',
  364. lineVerticalDashed1: '┇',
  365. lineVerticalDashed2: '┊',
  366. lineVerticalDashed3: '┋',
  367. lineVerticalDashed4: '╎',
  368. lineVerticalDashed5: '╏',
  369. lineVerticalDashed6: '╵',
  370. lineVerticalDashed7: '╷',
  371. lineVerticalDashed8: '╹',
  372. lineVerticalDashed9: '╻',
  373. lineVerticalDashed10: '╽',
  374. lineVerticalDashed11: '╿',
  375. lineDownLeft: '┐',
  376. lineDownLeftArc: '╮',
  377. lineDownBoldLeftBold: '┓',
  378. lineDownBoldLeft: '┒',
  379. lineDownLeftBold: '┑',
  380. lineDownDoubleLeftDouble: '╗',
  381. lineDownDoubleLeft: '╖',
  382. lineDownLeftDouble: '╕',
  383. lineDownRight: '┌',
  384. lineDownRightArc: '╭',
  385. lineDownBoldRightBold: '┏',
  386. lineDownBoldRight: '┎',
  387. lineDownRightBold: '┍',
  388. lineDownDoubleRightDouble: '╔',
  389. lineDownDoubleRight: '╓',
  390. lineDownRightDouble: '╒',
  391. lineUpLeft: '┘',
  392. lineUpLeftArc: '╯',
  393. lineUpBoldLeftBold: '┛',
  394. lineUpBoldLeft: '┚',
  395. lineUpLeftBold: '┙',
  396. lineUpDoubleLeftDouble: '╝',
  397. lineUpDoubleLeft: '╜',
  398. lineUpLeftDouble: '╛',
  399. lineUpRight: '└',
  400. lineUpRightArc: '╰',
  401. lineUpBoldRightBold: '┗',
  402. lineUpBoldRight: '┖',
  403. lineUpRightBold: '┕',
  404. lineUpDoubleRightDouble: '╚',
  405. lineUpDoubleRight: '╙',
  406. lineUpRightDouble: '╘',
  407. lineUpDownLeft: '┤',
  408. lineUpBoldDownBoldLeftBold: '┫',
  409. lineUpBoldDownBoldLeft: '┨',
  410. lineUpDownLeftBold: '┥',
  411. lineUpBoldDownLeftBold: '┩',
  412. lineUpDownBoldLeftBold: '┪',
  413. lineUpDownBoldLeft: '┧',
  414. lineUpBoldDownLeft: '┦',
  415. lineUpDoubleDownDoubleLeftDouble: '╣',
  416. lineUpDoubleDownDoubleLeft: '╢',
  417. lineUpDownLeftDouble: '╡',
  418. lineUpDownRight: '├',
  419. lineUpBoldDownBoldRightBold: '┣',
  420. lineUpBoldDownBoldRight: '┠',
  421. lineUpDownRightBold: '┝',
  422. lineUpBoldDownRightBold: '┡',
  423. lineUpDownBoldRightBold: '┢',
  424. lineUpDownBoldRight: '┟',
  425. lineUpBoldDownRight: '┞',
  426. lineUpDoubleDownDoubleRightDouble: '╠',
  427. lineUpDoubleDownDoubleRight: '╟',
  428. lineUpDownRightDouble: '╞',
  429. lineDownLeftRight: '┬',
  430. lineDownBoldLeftBoldRightBold: '┳',
  431. lineDownLeftBoldRightBold: '┯',
  432. lineDownBoldLeftRight: '┰',
  433. lineDownBoldLeftBoldRight: '┱',
  434. lineDownBoldLeftRightBold: '┲',
  435. lineDownLeftRightBold: '┮',
  436. lineDownLeftBoldRight: '┭',
  437. lineDownDoubleLeftDoubleRightDouble: '╦',
  438. lineDownDoubleLeftRight: '╥',
  439. lineDownLeftDoubleRightDouble: '╤',
  440. lineUpLeftRight: '┴',
  441. lineUpBoldLeftBoldRightBold: '┻',
  442. lineUpLeftBoldRightBold: '┷',
  443. lineUpBoldLeftRight: '┸',
  444. lineUpBoldLeftBoldRight: '┹',
  445. lineUpBoldLeftRightBold: '┺',
  446. lineUpLeftRightBold: '┶',
  447. lineUpLeftBoldRight: '┵',
  448. lineUpDoubleLeftDoubleRightDouble: '╩',
  449. lineUpDoubleLeftRight: '╨',
  450. lineUpLeftDoubleRightDouble: '╧',
  451. lineUpDownLeftRight: '┼',
  452. lineUpBoldDownBoldLeftBoldRightBold: '╋',
  453. lineUpDownBoldLeftBoldRightBold: '╈',
  454. lineUpBoldDownLeftBoldRightBold: '╇',
  455. lineUpBoldDownBoldLeftRightBold: '╊',
  456. lineUpBoldDownBoldLeftBoldRight: '╉',
  457. lineUpBoldDownLeftRight: '╀',
  458. lineUpDownBoldLeftRight: '╁',
  459. lineUpDownLeftBoldRight: '┽',
  460. lineUpDownLeftRightBold: '┾',
  461. lineUpBoldDownBoldLeftRight: '╂',
  462. lineUpDownLeftBoldRightBold: '┿',
  463. lineUpBoldDownLeftBoldRight: '╃',
  464. lineUpBoldDownLeftRightBold: '╄',
  465. lineUpDownBoldLeftBoldRight: '╅',
  466. lineUpDownBoldLeftRightBold: '╆',
  467. lineUpDoubleDownDoubleLeftDoubleRightDouble: '╬',
  468. lineUpDoubleDownDoubleLeftRight: '╫',
  469. lineUpDownLeftDoubleRightDouble: '╪',
  470. lineCross: '╳',
  471. lineBackslash: '╲',
  472. lineSlash: '╱'
  473. };
  474. const mainSymbols = {
  475. ...common,
  476. // The main symbols for those do not look that good on Ubuntu.
  477. ...(
  478. platform === 'linux' ?
  479. {
  480. circleQuestionMark: '?⃝',
  481. questionMarkPrefix: '?⃝'
  482. } :
  483. {
  484. circleQuestionMark: '?',
  485. questionMarkPrefix: '?'
  486. }
  487. ),
  488. tick: '✔',
  489. info: 'ℹ',
  490. warning: '⚠',
  491. cross: '✖',
  492. squareSmall: '◻',
  493. squareSmallFilled: '◼',
  494. circle: '◯',
  495. circleFilled: '◉',
  496. circleDotted: '◌',
  497. circleDouble: '◎',
  498. circleCircle: 'ⓞ',
  499. circleCross: 'ⓧ',
  500. circlePipe: 'Ⓘ',
  501. radioOn: '◉',
  502. radioOff: '◯',
  503. checkboxOn: '☒',
  504. checkboxOff: '☐',
  505. checkboxCircleOn: 'ⓧ',
  506. checkboxCircleOff: 'Ⓘ',
  507. pointer: '❯',
  508. triangleUpOutline: '△',
  509. triangleLeft: '◀',
  510. triangleRight: '▶',
  511. lozenge: '◆',
  512. lozengeOutline: '◇',
  513. hamburger: '☰',
  514. smiley: '㋡',
  515. mustache: '෴',
  516. star: '★',
  517. play: '▶',
  518. nodejs: '⬢',
  519. oneSeventh: '⅐',
  520. oneNinth: '⅑',
  521. oneTenth: '⅒'
  522. };
  523. const fallbackSymbols = {
  524. ...common,
  525. tick: '√',
  526. info: 'i',
  527. warning: '‼',
  528. cross: '×',
  529. squareSmall: '□',
  530. squareSmallFilled: '■',
  531. circle: '( )',
  532. circleFilled: '(*)',
  533. circleDotted: '( )',
  534. circleDouble: '( )',
  535. circleCircle: '(○)',
  536. circleCross: '(×)',
  537. circlePipe: '(│)',
  538. circleQuestionMark: '(?)',
  539. radioOn: '(*)',
  540. radioOff: '( )',
  541. checkboxOn: '[×]',
  542. checkboxOff: '[ ]',
  543. checkboxCircleOn: '(×)',
  544. checkboxCircleOff: '( )',
  545. questionMarkPrefix: '?',
  546. pointer: '>',
  547. triangleUpOutline: '∆',
  548. triangleLeft: '◄',
  549. triangleRight: '►',
  550. lozenge: '♦',
  551. lozengeOutline: '◊',
  552. hamburger: '≡',
  553. smiley: '☺',
  554. mustache: '┌─┐',
  555. star: '✶',
  556. play: '►',
  557. nodejs: '♦',
  558. oneSeventh: '1/7',
  559. oneNinth: '1/9',
  560. oneTenth: '1/10'
  561. };
  562. const shouldUseMain = isUnicodeSupported();
  563. const figures = shouldUseMain ? mainSymbols : fallbackSymbols;
  564. const { bullet, tick, cross, pointerSmall, radioOff } = figures;
  565. const nodeModules = `${path.delimiter}node_modules${path.delimiter}`;
  566. const BAR_LENGTH = 25;
  567. const BLOCK_CHAR = "\u2588";
  568. const BLOCK_CHAR2 = "\u2588";
  569. const NEXT = " " + chalk__default.blue(pointerSmall) + " ";
  570. const BULLET = bullet;
  571. const TICK = tick;
  572. const CROSS = cross;
  573. const CIRCLE_OPEN = radioOff;
  574. const consola = _consola__default.withTag("webpackbar");
  575. const colorize = (color) => {
  576. if (color[0] === "#") {
  577. return chalk__default.hex(color);
  578. }
  579. return chalk__default[color] || chalk__default.keyword(color);
  580. };
  581. const renderBar = (progress, color) => {
  582. const w = progress * (BAR_LENGTH / 100);
  583. const bg = chalk__default.white(BLOCK_CHAR);
  584. const fg = colorize(color)(BLOCK_CHAR2);
  585. return range(BAR_LENGTH).map((i) => i < w ? fg : bg).join("");
  586. };
  587. function createTable(data) {
  588. return markdownTable(data);
  589. }
  590. function ellipsisLeft(str, n) {
  591. if (str.length <= n - 3) {
  592. return str;
  593. }
  594. return `...${str.substr(str.length - n - 1)}`;
  595. }
  596. const parseRequest = (requestStr) => {
  597. const parts = (requestStr || "").split("!");
  598. const file = path__default.relative(process.cwd(), removeAfter("?", removeBefore(nodeModules, parts.pop())));
  599. const loaders = parts.map((part) => firstMatch(/[a-z0-9-@]+-loader/, part)).filter(hasValue);
  600. return {
  601. file: hasValue(file) ? file : null,
  602. loaders
  603. };
  604. };
  605. const formatRequest = (request) => {
  606. const loaders = request.loaders.join(NEXT);
  607. if (!loaders.length) {
  608. return request.file || "";
  609. }
  610. return `${loaders}${NEXT}${request.file}`;
  611. };
  612. function hook(compiler, hookName, fn) {
  613. if (compiler.hooks) {
  614. compiler.hooks[hookName].tap("WebpackBar:" + hookName, fn);
  615. } else {
  616. compiler.plugin(hookName, fn);
  617. }
  618. }
  619. const ESC = '\u001B[';
  620. const OSC = '\u001B]';
  621. const BEL = '\u0007';
  622. const SEP = ';';
  623. const isTerminalApp = process.env.TERM_PROGRAM === 'Apple_Terminal';
  624. const ansiEscapes = {};
  625. ansiEscapes.cursorTo = (x, y) => {
  626. if (typeof x !== 'number') {
  627. throw new TypeError('The `x` argument is required');
  628. }
  629. if (typeof y !== 'number') {
  630. return ESC + (x + 1) + 'G';
  631. }
  632. return ESC + (y + 1) + ';' + (x + 1) + 'H';
  633. };
  634. ansiEscapes.cursorMove = (x, y) => {
  635. if (typeof x !== 'number') {
  636. throw new TypeError('The `x` argument is required');
  637. }
  638. let returnValue = '';
  639. if (x < 0) {
  640. returnValue += ESC + (-x) + 'D';
  641. } else if (x > 0) {
  642. returnValue += ESC + x + 'C';
  643. }
  644. if (y < 0) {
  645. returnValue += ESC + (-y) + 'A';
  646. } else if (y > 0) {
  647. returnValue += ESC + y + 'B';
  648. }
  649. return returnValue;
  650. };
  651. ansiEscapes.cursorUp = (count = 1) => ESC + count + 'A';
  652. ansiEscapes.cursorDown = (count = 1) => ESC + count + 'B';
  653. ansiEscapes.cursorForward = (count = 1) => ESC + count + 'C';
  654. ansiEscapes.cursorBackward = (count = 1) => ESC + count + 'D';
  655. ansiEscapes.cursorLeft = ESC + 'G';
  656. ansiEscapes.cursorSavePosition = isTerminalApp ? '\u001B7' : ESC + 's';
  657. ansiEscapes.cursorRestorePosition = isTerminalApp ? '\u001B8' : ESC + 'u';
  658. ansiEscapes.cursorGetPosition = ESC + '6n';
  659. ansiEscapes.cursorNextLine = ESC + 'E';
  660. ansiEscapes.cursorPrevLine = ESC + 'F';
  661. ansiEscapes.cursorHide = ESC + '?25l';
  662. ansiEscapes.cursorShow = ESC + '?25h';
  663. ansiEscapes.eraseLines = count => {
  664. let clear = '';
  665. for (let i = 0; i < count; i++) {
  666. clear += ansiEscapes.eraseLine + (i < count - 1 ? ansiEscapes.cursorUp() : '');
  667. }
  668. if (count) {
  669. clear += ansiEscapes.cursorLeft;
  670. }
  671. return clear;
  672. };
  673. ansiEscapes.eraseEndLine = ESC + 'K';
  674. ansiEscapes.eraseStartLine = ESC + '1K';
  675. ansiEscapes.eraseLine = ESC + '2K';
  676. ansiEscapes.eraseDown = ESC + 'J';
  677. ansiEscapes.eraseUp = ESC + '1J';
  678. ansiEscapes.eraseScreen = ESC + '2J';
  679. ansiEscapes.scrollUp = ESC + 'S';
  680. ansiEscapes.scrollDown = ESC + 'T';
  681. ansiEscapes.clearScreen = '\u001Bc';
  682. ansiEscapes.clearTerminal = process.platform === 'win32' ?
  683. `${ansiEscapes.eraseScreen}${ESC}0f` :
  684. // 1. Erases the screen (Only done in case `2` is not supported)
  685. // 2. Erases the whole screen including scrollback buffer
  686. // 3. Moves cursor to the top-left position
  687. // More info: https://www.real-world-systems.com/docs/ANSIcode.html
  688. `${ansiEscapes.eraseScreen}${ESC}3J${ESC}H`;
  689. ansiEscapes.beep = BEL;
  690. ansiEscapes.link = (text, url) => {
  691. return [
  692. OSC,
  693. '8',
  694. SEP,
  695. SEP,
  696. url,
  697. BEL,
  698. text,
  699. OSC,
  700. '8',
  701. SEP,
  702. SEP,
  703. BEL
  704. ].join('');
  705. };
  706. ansiEscapes.image = (buffer, options = {}) => {
  707. let returnValue = `${OSC}1337;File=inline=1`;
  708. if (options.width) {
  709. returnValue += `;width=${options.width}`;
  710. }
  711. if (options.height) {
  712. returnValue += `;height=${options.height}`;
  713. }
  714. if (options.preserveAspectRatio === false) {
  715. returnValue += ';preserveAspectRatio=0';
  716. }
  717. return returnValue + ':' + buffer.toString('base64') + BEL;
  718. };
  719. ansiEscapes.iTerm = {
  720. setCwd: (cwd = process.cwd()) => `${OSC}50;CurrentDir=${cwd}${BEL}`,
  721. annotation: (message, options = {}) => {
  722. let returnValue = `${OSC}1337;`;
  723. const hasX = typeof options.x !== 'undefined';
  724. const hasY = typeof options.y !== 'undefined';
  725. if ((hasX || hasY) && !(hasX && hasY && typeof options.length !== 'undefined')) {
  726. throw new Error('`x`, `y` and `length` must be defined when `x` or `y` is defined');
  727. }
  728. message = message.replace(/\|/g, '');
  729. returnValue += options.isHidden ? 'AddHiddenAnnotation=' : 'AddAnnotation=';
  730. if (options.length > 0) {
  731. returnValue +=
  732. (hasX ?
  733. [message, options.length, options.x, options.y] :
  734. [options.length, message]).join('|');
  735. } else {
  736. returnValue += message;
  737. }
  738. return returnValue + BEL;
  739. }
  740. };
  741. function ansiRegex({onlyFirst = false} = {}) {
  742. const pattern = [
  743. '[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
  744. '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))'
  745. ].join('|');
  746. return new RegExp(pattern, onlyFirst ? undefined : 'g');
  747. }
  748. function stripAnsi(string) {
  749. if (typeof string !== 'string') {
  750. throw new TypeError(`Expected a \`string\`, got \`${typeof string}\``);
  751. }
  752. return string.replace(ansiRegex(), '');
  753. }
  754. /* eslint-disable yoda */
  755. function isFullwidthCodePoint(codePoint) {
  756. if (!Number.isInteger(codePoint)) {
  757. return false;
  758. }
  759. // Code points are derived from:
  760. // https://unicode.org/Public/UNIDATA/EastAsianWidth.txt
  761. return codePoint >= 0x1100 && (
  762. codePoint <= 0x115F || // Hangul Jamo
  763. codePoint === 0x2329 || // LEFT-POINTING ANGLE BRACKET
  764. codePoint === 0x232A || // RIGHT-POINTING ANGLE BRACKET
  765. // CJK Radicals Supplement .. Enclosed CJK Letters and Months
  766. (0x2E80 <= codePoint && codePoint <= 0x3247 && codePoint !== 0x303F) ||
  767. // Enclosed CJK Letters and Months .. CJK Unified Ideographs Extension A
  768. (0x3250 <= codePoint && codePoint <= 0x4DBF) ||
  769. // CJK Unified Ideographs .. Yi Radicals
  770. (0x4E00 <= codePoint && codePoint <= 0xA4C6) ||
  771. // Hangul Jamo Extended-A
  772. (0xA960 <= codePoint && codePoint <= 0xA97C) ||
  773. // Hangul Syllables
  774. (0xAC00 <= codePoint && codePoint <= 0xD7A3) ||
  775. // CJK Compatibility Ideographs
  776. (0xF900 <= codePoint && codePoint <= 0xFAFF) ||
  777. // Vertical Forms
  778. (0xFE10 <= codePoint && codePoint <= 0xFE19) ||
  779. // CJK Compatibility Forms .. Small Form Variants
  780. (0xFE30 <= codePoint && codePoint <= 0xFE6B) ||
  781. // Halfwidth and Fullwidth Forms
  782. (0xFF01 <= codePoint && codePoint <= 0xFF60) ||
  783. (0xFFE0 <= codePoint && codePoint <= 0xFFE6) ||
  784. // Kana Supplement
  785. (0x1B000 <= codePoint && codePoint <= 0x1B001) ||
  786. // Enclosed Ideographic Supplement
  787. (0x1F200 <= codePoint && codePoint <= 0x1F251) ||
  788. // CJK Unified Ideographs Extension B .. Tertiary Ideographic Plane
  789. (0x20000 <= codePoint && codePoint <= 0x3FFFD)
  790. );
  791. }
  792. var emojiRegex = function () {
  793. // https://mths.be/emoji
  794. return /\uD83C\uDFF4\uDB40\uDC67\uDB40\uDC62(?:\uDB40\uDC77\uDB40\uDC6C\uDB40\uDC73|\uDB40\uDC73\uDB40\uDC63\uDB40\uDC74|\uDB40\uDC65\uDB40\uDC6E\uDB40\uDC67)\uDB40\uDC7F|(?:\uD83E\uDDD1\uD83C\uDFFF\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB-\uDFFE])|(?:\uD83E\uDDD1\uD83C\uDFFE\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFD\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFC\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFB\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFB\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFC-\uDFFF])|\uD83D\uDC68(?:\uD83C\uDFFB(?:\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF]))|\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFC-\uDFFF])|[\u2695\u2696\u2708]\uFE0F|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))?|(?:\uD83C[\uDFFC-\uDFFF])\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF]))|\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83D\uDC68|(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFE])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])\uFE0F|\u200D(?:(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D[\uDC66\uDC67])|\uD83D[\uDC66\uDC67])|\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC)?|(?:\uD83D\uDC69(?:\uD83C\uDFFB\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|(?:\uD83C[\uDFFC-\uDFFF])\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69]))|\uD83E\uDDD1(?:\uD83C[\uDFFB-\uDFFF])\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1)(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC69(?:\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFB\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83E\uDDD1(?:\u200D(?:\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFB\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83D\uDC69\u200D\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D[\uDC66\uDC67])|\uD83D\uDC69\u200D\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|(?:\uD83D\uDC41\uFE0F\u200D\uD83D\uDDE8|\uD83E\uDDD1(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|\uD83D\uDC69(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|\uD83D\uDE36\u200D\uD83C\uDF2B|\uD83C\uDFF3\uFE0F\u200D\u26A7|\uD83D\uDC3B\u200D\u2744|(?:(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF])\u200D[\u2640\u2642]|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642]|\uD83C\uDFF4\u200D\u2620|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])\u200D[\u2640\u2642]|[\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u2328\u23CF\u23ED-\u23EF\u23F1\u23F2\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB\u25FC\u2600-\u2604\u260E\u2611\u2618\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u2692\u2694-\u2697\u2699\u269B\u269C\u26A0\u26A7\u26B0\u26B1\u26C8\u26CF\u26D1\u26D3\u26E9\u26F0\u26F1\u26F4\u26F7\u26F8\u2702\u2708\u2709\u270F\u2712\u2714\u2716\u271D\u2721\u2733\u2734\u2744\u2747\u2763\u27A1\u2934\u2935\u2B05-\u2B07\u3030\u303D\u3297\u3299]|\uD83C[\uDD70\uDD71\uDD7E\uDD7F\uDE02\uDE37\uDF21\uDF24-\uDF2C\uDF36\uDF7D\uDF96\uDF97\uDF99-\uDF9B\uDF9E\uDF9F\uDFCD\uDFCE\uDFD4-\uDFDF\uDFF5\uDFF7]|\uD83D[\uDC3F\uDCFD\uDD49\uDD4A\uDD6F\uDD70\uDD73\uDD76-\uDD79\uDD87\uDD8A-\uDD8D\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA\uDECB\uDECD-\uDECF\uDEE0-\uDEE5\uDEE9\uDEF0\uDEF3])\uFE0F|\uD83C\uDFF3\uFE0F\u200D\uD83C\uDF08|\uD83D\uDC69\u200D\uD83D\uDC67|\uD83D\uDC69\u200D\uD83D\uDC66|\uD83D\uDE35\u200D\uD83D\uDCAB|\uD83D\uDE2E\u200D\uD83D\uDCA8|\uD83D\uDC15\u200D\uD83E\uDDBA|\uD83E\uDDD1(?:\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC|\uD83C\uDFFB)?|\uD83D\uDC69(?:\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC|\uD83C\uDFFB)?|\uD83C\uDDFD\uD83C\uDDF0|\uD83C\uDDF6\uD83C\uDDE6|\uD83C\uDDF4\uD83C\uDDF2|\uD83D\uDC08\u200D\u2B1B|\u2764\uFE0F\u200D(?:\uD83D\uDD25|\uD83E\uDE79)|\uD83D\uDC41\uFE0F|\uD83C\uDFF3\uFE0F|\uD83C\uDDFF(?:\uD83C[\uDDE6\uDDF2\uDDFC])|\uD83C\uDDFE(?:\uD83C[\uDDEA\uDDF9])|\uD83C\uDDFC(?:\uD83C[\uDDEB\uDDF8])|\uD83C\uDDFB(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA])|\uD83C\uDDFA(?:\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF])|\uD83C\uDDF9(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF])|\uD83C\uDDF8(?:\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF])|\uD83C\uDDF7(?:\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC])|\uD83C\uDDF5(?:\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE])|\uD83C\uDDF3(?:\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF])|\uD83C\uDDF2(?:\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF])|\uD83C\uDDF1(?:\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE])|\uD83C\uDDF0(?:\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF])|\uD83C\uDDEF(?:\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5])|\uD83C\uDDEE(?:\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9])|\uD83C\uDDED(?:\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA])|\uD83C\uDDEC(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE])|\uD83C\uDDEB(?:\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7])|\uD83C\uDDEA(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA])|\uD83C\uDDE9(?:\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF])|\uD83C\uDDE8(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF5\uDDF7\uDDFA-\uDDFF])|\uD83C\uDDE7(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF])|\uD83C\uDDE6(?:\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF])|[#\*0-9]\uFE0F\u20E3|\u2764\uFE0F|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])(?:\uD83C[\uDFFB-\uDFFF])|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])|\uD83C\uDFF4|(?:[\u270A\u270B]|\uD83C[\uDF85\uDFC2\uDFC7]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1C\uDD1E\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5])(?:\uD83C[\uDFFB-\uDFFF])|(?:[\u261D\u270C\u270D]|\uD83D[\uDD74\uDD90])(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])|[\u270A\u270B]|\uD83C[\uDF85\uDFC2\uDFC7]|\uD83D[\uDC08\uDC15\uDC3B\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE2E\uDE35\uDE36\uDE4C\uDE4F\uDEC0\uDECC]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1C\uDD1E\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5]|\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD]|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF]|[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF84\uDF86-\uDF93\uDFA0-\uDFC1\uDFC5\uDFC6\uDFC8\uDFC9\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC07\uDC09-\uDC14\uDC16-\uDC3A\uDC3C-\uDC3E\uDC40\uDC44\uDC45\uDC51-\uDC65\uDC6A\uDC79-\uDC7B\uDC7D-\uDC80\uDC84\uDC88-\uDC8E\uDC90\uDC92-\uDCA9\uDCAB-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDDA4\uDDFB-\uDE2D\uDE2F-\uDE34\uDE37-\uDE44\uDE48-\uDE4A\uDE80-\uDEA2\uDEA4-\uDEB3\uDEB7-\uDEBF\uDEC1-\uDEC5\uDED0-\uDED2\uDED5-\uDED7\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0D\uDD0E\uDD10-\uDD17\uDD1D\uDD20-\uDD25\uDD27-\uDD2F\uDD3A\uDD3F-\uDD45\uDD47-\uDD76\uDD78\uDD7A-\uDDB4\uDDB7\uDDBA\uDDBC-\uDDCB\uDDD0\uDDE0-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6]|(?:[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u270A\u270B\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF93\uDFA0-\uDFCA\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF4\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC3E\uDC40\uDC42-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDD7A\uDD95\uDD96\uDDA4\uDDFB-\uDE4F\uDE80-\uDEC5\uDECC\uDED0-\uDED2\uDED5-\uDED7\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0C-\uDD3A\uDD3C-\uDD45\uDD47-\uDD78\uDD7A-\uDDCB\uDDCD-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6])|(?:[#\*0-9\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23E9-\u23F3\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB-\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u261D\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692-\u2697\u2699\u269B\u269C\u26A0\u26A1\u26A7\u26AA\u26AB\u26B0\u26B1\u26BD\u26BE\u26C4\u26C5\u26C8\u26CE\u26CF\u26D1\u26D3\u26D4\u26E9\u26EA\u26F0-\u26F5\u26F7-\u26FA\u26FD\u2702\u2705\u2708-\u270D\u270F\u2712\u2714\u2716\u271D\u2721\u2728\u2733\u2734\u2744\u2747\u274C\u274E\u2753-\u2755\u2757\u2763\u2764\u2795-\u2797\u27A1\u27B0\u27BF\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B50\u2B55\u3030\u303D\u3297\u3299]|\uD83C[\uDC04\uDCCF\uDD70\uDD71\uDD7E\uDD7F\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE02\uDE1A\uDE2F\uDE32-\uDE3A\uDE50\uDE51\uDF00-\uDF21\uDF24-\uDF93\uDF96\uDF97\uDF99-\uDF9B\uDF9E-\uDFF0\uDFF3-\uDFF5\uDFF7-\uDFFF]|\uD83D[\uDC00-\uDCFD\uDCFF-\uDD3D\uDD49-\uDD4E\uDD50-\uDD67\uDD6F\uDD70\uDD73-\uDD7A\uDD87\uDD8A-\uDD8D\uDD90\uDD95\uDD96\uDDA4\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA-\uDE4F\uDE80-\uDEC5\uDECB-\uDED2\uDED5-\uDED7\uDEE0-\uDEE5\uDEE9\uDEEB\uDEEC\uDEF0\uDEF3-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0C-\uDD3A\uDD3C-\uDD45\uDD47-\uDD78\uDD7A-\uDDCB\uDDCD-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6])\uFE0F|(?:[\u261D\u26F9\u270A-\u270D]|\uD83C[\uDF85\uDFC2-\uDFC4\uDFC7\uDFCA-\uDFCC]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66-\uDC78\uDC7C\uDC81-\uDC83\uDC85-\uDC87\uDC8F\uDC91\uDCAA\uDD74\uDD75\uDD7A\uDD90\uDD95\uDD96\uDE45-\uDE47\uDE4B-\uDE4F\uDEA3\uDEB4-\uDEB6\uDEC0\uDECC]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1F\uDD26\uDD30-\uDD39\uDD3C-\uDD3E\uDD77\uDDB5\uDDB6\uDDB8\uDDB9\uDDBB\uDDCD-\uDDCF\uDDD1-\uDDDD])/g;
  795. };
  796. function stringWidth(string) {
  797. if (typeof string !== 'string' || string.length === 0) {
  798. return 0;
  799. }
  800. string = stripAnsi(string);
  801. if (string.length === 0) {
  802. return 0;
  803. }
  804. string = string.replace(emojiRegex(), ' ');
  805. let width = 0;
  806. for (let index = 0; index < string.length; index++) {
  807. const codePoint = string.codePointAt(index);
  808. // Ignore control characters
  809. if (codePoint <= 0x1F || (codePoint >= 0x7F && codePoint <= 0x9F)) {
  810. continue;
  811. }
  812. // Ignore combining characters
  813. if (codePoint >= 0x300 && codePoint <= 0x36F) {
  814. continue;
  815. }
  816. // Surrogates
  817. if (codePoint > 0xFFFF) {
  818. index++;
  819. }
  820. width += isFullwidthCodePoint(codePoint) ? 2 : 1;
  821. }
  822. return width;
  823. }
  824. const ANSI_BACKGROUND_OFFSET = 10;
  825. const wrapAnsi16 = (offset = 0) => code => `\u001B[${code + offset}m`;
  826. const wrapAnsi256 = (offset = 0) => code => `\u001B[${38 + offset};5;${code}m`;
  827. const wrapAnsi16m = (offset = 0) => (red, green, blue) => `\u001B[${38 + offset};2;${red};${green};${blue}m`;
  828. function assembleStyles() {
  829. const codes = new Map();
  830. const styles = {
  831. modifier: {
  832. reset: [0, 0],
  833. // 21 isn't widely supported and 22 does the same thing
  834. bold: [1, 22],
  835. dim: [2, 22],
  836. italic: [3, 23],
  837. underline: [4, 24],
  838. overline: [53, 55],
  839. inverse: [7, 27],
  840. hidden: [8, 28],
  841. strikethrough: [9, 29]
  842. },
  843. color: {
  844. black: [30, 39],
  845. red: [31, 39],
  846. green: [32, 39],
  847. yellow: [33, 39],
  848. blue: [34, 39],
  849. magenta: [35, 39],
  850. cyan: [36, 39],
  851. white: [37, 39],
  852. // Bright color
  853. blackBright: [90, 39],
  854. redBright: [91, 39],
  855. greenBright: [92, 39],
  856. yellowBright: [93, 39],
  857. blueBright: [94, 39],
  858. magentaBright: [95, 39],
  859. cyanBright: [96, 39],
  860. whiteBright: [97, 39]
  861. },
  862. bgColor: {
  863. bgBlack: [40, 49],
  864. bgRed: [41, 49],
  865. bgGreen: [42, 49],
  866. bgYellow: [43, 49],
  867. bgBlue: [44, 49],
  868. bgMagenta: [45, 49],
  869. bgCyan: [46, 49],
  870. bgWhite: [47, 49],
  871. // Bright color
  872. bgBlackBright: [100, 49],
  873. bgRedBright: [101, 49],
  874. bgGreenBright: [102, 49],
  875. bgYellowBright: [103, 49],
  876. bgBlueBright: [104, 49],
  877. bgMagentaBright: [105, 49],
  878. bgCyanBright: [106, 49],
  879. bgWhiteBright: [107, 49]
  880. }
  881. };
  882. // Alias bright black as gray (and grey)
  883. styles.color.gray = styles.color.blackBright;
  884. styles.bgColor.bgGray = styles.bgColor.bgBlackBright;
  885. styles.color.grey = styles.color.blackBright;
  886. styles.bgColor.bgGrey = styles.bgColor.bgBlackBright;
  887. for (const [groupName, group] of Object.entries(styles)) {
  888. for (const [styleName, style] of Object.entries(group)) {
  889. styles[styleName] = {
  890. open: `\u001B[${style[0]}m`,
  891. close: `\u001B[${style[1]}m`
  892. };
  893. group[styleName] = styles[styleName];
  894. codes.set(style[0], style[1]);
  895. }
  896. Object.defineProperty(styles, groupName, {
  897. value: group,
  898. enumerable: false
  899. });
  900. }
  901. Object.defineProperty(styles, 'codes', {
  902. value: codes,
  903. enumerable: false
  904. });
  905. styles.color.close = '\u001B[39m';
  906. styles.bgColor.close = '\u001B[49m';
  907. styles.color.ansi = wrapAnsi16();
  908. styles.color.ansi256 = wrapAnsi256();
  909. styles.color.ansi16m = wrapAnsi16m();
  910. styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
  911. styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
  912. styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
  913. // From https://github.com/Qix-/color-convert/blob/3f0e0d4e92e235796ccb17f6e85c72094a651f49/conversions.js
  914. Object.defineProperties(styles, {
  915. rgbToAnsi256: {
  916. value: (red, green, blue) => {
  917. // We use the extended greyscale palette here, with the exception of
  918. // black and white. normal palette only has 4 greyscale shades.
  919. if (red === green && green === blue) {
  920. if (red < 8) {
  921. return 16;
  922. }
  923. if (red > 248) {
  924. return 231;
  925. }
  926. return Math.round(((red - 8) / 247) * 24) + 232;
  927. }
  928. return 16 +
  929. (36 * Math.round(red / 255 * 5)) +
  930. (6 * Math.round(green / 255 * 5)) +
  931. Math.round(blue / 255 * 5);
  932. },
  933. enumerable: false
  934. },
  935. hexToRgb: {
  936. value: hex => {
  937. const matches = /(?<colorString>[a-f\d]{6}|[a-f\d]{3})/i.exec(hex.toString(16));
  938. if (!matches) {
  939. return [0, 0, 0];
  940. }
  941. let {colorString} = matches.groups;
  942. if (colorString.length === 3) {
  943. colorString = colorString.split('').map(character => character + character).join('');
  944. }
  945. const integer = Number.parseInt(colorString, 16);
  946. return [
  947. (integer >> 16) & 0xFF,
  948. (integer >> 8) & 0xFF,
  949. integer & 0xFF
  950. ];
  951. },
  952. enumerable: false
  953. },
  954. hexToAnsi256: {
  955. value: hex => styles.rgbToAnsi256(...styles.hexToRgb(hex)),
  956. enumerable: false
  957. },
  958. ansi256ToAnsi: {
  959. value: code => {
  960. if (code < 8) {
  961. return 30 + code;
  962. }
  963. if (code < 16) {
  964. return 90 + (code - 8);
  965. }
  966. let red;
  967. let green;
  968. let blue;
  969. if (code >= 232) {
  970. red = (((code - 232) * 10) + 8) / 255;
  971. green = red;
  972. blue = red;
  973. } else {
  974. code -= 16;
  975. const remainder = code % 36;
  976. red = Math.floor(code / 36) / 5;
  977. green = Math.floor(remainder / 6) / 5;
  978. blue = (remainder % 6) / 5;
  979. }
  980. const value = Math.max(red, green, blue) * 2;
  981. if (value === 0) {
  982. return 30;
  983. }
  984. let result = 30 + ((Math.round(blue) << 2) | (Math.round(green) << 1) | Math.round(red));
  985. if (value === 2) {
  986. result += 60;
  987. }
  988. return result;
  989. },
  990. enumerable: false
  991. },
  992. rgbToAnsi: {
  993. value: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),
  994. enumerable: false
  995. },
  996. hexToAnsi: {
  997. value: hex => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),
  998. enumerable: false
  999. }
  1000. });
  1001. return styles;
  1002. }
  1003. const ansiStyles = assembleStyles();
  1004. const ESCAPES = new Set([
  1005. '\u001B',
  1006. '\u009B',
  1007. ]);
  1008. const END_CODE = 39;
  1009. const ANSI_ESCAPE_BELL = '\u0007';
  1010. const ANSI_CSI = '[';
  1011. const ANSI_OSC = ']';
  1012. const ANSI_SGR_TERMINATOR = 'm';
  1013. const ANSI_ESCAPE_LINK = `${ANSI_OSC}8;;`;
  1014. const wrapAnsiCode = code => `${ESCAPES.values().next().value}${ANSI_CSI}${code}${ANSI_SGR_TERMINATOR}`;
  1015. const wrapAnsiHyperlink = uri => `${ESCAPES.values().next().value}${ANSI_ESCAPE_LINK}${uri}${ANSI_ESCAPE_BELL}`;
  1016. // Calculate the length of words split on ' ', ignoring
  1017. // the extra characters added by ansi escape codes
  1018. const wordLengths = string => string.split(' ').map(character => stringWidth(character));
  1019. // Wrap a long word across multiple rows
  1020. // Ansi escape codes do not count towards length
  1021. const wrapWord = (rows, word, columns) => {
  1022. const characters = [...word];
  1023. let isInsideEscape = false;
  1024. let isInsideLinkEscape = false;
  1025. let visible = stringWidth(stripAnsi(rows[rows.length - 1]));
  1026. for (const [index, character] of characters.entries()) {
  1027. const characterLength = stringWidth(character);
  1028. if (visible + characterLength <= columns) {
  1029. rows[rows.length - 1] += character;
  1030. } else {
  1031. rows.push(character);
  1032. visible = 0;
  1033. }
  1034. if (ESCAPES.has(character)) {
  1035. isInsideEscape = true;
  1036. isInsideLinkEscape = characters.slice(index + 1).join('').startsWith(ANSI_ESCAPE_LINK);
  1037. }
  1038. if (isInsideEscape) {
  1039. if (isInsideLinkEscape) {
  1040. if (character === ANSI_ESCAPE_BELL) {
  1041. isInsideEscape = false;
  1042. isInsideLinkEscape = false;
  1043. }
  1044. } else if (character === ANSI_SGR_TERMINATOR) {
  1045. isInsideEscape = false;
  1046. }
  1047. continue;
  1048. }
  1049. visible += characterLength;
  1050. if (visible === columns && index < characters.length - 1) {
  1051. rows.push('');
  1052. visible = 0;
  1053. }
  1054. }
  1055. // It's possible that the last row we copy over is only
  1056. // ansi escape characters, handle this edge-case
  1057. if (!visible && rows[rows.length - 1].length > 0 && rows.length > 1) {
  1058. rows[rows.length - 2] += rows.pop();
  1059. }
  1060. };
  1061. // Trims spaces from a string ignoring invisible sequences
  1062. const stringVisibleTrimSpacesRight = string => {
  1063. const words = string.split(' ');
  1064. let last = words.length;
  1065. while (last > 0) {
  1066. if (stringWidth(words[last - 1]) > 0) {
  1067. break;
  1068. }
  1069. last--;
  1070. }
  1071. if (last === words.length) {
  1072. return string;
  1073. }
  1074. return words.slice(0, last).join(' ') + words.slice(last).join('');
  1075. };
  1076. // The wrap-ansi module can be invoked in either 'hard' or 'soft' wrap mode
  1077. //
  1078. // 'hard' will never allow a string to take up more than columns characters
  1079. //
  1080. // 'soft' allows long words to expand past the column length
  1081. const exec = (string, columns, options = {}) => {
  1082. if (options.trim !== false && string.trim() === '') {
  1083. return '';
  1084. }
  1085. let returnValue = '';
  1086. let escapeCode;
  1087. let escapeUrl;
  1088. const lengths = wordLengths(string);
  1089. let rows = [''];
  1090. for (const [index, word] of string.split(' ').entries()) {
  1091. if (options.trim !== false) {
  1092. rows[rows.length - 1] = rows[rows.length - 1].trimStart();
  1093. }
  1094. let rowLength = stringWidth(rows[rows.length - 1]);
  1095. if (index !== 0) {
  1096. if (rowLength >= columns && (options.wordWrap === false || options.trim === false)) {
  1097. // If we start with a new word but the current row length equals the length of the columns, add a new row
  1098. rows.push('');
  1099. rowLength = 0;
  1100. }
  1101. if (rowLength > 0 || options.trim === false) {
  1102. rows[rows.length - 1] += ' ';
  1103. rowLength++;
  1104. }
  1105. }
  1106. // In 'hard' wrap mode, the length of a line is never allowed to extend past 'columns'
  1107. if (options.hard && lengths[index] > columns) {
  1108. const remainingColumns = (columns - rowLength);
  1109. const breaksStartingThisLine = 1 + Math.floor((lengths[index] - remainingColumns - 1) / columns);
  1110. const breaksStartingNextLine = Math.floor((lengths[index] - 1) / columns);
  1111. if (breaksStartingNextLine < breaksStartingThisLine) {
  1112. rows.push('');
  1113. }
  1114. wrapWord(rows, word, columns);
  1115. continue;
  1116. }
  1117. if (rowLength + lengths[index] > columns && rowLength > 0 && lengths[index] > 0) {
  1118. if (options.wordWrap === false && rowLength < columns) {
  1119. wrapWord(rows, word, columns);
  1120. continue;
  1121. }
  1122. rows.push('');
  1123. }
  1124. if (rowLength + lengths[index] > columns && options.wordWrap === false) {
  1125. wrapWord(rows, word, columns);
  1126. continue;
  1127. }
  1128. rows[rows.length - 1] += word;
  1129. }
  1130. if (options.trim !== false) {
  1131. rows = rows.map(row => stringVisibleTrimSpacesRight(row));
  1132. }
  1133. const pre = [...rows.join('\n')];
  1134. for (const [index, character] of pre.entries()) {
  1135. returnValue += character;
  1136. if (ESCAPES.has(character)) {
  1137. const {groups} = new RegExp(`(?:\\${ANSI_CSI}(?<code>\\d+)m|\\${ANSI_ESCAPE_LINK}(?<uri>.*)${ANSI_ESCAPE_BELL})`).exec(pre.slice(index).join('')) || {groups: {}};
  1138. if (groups.code !== undefined) {
  1139. const code = Number.parseFloat(groups.code);
  1140. escapeCode = code === END_CODE ? undefined : code;
  1141. } else if (groups.uri !== undefined) {
  1142. escapeUrl = groups.uri.length === 0 ? undefined : groups.uri;
  1143. }
  1144. }
  1145. const code = ansiStyles.codes.get(Number(escapeCode));
  1146. if (pre[index + 1] === '\n') {
  1147. if (escapeUrl) {
  1148. returnValue += wrapAnsiHyperlink('');
  1149. }
  1150. if (escapeCode && code) {
  1151. returnValue += wrapAnsiCode(code);
  1152. }
  1153. } else if (character === '\n') {
  1154. if (escapeCode && code) {
  1155. returnValue += wrapAnsiCode(escapeCode);
  1156. }
  1157. if (escapeUrl) {
  1158. returnValue += wrapAnsiHyperlink(escapeUrl);
  1159. }
  1160. }
  1161. }
  1162. return returnValue;
  1163. };
  1164. // For each newline, invoke the method separately
  1165. function wrapAnsi(string, columns, options) {
  1166. return String(string)
  1167. .normalize()
  1168. .replace(/\r\n/g, '\n')
  1169. .split('\n')
  1170. .map(line => exec(line, columns, options))
  1171. .join('\n');
  1172. }
  1173. const originalWrite = Symbol("webpackbarWrite");
  1174. class LogUpdate {
  1175. constructor() {
  1176. this.prevLineCount = 0;
  1177. this.listening = false;
  1178. this.extraLines = "";
  1179. this._onData = this._onData.bind(this);
  1180. this._streams = [process.stdout, process.stderr];
  1181. }
  1182. render(lines) {
  1183. this.listen();
  1184. const wrappedLines = wrapAnsi(lines, this.columns, {
  1185. trim: false,
  1186. hard: true,
  1187. wordWrap: false
  1188. });
  1189. const data = ansiEscapes.eraseLines(this.prevLineCount) + wrappedLines + "\n" + this.extraLines;
  1190. this.write(data);
  1191. const _lines = data.split("\n");
  1192. this.prevLineCount = _lines.length;
  1193. }
  1194. get columns() {
  1195. return (process.stderr.columns || 80) - 2;
  1196. }
  1197. write(data) {
  1198. const stream = process.stderr;
  1199. if (stream.write[originalWrite]) {
  1200. stream.write[originalWrite].call(stream, data, "utf-8");
  1201. } else {
  1202. stream.write(data, "utf-8");
  1203. }
  1204. }
  1205. clear() {
  1206. this.done();
  1207. this.write(ansiEscapes.eraseLines(this.prevLineCount));
  1208. }
  1209. done() {
  1210. this.stopListen();
  1211. this.prevLineCount = 0;
  1212. this.extraLines = "";
  1213. }
  1214. _onData(data) {
  1215. const str = String(data);
  1216. const lines = str.split("\n").length - 1;
  1217. if (lines > 0) {
  1218. this.prevLineCount += lines;
  1219. this.extraLines += data;
  1220. }
  1221. }
  1222. listen() {
  1223. if (this.listening) {
  1224. return;
  1225. }
  1226. for (const stream of this._streams) {
  1227. if (stream.write[originalWrite]) {
  1228. continue;
  1229. }
  1230. const write = (data, ...args) => {
  1231. if (!stream.write[originalWrite]) {
  1232. return stream.write(data, ...args);
  1233. }
  1234. this._onData(data);
  1235. return stream.write[originalWrite].call(stream, data, ...args);
  1236. };
  1237. write[originalWrite] = stream.write;
  1238. stream.write = write;
  1239. }
  1240. this.listening = true;
  1241. }
  1242. stopListen() {
  1243. for (const stream of this._streams) {
  1244. if (stream.write[originalWrite]) {
  1245. stream.write = stream.write[originalWrite];
  1246. }
  1247. }
  1248. this.listening = false;
  1249. }
  1250. }
  1251. const logUpdate = new LogUpdate();
  1252. let lastRender = Date.now();
  1253. class FancyReporter {
  1254. allDone() {
  1255. logUpdate.done();
  1256. }
  1257. done(context) {
  1258. this._renderStates(context.statesArray);
  1259. if (context.hasErrors) {
  1260. logUpdate.done();
  1261. }
  1262. }
  1263. progress(context) {
  1264. if (Date.now() - lastRender > 50) {
  1265. this._renderStates(context.statesArray);
  1266. }
  1267. }
  1268. _renderStates(statesArray) {
  1269. lastRender = Date.now();
  1270. const renderedStates = statesArray.map((c) => this._renderState(c)).join("\n\n");
  1271. logUpdate.render("\n" + renderedStates + "\n");
  1272. }
  1273. _renderState(state) {
  1274. const color = colorize(state.color);
  1275. let line1;
  1276. let line2;
  1277. if (state.progress >= 0 && state.progress < 100) {
  1278. line1 = [
  1279. color(BULLET),
  1280. color(state.name),
  1281. renderBar(state.progress, state.color),
  1282. state.message,
  1283. `(${state.progress || 0}%)`,
  1284. chalk__default.grey(state.details[0] || ""),
  1285. chalk__default.grey(state.details[1] || "")
  1286. ].join(" ");
  1287. line2 = state.request ? " " + chalk__default.grey(ellipsisLeft(formatRequest(state.request), logUpdate.columns)) : "";
  1288. } else {
  1289. let icon = " ";
  1290. if (state.hasErrors) {
  1291. icon = CROSS;
  1292. } else if (state.progress === 100) {
  1293. icon = TICK;
  1294. } else if (state.progress === -1) {
  1295. icon = CIRCLE_OPEN;
  1296. }
  1297. line1 = color(`${icon} ${state.name}`);
  1298. line2 = chalk__default.grey(" " + state.message);
  1299. }
  1300. return line1 + "\n" + line2;
  1301. }
  1302. }
  1303. class SimpleReporter {
  1304. start(context) {
  1305. consola.info(`Compiling ${context.state.name}`);
  1306. }
  1307. change(context, { shortPath }) {
  1308. consola.debug(`${shortPath} changed.`, `Rebuilding ${context.state.name}`);
  1309. }
  1310. done(context) {
  1311. const { hasError, message, name } = context.state;
  1312. consola[hasError ? "error" : "success"](`${name}: ${message}`);
  1313. }
  1314. }
  1315. const DB = {
  1316. loader: {
  1317. get: (loader) => startCase(loader)
  1318. },
  1319. ext: {
  1320. get: (ext) => `${ext} files`,
  1321. vue: "Vue Single File components",
  1322. js: "JavaScript files",
  1323. sass: "SASS files",
  1324. scss: "SASS files",
  1325. unknown: "Unknown files"
  1326. }
  1327. };
  1328. function getDescription(category, keyword) {
  1329. if (!DB[category]) {
  1330. return startCase(keyword);
  1331. }
  1332. if (DB[category][keyword]) {
  1333. return DB[category][keyword];
  1334. }
  1335. if (DB[category].get) {
  1336. return DB[category].get(keyword);
  1337. }
  1338. return "-";
  1339. }
  1340. function formatStats(allStats) {
  1341. const lines = [];
  1342. Object.keys(allStats).forEach((category) => {
  1343. const stats = allStats[category];
  1344. lines.push(`> Stats by ${chalk__default.bold(startCase(category))}`);
  1345. let totalRequests = 0;
  1346. const totalTime = [0, 0];
  1347. const data = [
  1348. [startCase(category), "Requests", "Time", "Time/Request", "Description"]
  1349. ];
  1350. Object.keys(stats).forEach((item) => {
  1351. const stat = stats[item];
  1352. totalRequests += stat.count || 0;
  1353. const description = getDescription(category, item);
  1354. totalTime[0] += stat.time[0];
  1355. totalTime[1] += stat.time[1];
  1356. const avgTime = [stat.time[0] / stat.count, stat.time[1] / stat.count];
  1357. data.push([
  1358. item,
  1359. stat.count || "-",
  1360. prettyTime__default(stat.time),
  1361. prettyTime__default(avgTime),
  1362. description
  1363. ]);
  1364. });
  1365. data.push(["Total", totalRequests, prettyTime__default(totalTime), "", ""]);
  1366. lines.push(createTable(data));
  1367. });
  1368. return `${lines.join("\n\n")}
  1369. `;
  1370. }
  1371. class Profiler {
  1372. constructor() {
  1373. this.requests = [];
  1374. }
  1375. onRequest(request) {
  1376. if (!request) {
  1377. return;
  1378. }
  1379. if (this.requests.length) {
  1380. const lastReq = this.requests[this.requests.length - 1];
  1381. if (lastReq.start) {
  1382. lastReq.time = process.hrtime(lastReq.start);
  1383. delete lastReq.start;
  1384. }
  1385. }
  1386. if (!request.file || !request.loaders.length) {
  1387. return;
  1388. }
  1389. this.requests.push({
  1390. request,
  1391. start: process.hrtime()
  1392. });
  1393. }
  1394. getStats() {
  1395. const loaderStats = {};
  1396. const extStats = {};
  1397. const getStat = (stats, name) => {
  1398. if (!stats[name]) {
  1399. stats[name] = {
  1400. count: 0,
  1401. time: [0, 0]
  1402. };
  1403. }
  1404. return stats[name];
  1405. };
  1406. const addToStat = (stats, name, count, time) => {
  1407. const stat = getStat(stats, name);
  1408. stat.count += count;
  1409. stat.time[0] += time[0];
  1410. stat.time[1] += time[1];
  1411. };
  1412. this.requests.forEach(({ request, time = [0, 0] }) => {
  1413. request.loaders.forEach((loader) => {
  1414. addToStat(loaderStats, loader, 1, time);
  1415. });
  1416. const ext = request.file && path__default.extname(request.file).substr(1);
  1417. addToStat(extStats, ext && ext.length ? ext : "unknown", 1, time);
  1418. });
  1419. return {
  1420. ext: extStats,
  1421. loader: loaderStats
  1422. };
  1423. }
  1424. getFormattedStats() {
  1425. return formatStats(this.getStats());
  1426. }
  1427. }
  1428. class ProfileReporter {
  1429. progress(context) {
  1430. if (!context.state.profiler) {
  1431. context.state.profiler = new Profiler();
  1432. }
  1433. context.state.profiler.onRequest(context.state.request);
  1434. }
  1435. done(context) {
  1436. if (context.state.profiler) {
  1437. context.state.profile = context.state.profiler.getFormattedStats();
  1438. delete context.state.profiler;
  1439. }
  1440. }
  1441. allDone(context) {
  1442. let str = "";
  1443. for (const state of context.statesArray) {
  1444. const color = colorize(state.color);
  1445. if (state.profile) {
  1446. str += color(`
  1447. Profile results for ${chalk__default.bold(state.name)}
  1448. `) + `
  1449. ${state.profile}
  1450. `;
  1451. delete state.profile;
  1452. }
  1453. }
  1454. process.stderr.write(str);
  1455. }
  1456. }
  1457. class StatsReporter {
  1458. constructor(options) {
  1459. this.options = Object.assign({
  1460. chunks: false,
  1461. children: false,
  1462. modules: false,
  1463. colors: true,
  1464. warnings: true,
  1465. errors: true
  1466. }, options);
  1467. }
  1468. done(context, { stats }) {
  1469. const str = stats.toString(this.options);
  1470. if (context.hasErrors) {
  1471. process.stderr.write("\n" + str + "\n");
  1472. } else {
  1473. context.state.statsString = str;
  1474. }
  1475. }
  1476. allDone(context) {
  1477. let str = "";
  1478. for (const state of context.statesArray) {
  1479. if (state.statsString) {
  1480. str += "\n" + state.statsString + "\n";
  1481. delete state.statsString;
  1482. }
  1483. }
  1484. process.stderr.write(str);
  1485. }
  1486. }
  1487. const reporters = {
  1488. __proto__: null,
  1489. fancy: FancyReporter,
  1490. basic: SimpleReporter,
  1491. profile: ProfileReporter,
  1492. stats: StatsReporter
  1493. };
  1494. const DEFAULTS = {
  1495. name: "webpack",
  1496. color: "green",
  1497. reporters: stdEnv.isMinimal ? ["basic"] : ["fancy"],
  1498. reporter: null
  1499. };
  1500. const DEFAULT_STATE = {
  1501. start: null,
  1502. progress: -1,
  1503. done: false,
  1504. message: "",
  1505. details: [],
  1506. request: null,
  1507. hasErrors: false
  1508. };
  1509. const globalStates = {};
  1510. class WebpackBarPlugin extends Webpack__default.ProgressPlugin {
  1511. constructor(options) {
  1512. super({ activeModules: true });
  1513. this.options = Object.assign({}, DEFAULTS, options);
  1514. this.handler = (percent, message, ...details) => {
  1515. this.updateProgress(percent, message, details);
  1516. };
  1517. const _reporters = Array.from(this.options.reporters || []).concat(this.options.reporter).filter(Boolean).map((reporter) => {
  1518. if (Array.isArray(reporter)) {
  1519. return { reporter: reporter[0], options: reporter[1] };
  1520. }
  1521. if (typeof reporter === "string") {
  1522. return { reporter };
  1523. }
  1524. return { reporter };
  1525. });
  1526. this.reporters = _reporters.map(({ reporter, options: options2 = {} }) => {
  1527. if (typeof reporter === "string") {
  1528. if (this.options[reporter] === false) {
  1529. return void 0;
  1530. }
  1531. options2 = { ...this.options[reporter], ...options2 };
  1532. reporter = reporters[reporter] || require(reporter);
  1533. }
  1534. if (typeof reporter === "function") {
  1535. try {
  1536. reporter = new reporter(options2);
  1537. } catch (err) {
  1538. reporter = reporter(options2);
  1539. }
  1540. }
  1541. return reporter;
  1542. }).filter(Boolean);
  1543. }
  1544. callReporters(fn, payload = {}) {
  1545. for (const reporter of this.reporters) {
  1546. if (typeof reporter[fn] === "function") {
  1547. try {
  1548. reporter[fn](this, payload);
  1549. } catch (e) {
  1550. process.stdout.write(e.stack + "\n");
  1551. }
  1552. }
  1553. }
  1554. }
  1555. get hasRunning() {
  1556. return objectValues(this.states).some((state) => !state.done);
  1557. }
  1558. get hasErrors() {
  1559. return objectValues(this.states).some((state) => state.hasErrors);
  1560. }
  1561. get statesArray() {
  1562. return objectValues(this.states).sort((s1, s2) => s1.name.localeCompare(s2.name));
  1563. }
  1564. get states() {
  1565. return globalStates;
  1566. }
  1567. get state() {
  1568. return globalStates[this.options.name];
  1569. }
  1570. _ensureState() {
  1571. if (!this.states[this.options.name]) {
  1572. this.states[this.options.name] = {
  1573. ...DEFAULT_STATE,
  1574. color: this.options.color,
  1575. name: startCase(this.options.name)
  1576. };
  1577. }
  1578. }
  1579. apply(compiler) {
  1580. if (compiler.webpackbar) {
  1581. return;
  1582. }
  1583. compiler.webpackbar = this;
  1584. super.apply(compiler);
  1585. hook(compiler, "afterPlugins", () => {
  1586. this._ensureState();
  1587. });
  1588. hook(compiler, "compile", () => {
  1589. this._ensureState();
  1590. Object.assign(this.state, {
  1591. ...DEFAULT_STATE,
  1592. start: process.hrtime()
  1593. });
  1594. this.callReporters("start");
  1595. });
  1596. hook(compiler, "invalid", (fileName, changeTime) => {
  1597. this._ensureState();
  1598. this.callReporters("change", {
  1599. path: fileName,
  1600. shortPath: shortenPath(fileName),
  1601. time: changeTime
  1602. });
  1603. });
  1604. hook(compiler, "done", (stats) => {
  1605. this._ensureState();
  1606. if (this.state.done) {
  1607. return;
  1608. }
  1609. const hasErrors = stats.hasErrors();
  1610. const status = hasErrors ? "with some errors" : "successfully";
  1611. const time = this.state.start ? " in " + prettyTime__default(process.hrtime(this.state.start), 2) : "";
  1612. Object.assign(this.state, {
  1613. ...DEFAULT_STATE,
  1614. progress: 100,
  1615. done: true,
  1616. message: `Compiled ${status}${time}`,
  1617. hasErrors
  1618. });
  1619. this.callReporters("progress");
  1620. this.callReporters("done", { stats });
  1621. if (!this.hasRunning) {
  1622. this.callReporters("beforeAllDone");
  1623. this.callReporters("allDone");
  1624. this.callReporters("afterAllDone");
  1625. }
  1626. });
  1627. }
  1628. updateProgress(percent = 0, message = "", details = []) {
  1629. const progress = Math.floor(percent * 100);
  1630. const activeModule = details.pop();
  1631. Object.assign(this.state, {
  1632. progress,
  1633. message: message || "",
  1634. details,
  1635. request: parseRequest(activeModule)
  1636. });
  1637. this.callReporters("progress");
  1638. }
  1639. }
  1640. module.exports = WebpackBarPlugin;