From 0df7ef5899143b10385d4d094631f1e59b7d5dfc Mon Sep 17 00:00:00 2001 From: Craigory Coppola Date: Wed, 18 Dec 2024 12:01:32 -0500 Subject: [PATCH] chore(core): review feedback --- packages/nx/src/daemon/client/client.ts | 12 ++++-------- .../src/project-graph/build-project-graph.ts | 18 +++++++----------- .../utils/project-configuration-utils.ts | 6 +----- packages/nx/src/utils/delayed-spinner.ts | 8 ++++---- 4 files changed, 16 insertions(+), 28 deletions(-) diff --git a/packages/nx/src/daemon/client/client.ts b/packages/nx/src/daemon/client/client.ts index 5244cce47458f..3c3fe28e5cd75 100644 --- a/packages/nx/src/daemon/client/client.ts +++ b/packages/nx/src/daemon/client/client.ts @@ -77,10 +77,7 @@ import { FLUSH_SYNC_GENERATOR_CHANGES_TO_DISK, type HandleFlushSyncGeneratorChangesToDiskMessage, } from '../message-types/flush-sync-generator-changes-to-disk'; -import { - DelayedSpinner, - SHOULD_SHOW_SPINNERS, -} from '../../utils/delayed-spinner'; +import { DelayedSpinner } from '../../utils/delayed-spinner'; const DAEMON_ENV_SETTINGS = { NX_PROJECT_GLOB_CACHE: 'false', @@ -200,10 +197,9 @@ export class DaemonClient { }> { let spinner: DelayedSpinner; // If the graph takes a while to load, we want to show a spinner. - spinner = new DelayedSpinner({ - message: 'Calculating the project graph on the Nx Daemon', - ciDelay: 10_000, - }).scheduleMessageUpdate({ + spinner = new DelayedSpinner( + 'Calculating the project graph on the Nx Daemon' + ).scheduleMessageUpdate({ message: 'Calculating the project graph on the Nx Daemon is taking longer than expected. Re-run with NX_DAEMON=false to see more details.', ciDelay: 60_000, diff --git a/packages/nx/src/project-graph/build-project-graph.ts b/packages/nx/src/project-graph/build-project-graph.ts index e4137477834bc..a37283e0e746d 100644 --- a/packages/nx/src/project-graph/build-project-graph.ts +++ b/packages/nx/src/project-graph/build-project-graph.ts @@ -44,7 +44,7 @@ import { ConfigurationSourceMaps, mergeMetadata, } from './utils/project-configuration-utils'; -import { DelayedSpinner, SHOULD_SHOW_SPINNERS } from '../utils/delayed-spinner'; +import { DelayedSpinner } from '../utils/delayed-spinner'; let storedFileMap: FileMap | null = null; let storedAllWorkspaceFiles: FileData[] | null = null; @@ -342,10 +342,9 @@ async function updateProjectGraphWithPlugins( } } - spinner = new DelayedSpinner({ - message: `Creating project graph dependencies with ${plugins.length} plugins`, - ciDelay: 10_000, - }); + spinner = new DelayedSpinner( + `Creating project graph dependencies with ${plugins.length} plugins` + ); await Promise.all( createDependencyPlugins.map(async (plugin) => { @@ -461,12 +460,9 @@ export async function applyProjectMetadata( } } - if (SHOULD_SHOW_SPINNERS) { - spinner = new DelayedSpinner({ - message: `Creating project metadata with ${plugins.length} plugins`, - ciDelay: 10_000, - }); - } + spinner = new DelayedSpinner( + `Creating project metadata with ${plugins.length} plugins` + ); const promises = plugins.map(async (plugin) => { if (plugin.createMetadata) { diff --git a/packages/nx/src/project-graph/utils/project-configuration-utils.ts b/packages/nx/src/project-graph/utils/project-configuration-utils.ts index 42b74ead1518c..f46294ebe928a 100644 --- a/packages/nx/src/project-graph/utils/project-configuration-utils.ts +++ b/packages/nx/src/project-graph/utils/project-configuration-utils.ts @@ -31,11 +31,7 @@ import { } from '../error-types'; import { CreateNodesResult } from '../plugins/public-api'; import { isGlobPattern } from '../../utils/globs'; -import { isOnDaemon } from '../../daemon/is-on-daemon'; -import { - DelayedSpinner, - SHOULD_SHOW_SPINNERS, -} from '../../utils/delayed-spinner'; +import { DelayedSpinner } from '../../utils/delayed-spinner'; export type SourceInformation = [file: string | null, plugin: string]; export type ConfigurationSourceMaps = Record< diff --git a/packages/nx/src/utils/delayed-spinner.ts b/packages/nx/src/utils/delayed-spinner.ts index 6d927f81b655c..5c5918477c6dc 100644 --- a/packages/nx/src/utils/delayed-spinner.ts +++ b/packages/nx/src/utils/delayed-spinner.ts @@ -39,13 +39,13 @@ export class DelayedSpinner { typeof messageOrOpts === 'string' ? messageOrOpts : messageOrOpts.message; const opts: Omit = typeof messageOrOpts === 'string' ? { delay: ms } : messageOrOpts; - const ciDelay = opts.ciDelay ?? opts.delay ?? 5000; + const ciDelay = opts.ciDelay ?? opts.delay ?? 10_000; const delay = SHOULD_SHOW_SPINNERS ? ciDelay : opts.delay ?? 500; this.timeouts.push( setTimeout(() => { if (!SHOULD_SHOW_SPINNERS) { - console.log(message); + console.warn(message); } else { this.spinner = ora(message); } @@ -64,7 +64,7 @@ export class DelayedSpinner { if (this.spinner && SHOULD_SHOW_SPINNERS) { this.spinner.text = message; } else if (this.lastMessage && this.lastMessage !== message) { - console.log(message); + console.warn(message); this.lastMessage = message; } return this; @@ -98,4 +98,4 @@ export class DelayedSpinner { } } -export const SHOULD_SHOW_SPINNERS = process.stdout.isTTY && !isCI(); +const SHOULD_SHOW_SPINNERS = process.stdout.isTTY && !isCI();