@@ -6,7 +6,8 @@ import { eraseLines } from "./cli";
6
6
7
7
const originalWrite = Symbol ( "webpackbarWrite" ) ;
8
8
9
- export default class LogUpdate {
9
+ class LogUpdate {
10
+ public keepOnBottom = false ;
10
11
private prevLines : string | null ;
11
12
private listening : boolean ;
12
13
private extraLines : string ;
@@ -29,11 +30,10 @@ export default class LogUpdate {
29
30
wordWrap : false ,
30
31
} ) ;
31
32
32
- const data =
33
- eraseLines ( this . lineCount ) + wrappedLines + "\n" + this . extraLines ;
33
+ const linesToWrite = wrappedLines + "\n" + this . extraLines ;
34
+ this . write ( eraseLines ( this . lineCount ) + linesToWrite ) ;
34
35
35
- this . write ( data ) ;
36
- this . prevLines = data ;
36
+ this . prevLines = linesToWrite ;
37
37
}
38
38
39
39
/**
@@ -82,14 +82,22 @@ export default class LogUpdate {
82
82
}
83
83
84
84
_onData ( data ) {
85
- const str = String ( data ) ;
86
- const lines = str . split ( "\n" ) . length - 1 ;
87
- if ( lines > 0 ) {
85
+ if ( this . keepOnBottom ) {
86
+ // Erase the progress bar so that the data can be printed above it
87
+ this . write ( eraseLines ( this . lineCount ) ) ;
88
+ } else {
88
89
this . prevLines += data ;
89
90
this . extraLines += data ;
90
91
}
91
92
}
92
93
94
+ _afterData ( ) {
95
+ if ( this . keepOnBottom ) {
96
+ // Re-draw the bar in the new position after the printed data
97
+ this . write ( this . prevLines ) ;
98
+ }
99
+ }
100
+
93
101
listen ( ) {
94
102
// Prevent listening more than once
95
103
if ( this . listening ) {
@@ -109,7 +117,9 @@ export default class LogUpdate {
109
117
return stream . write ( data , ...args ) ;
110
118
}
111
119
this . _onData ( data ) ;
112
- return stream . write [ originalWrite ] . call ( stream , data , ...args ) ;
120
+ const result = stream . write [ originalWrite ] . call ( stream , data , ...args ) ;
121
+ this . _afterData ( ) ;
122
+ return result ;
113
123
} ;
114
124
115
125
// Backup original write fn
@@ -133,3 +143,5 @@ export default class LogUpdate {
133
143
this . listening = false ;
134
144
}
135
145
}
146
+
147
+ export const logUpdate = new LogUpdate ( ) ;
0 commit comments