Skip to content

Commit f11adbb

Browse files
pvdzgatsbybot
and
gatsbybot
authored
fix(gatsby-cli): fix timers on progress bar (#28684)
* fix(gatsby-cli): fix timers on progress bar * Add rate as well * Make sure max is >=1 and init is only set when given * yes, "thank you", TS Co-authored-by: gatsbybot <mathews.kyle+gatsbybot@gmail.com>
1 parent 6b8cd5d commit f11adbb

File tree

1 file changed

+15
-3
lines changed
  • packages/gatsby-cli/src/reporter/loggers/yurnalist

1 file changed

+15
-3
lines changed

packages/gatsby-cli/src/reporter/loggers/yurnalist/index.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,27 @@ export function initializeYurnalistLogger(): void {
9393
activities[action.payload.id] = activity
9494
} else if (action.payload.type === ActivityTypes.Progress) {
9595
const bar = new ProgressBar(
96-
` [:bar] :current/:total :elapsed s :percent ${action.payload.text}`,
96+
` [:bar] :current/:total :elapsed s :rate /s :percent ${action.payload.text}`,
9797
{
98-
total: action.payload.total,
99-
curr: action.payload.current,
98+
total: Math.max(action.payload.total || 1, 1) || 1, // Not zero. Otherwise you get 0/0 errors.
99+
// curr: action.payload.current, // see below
100100
width: 30,
101101
clear: true,
102102
}
103103
)
104104

105+
// There is a bug in the `progress` package where the timer doesn't
106+
// start until the first tick and setting `curr` will cause the
107+
// time/eta to remain zero: https://github.com/visionmedia/node-progress/issues/81
108+
// This is a workaround although the eta will initially be wrong
109+
// until it settles, if starting at non-zero.
110+
if (
111+
typeof action.payload.current === `number` &&
112+
action.payload.current >= 0
113+
) {
114+
bar.tick(action.payload.current)
115+
}
116+
105117
activities[action.payload.id] = {
106118
text: undefined,
107119
statusText: undefined,

0 commit comments

Comments
 (0)