Skip to content

fix(@angular-devkit/build-angular): show progress during re-builds #21034

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/angular_devkit/build_angular/src/utils/spinner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@

import * as ora from 'ora';
import { colors } from './color';
import { isTTY } from './tty';

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

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

constructor(text?: string) {
this.spinner = ora({
Expand All @@ -22,13 +24,18 @@ export class Spinner {
// when the underlying process is sync.
hideCursor: false,
discardStdin: false,
isEnabled: this.#isTTY,
});
}

set text(text: string) {
this.spinner.text = text;
}

get isSpinning(): boolean {
return this.spinner.isSpinning || !this.#isTTY;
}

succeed(text?: string): void {
if (this.enabled) {
this.spinner.succeed(text);
Expand Down
29 changes: 12 additions & 17 deletions packages/angular_devkit/build_angular/src/webpack/configs/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,33 +72,28 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
const spinner = new Spinner();
spinner.start(`Generating ${platform} application bundles (phase: setup)...`);

let previousPercentage: number | undefined;
extraPlugins.push(
new ProgressPlugin({
handler: (percentage: number, message: string) => {
if (previousPercentage === 1 && percentage !== 0) {
// In some scenarios in Webpack 5 percentage goes from 1 back to 0.99.
// Ex: 0.99 -> 1 -> 0.99 -> 1
// This causes the "complete" message to be displayed multiple times.

return;
}
const phase = message ? ` (phase: ${message})` : '';
spinner.text = `Generating ${platform} application bundles${phase}...`;

switch (percentage) {
case 1:
spinner.succeed(
`${platform.replace(/^\w/, (s) =>
s.toUpperCase(),
)} application bundle generation complete.`,
);
if (spinner.isSpinning) {
spinner.succeed(
`${platform.replace(/^\w/, (s) =>
s.toUpperCase(),
)} application bundle generation complete.`,
);
}
break;
case 0:
default:
spinner.text = `Generating ${platform} application bundles (phase: ${message})...`;
if (!spinner.isSpinning) {
spinner.start();
}
break;
}

previousPercentage = percentage;
},
}),
);
Expand Down