fix(core): graph spinners should update properly (#29433)

## Current Behavior
Spinners are not updated properly

## Expected Behavior
Spinners are updated properly

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #
This commit is contained in:
Craigory Coppola 2024-12-19 17:09:28 -05:00 committed by GitHub
parent 16c8ba164c
commit 09800062e7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 25 additions and 15 deletions

View File

@ -319,13 +319,14 @@ async function updateProjectGraphWithPlugins(
const inProgressPlugins = new Set<string>(); const inProgressPlugins = new Set<string>();
function updateSpinner() { function updateSpinner() {
if (!spinner) { if (!spinner || inProgressPlugins.size === 0) {
return; return;
} }
if (inProgressPlugins.size === 1) { if (inProgressPlugins.size === 1) {
spinner.setMessage( spinner.setMessage(
`Creating project graph dependencies with ${ `Creating project graph dependencies with ${
inProgressPlugins.keys()[0] inProgressPlugins.values().next().value
}` }`
); );
} else if (process.env.NX_VERBOSE_LOGGING === 'true') { } else if (process.env.NX_VERBOSE_LOGGING === 'true') {
@ -439,12 +440,15 @@ export async function applyProjectMetadata(
const inProgressPlugins = new Set<string>(); const inProgressPlugins = new Set<string>();
function updateSpinner() { function updateSpinner() {
if (!spinner) { if (!spinner || inProgressPlugins.size === 0) {
return; return;
} }
if (inProgressPlugins.size === 1) { if (inProgressPlugins.size === 1) {
spinner.setMessage( spinner.setMessage(
`Creating project metadata with ${inProgressPlugins.keys()[0]}` `Creating project metadata with ${
inProgressPlugins.values().next().value
}`
); );
} else if (process.env.NX_VERBOSE_LOGGING === 'true') { } else if (process.env.NX_VERBOSE_LOGGING === 'true') {
spinner.setMessage( spinner.setMessage(

View File

@ -330,13 +330,15 @@ export async function createProjectConfigurations(
const inProgressPlugins = new Set<string>(); const inProgressPlugins = new Set<string>();
function updateSpinner() { function updateSpinner() {
if (!spinner) { if (!spinner || inProgressPlugins.size === 0) {
return; return;
} }
if (inProgressPlugins.size === 1) { if (inProgressPlugins.size === 1) {
spinner.setMessage( spinner.setMessage(
`Creating project graph nodes with ${inProgressPlugins.keys()[0]}` `Creating project graph nodes with ${
inProgressPlugins.values().next().value
}`
); );
} else if (process.env.NX_VERBOSE_LOGGING === 'true') { } else if (process.env.NX_VERBOSE_LOGGING === 'true') {
spinner.setMessage( spinner.setMessage(

View File

@ -15,8 +15,9 @@ export type DelayedSpinnerOptions = {
export class DelayedSpinner { export class DelayedSpinner {
spinner: ora.Ora; spinner: ora.Ora;
timeouts: NodeJS.Timeout[] = []; timeouts: NodeJS.Timeout[] = [];
initial: number = Date.now();
lastMessage: string; private lastMessage: string;
private ready: boolean;
/** /**
* Constructs a new {@link DelayedSpinner} instance. * Constructs a new {@link DelayedSpinner} instance.
@ -29,10 +30,11 @@ export class DelayedSpinner {
this.timeouts.push( this.timeouts.push(
setTimeout(() => { setTimeout(() => {
this.ready = true;
if (!SHOULD_SHOW_SPINNERS) { if (!SHOULD_SHOW_SPINNERS) {
console.warn(message); console.warn(this.lastMessage);
} else { } else {
this.spinner = ora(message); this.spinner = ora(this.lastMessage).start();
} }
this.lastMessage = message; this.lastMessage = message;
}, delay).unref() }, delay).unref()
@ -46,12 +48,14 @@ export class DelayedSpinner {
* @returns The {@link DelayedSpinner} instance * @returns The {@link DelayedSpinner} instance
*/ */
setMessage(message: string) { setMessage(message: string) {
if (this.spinner && SHOULD_SHOW_SPINNERS) { if (SHOULD_SHOW_SPINNERS) {
this.spinner.text = message; if (this.spinner) {
} else if (this.lastMessage && this.lastMessage !== message) { this.spinner.text = message;
}
} else if (this.ready && this.lastMessage && this.lastMessage !== message) {
console.warn(message); console.warn(message);
this.lastMessage = message;
} }
this.lastMessage = message;
return this; return this;
} }
@ -91,6 +95,6 @@ function normalizeDelayedSpinnerOpts(
) { ) {
opts ??= {}; opts ??= {};
opts.delay ??= 500; opts.delay ??= 500;
opts.ciDelay ??= 10_000; opts.ciDelay ??= 30_000;
return opts; return opts;
} }