Skip to content

Commit

Permalink
fix(core): graph spinners should update properly (#29433)
Browse files Browse the repository at this point in the history
## 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 #
  • Loading branch information
AgentEnder authored Dec 19, 2024
1 parent 16c8ba1 commit 0980006
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
12 changes: 8 additions & 4 deletions packages/nx/src/project-graph/build-project-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,13 +319,14 @@ async function updateProjectGraphWithPlugins(
const inProgressPlugins = new Set<string>();

function updateSpinner() {
if (!spinner) {
if (!spinner || inProgressPlugins.size === 0) {
return;
}

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

function updateSpinner() {
if (!spinner) {
if (!spinner || inProgressPlugins.size === 0) {
return;
}

if (inProgressPlugins.size === 1) {
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') {
spinner.setMessage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,13 +330,15 @@ export async function createProjectConfigurations(
const inProgressPlugins = new Set<string>();

function updateSpinner() {
if (!spinner) {
if (!spinner || inProgressPlugins.size === 0) {
return;
}

if (inProgressPlugins.size === 1) {
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') {
spinner.setMessage(
Expand Down
22 changes: 13 additions & 9 deletions packages/nx/src/utils/delayed-spinner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ export type DelayedSpinnerOptions = {
export class DelayedSpinner {
spinner: ora.Ora;
timeouts: NodeJS.Timeout[] = [];
initial: number = Date.now();
lastMessage: string;

private lastMessage: string;
private ready: boolean;

/**
* Constructs a new {@link DelayedSpinner} instance.
Expand All @@ -29,10 +30,11 @@ export class DelayedSpinner {

this.timeouts.push(
setTimeout(() => {
this.ready = true;
if (!SHOULD_SHOW_SPINNERS) {
console.warn(message);
console.warn(this.lastMessage);
} else {
this.spinner = ora(message);
this.spinner = ora(this.lastMessage).start();
}
this.lastMessage = message;
}, delay).unref()
Expand All @@ -46,12 +48,14 @@ export class DelayedSpinner {
* @returns The {@link DelayedSpinner} instance
*/
setMessage(message: string) {
if (this.spinner && SHOULD_SHOW_SPINNERS) {
this.spinner.text = message;
} else if (this.lastMessage && this.lastMessage !== message) {
if (SHOULD_SHOW_SPINNERS) {
if (this.spinner) {
this.spinner.text = message;
}
} else if (this.ready && this.lastMessage && this.lastMessage !== message) {
console.warn(message);
this.lastMessage = message;
}
this.lastMessage = message;
return this;
}

Expand Down Expand Up @@ -91,6 +95,6 @@ function normalizeDelayedSpinnerOpts(
) {
opts ??= {};
opts.delay ??= 500;
opts.ciDelay ??= 10_000;
opts.ciDelay ??= 30_000;
return opts;
}

0 comments on commit 0980006

Please sign in to comment.