MCPcopy
hub / github.com/webpack/webpack / reportProfile

Function reportProfile

lib/ProgressPlugin.js:71–126  ·  view source on GitHub ↗
(logger, lastStateInfo, percentage, msg, args)

Source from the content-addressed store, hash-verified

69 * @param {string[]} args args
70 */
71const reportProfile = (logger, lastStateInfo, percentage, msg, args) => {
72 if (percentage === 0) {
73 lastStateInfo.length = 0;
74 }
75 const fullState = [msg, ...args];
76 const state = fullState.map((s) => s.replace(/\d+\/\d+ /g, ""));
77 const now = Date.now();
78 const len = Math.max(state.length, lastStateInfo.length);
79 for (let i = len; i >= 0; i--) {
80 const stateItem = i < state.length ? state[i] : undefined;
81 const lastStateItem =
82 i < lastStateInfo.length ? lastStateInfo[i] : undefined;
83 if (lastStateItem) {
84 if (stateItem !== lastStateItem.value) {
85 const diff = now - lastStateItem.time;
86 if (lastStateItem.value) {
87 let reportState = lastStateItem.value;
88 if (i > 0) {
89 reportState = `${lastStateInfo[i - 1].value} > ${reportState}`;
90 }
91 const stateMsg = `${" | ".repeat(i)}${diff} ms ${reportState}`;
92 const d = diff;
93 // This depends on timing so we ignore it for coverage
94 /* eslint-disable no-lone-blocks */
95 /* istanbul ignore next */
96 {
97 if (d > 10000) {
98 logger.error(stateMsg);
99 } else if (d > 1000) {
100 logger.warn(stateMsg);
101 } else if (d > 10) {
102 logger.info(stateMsg);
103 } else if (d > 5) {
104 logger.log(stateMsg);
105 } else {
106 logger.debug(stateMsg);
107 }
108 }
109 /* eslint-enable no-lone-blocks */
110 }
111 if (stateItem === undefined) {
112 lastStateInfo.length = i;
113 } else {
114 lastStateItem.value = stateItem;
115 lastStateItem.time = now;
116 lastStateInfo.length = i + 1;
117 }
118 }
119 } else {
120 lastStateInfo[i] = {
121 value: stateItem,
122 time: now
123 };
124 }
125 }
126};
127
128/**

Callers 1

defaultHandlerFunction · 0.85

Calls 6

warnMethod · 0.80
infoMethod · 0.80
logMethod · 0.80
debugMethod · 0.80
replaceMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected