Skip to content

Commit 2b16656

Browse files
committed
fix(@angular-devkit/build-angular): show progress during re-builds
With the recent changes in #20960 we moved the spinner to be started outside of the progress callback, this causes a side-effect that after `succeed` is called the spinner will stop reporting progress unless it is started again. (cherry picked from commit bd82967)
1 parent 8575056 commit 2b16656

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

packages/angular_devkit/build_angular/src/utils/spinner.ts

+7
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88

99
import * as ora from 'ora';
1010
import { colors } from './color';
11+
import { isTTY } from './tty';
1112

1213
export class Spinner {
1314
private readonly spinner: ora.Ora;
1415

1516
/** When false, only fail messages will be displayed. */
1617
enabled = true;
18+
readonly #isTTY = isTTY();
1719

1820
constructor(text?: string) {
1921
this.spinner = ora({
@@ -22,13 +24,18 @@ export class Spinner {
2224
// when the underlying process is sync.
2325
hideCursor: false,
2426
discardStdin: false,
27+
isEnabled: this.#isTTY,
2528
});
2629
}
2730

2831
set text(text: string) {
2932
this.spinner.text = text;
3033
}
3134

35+
get isSpinning(): boolean {
36+
return this.spinner.isSpinning || !this.#isTTY;
37+
}
38+
3239
succeed(text?: string): void {
3340
if (this.enabled) {
3441
this.spinner.succeed(text);

packages/angular_devkit/build_angular/src/webpack/configs/common.ts

+12-17
Original file line numberDiff line numberDiff line change
@@ -72,33 +72,28 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
7272
const spinner = new Spinner();
7373
spinner.start(`Generating ${platform} application bundles (phase: setup)...`);
7474

75-
let previousPercentage: number | undefined;
7675
extraPlugins.push(
7776
new ProgressPlugin({
7877
handler: (percentage: number, message: string) => {
79-
if (previousPercentage === 1 && percentage !== 0) {
80-
// In some scenarios in Webpack 5 percentage goes from 1 back to 0.99.
81-
// Ex: 0.99 -> 1 -> 0.99 -> 1
82-
// This causes the "complete" message to be displayed multiple times.
83-
84-
return;
85-
}
78+
const phase = message ? ` (phase: ${message})` : '';
79+
spinner.text = `Generating ${platform} application bundles${phase}...`;
8680

8781
switch (percentage) {
8882
case 1:
89-
spinner.succeed(
90-
`${platform.replace(/^\w/, (s) =>
91-
s.toUpperCase(),
92-
)} application bundle generation complete.`,
93-
);
83+
if (spinner.isSpinning) {
84+
spinner.succeed(
85+
`${platform.replace(/^\w/, (s) =>
86+
s.toUpperCase(),
87+
)} application bundle generation complete.`,
88+
);
89+
}
9490
break;
9591
case 0:
96-
default:
97-
spinner.text = `Generating ${platform} application bundles (phase: ${message})...`;
92+
if (!spinner.isSpinning) {
93+
spinner.start();
94+
}
9895
break;
9996
}
100-
101-
previousPercentage = percentage;
10297
},
10398
}),
10499
);

0 commit comments

Comments
 (0)