mirror of https://github.com/webpack/webpack.git
refactor to single write per update
throttle unimportant updates
This commit is contained in:
parent
f29991bda4
commit
cae07597f6
|
|
@ -68,8 +68,8 @@ const createDefaultHandler = profile => {
|
||||||
const diff = now - lastStateTime;
|
const diff = now - lastStateTime;
|
||||||
if (diff >= 1) {
|
if (diff >= 1) {
|
||||||
const stateMsg = `${diff}ms ${lastState}`;
|
const stateMsg = `${diff}ms ${lastState}`;
|
||||||
goToLineStart(stateMsg);
|
goToLineStartAndWrite(stateMsg);
|
||||||
process.stderr.write(stateMsg + "\n");
|
process.stderr.write("\n");
|
||||||
lineCaretPosition = 0;
|
lineCaretPosition = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -78,14 +78,13 @@ const createDefaultHandler = profile => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (lastMessage !== msg) {
|
if (lastMessage !== msg) {
|
||||||
goToLineStart(msg);
|
|
||||||
msg = msg.substring(0, maxLineLength);
|
msg = msg.substring(0, maxLineLength);
|
||||||
process.stderr.write(msg);
|
goToLineStartAndWrite(msg);
|
||||||
lastMessage = msg;
|
lastMessage = msg;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const goToLineStart = nextMessage => {
|
const goToLineStartAndWrite = nextMessage => {
|
||||||
let str = "";
|
let str = "";
|
||||||
for (; lineCaretPosition > nextMessage.length; lineCaretPosition--) {
|
for (; lineCaretPosition > nextMessage.length; lineCaretPosition--) {
|
||||||
str += "\b \b";
|
str += "\b \b";
|
||||||
|
|
@ -94,7 +93,7 @@ const createDefaultHandler = profile => {
|
||||||
str += "\b";
|
str += "\b";
|
||||||
}
|
}
|
||||||
lineCaretPosition = nextMessage.length;
|
lineCaretPosition = nextMessage.length;
|
||||||
if (str) process.stderr.write(str);
|
if (str) process.stderr.write(str + nextMessage);
|
||||||
};
|
};
|
||||||
|
|
||||||
return defaultHandler;
|
return defaultHandler;
|
||||||
|
|
@ -193,6 +192,11 @@ class ProgressPlugin {
|
||||||
let doneModules = 0;
|
let doneModules = 0;
|
||||||
let doneEntries = 0;
|
let doneEntries = 0;
|
||||||
const activeModules = new Set();
|
const activeModules = new Set();
|
||||||
|
let lastUpdate = 0;
|
||||||
|
|
||||||
|
const updateThrottled = () => {
|
||||||
|
if (lastUpdate + 500 < Date.now()) update();
|
||||||
|
};
|
||||||
|
|
||||||
const update = () => {
|
const update = () => {
|
||||||
/** @type {string[]} */
|
/** @type {string[]} */
|
||||||
|
|
@ -214,11 +218,12 @@ class ProgressPlugin {
|
||||||
items.push(lastActiveModule);
|
items.push(lastActiveModule);
|
||||||
}
|
}
|
||||||
handler(percentage, "building", ...items);
|
handler(percentage, "building", ...items);
|
||||||
|
lastUpdate = Date.now();
|
||||||
};
|
};
|
||||||
|
|
||||||
const moduleAdd = module => {
|
const moduleAdd = module => {
|
||||||
moduleCount++;
|
moduleCount++;
|
||||||
if (moduleCount % 100 === 0) update();
|
if (moduleCount % 100 === 0) updateThrottled();
|
||||||
};
|
};
|
||||||
|
|
||||||
const moduleBuild = module => {
|
const moduleBuild = module => {
|
||||||
|
|
@ -234,7 +239,7 @@ class ProgressPlugin {
|
||||||
|
|
||||||
const entryAdd = (entry, name) => {
|
const entryAdd = (entry, name) => {
|
||||||
entriesCount++;
|
entriesCount++;
|
||||||
if (entriesCount % 10 === 0) update();
|
if (entriesCount % 10 === 0) updateThrottled();
|
||||||
};
|
};
|
||||||
|
|
||||||
const moduleDone = module => {
|
const moduleDone = module => {
|
||||||
|
|
@ -248,11 +253,12 @@ class ProgressPlugin {
|
||||||
for (const m of activeModules) {
|
for (const m of activeModules) {
|
||||||
lastActiveModule = m;
|
lastActiveModule = m;
|
||||||
}
|
}
|
||||||
if (doneModules % 100 !== 0) update();
|
update();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (doneModules % 100 === 0) update();
|
if (doneModules % 100 === 0) updateThrottled();
|
||||||
};
|
};
|
||||||
|
|
||||||
const entryDone = (entry, name) => {
|
const entryDone = (entry, name) => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue