Skip to content

Commit 2417991

Browse files
committed
Fix progress indicator erasing too many characters. Fixes webpack#3591
The code was erasing (actually: moving the caret back for) too many characters because the number of characters to move back was being overwritten too early. The bug manifests itself only in Windows Command Prompt via npm script and only when webpack is run in conjunction with other npm scripts. Linux terminal is also affected, but apparently is more graceful (doesn't allow the backspace character to jump to the previous terminal line).
1 parent 8bc25f6 commit 2417991

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

‎lib/ProgressPlugin.js‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ ProgressPlugin.prototype.apply = function(compiler) {
131131
});
132132
}
133133

134-
var chars = 0,
134+
var lineCaretPosition = 0,
135135
lastState, lastStateTime;
136136

137137
function defaultHandler(percentage, msg) {
@@ -165,7 +165,7 @@ ProgressPlugin.prototype.apply = function(compiler) {
165165
var stateMsg = (now - lastStateTime) + "ms " + lastState;
166166
goToLineStart(stateMsg);
167167
process.stderr.write(stateMsg + "\n");
168-
chars = 0;
168+
lineCaretPosition = 0;
169169
}
170170
lastState = state;
171171
lastStateTime = now;
@@ -177,13 +177,13 @@ ProgressPlugin.prototype.apply = function(compiler) {
177177

178178
function goToLineStart(nextMessage) {
179179
var str = "";
180-
for(; chars > nextMessage.length; chars--) {
180+
for(; lineCaretPosition > nextMessage.length; lineCaretPosition--) {
181181
str += "\b \b";
182182
}
183-
chars = nextMessage.length;
184-
for(var i = 0; i < chars; i++) {
183+
for(var i = 0; i < lineCaretPosition; i++) {
185184
str += "\b";
186185
}
186+
lineCaretPosition = nextMessage.length;
187187
if(str) process.stderr.write(str);
188188
}
189189
};

0 commit comments

Comments
 (0)