Skip to content

Commit

Permalink
chore(core): review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder committed Dec 18, 2024
1 parent 209eae6 commit 0df7ef5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 28 deletions.
12 changes: 4 additions & 8 deletions packages/nx/src/daemon/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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,
Expand Down
18 changes: 7 additions & 11 deletions packages/nx/src/project-graph/build-project-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<
Expand Down
8 changes: 4 additions & 4 deletions packages/nx/src/utils/delayed-spinner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ export class DelayedSpinner {
typeof messageOrOpts === 'string' ? messageOrOpts : messageOrOpts.message;
const opts: Omit<DelayedSpinnerOptions, 'message'> =
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);
}
Expand All @@ -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;
Expand Down Expand Up @@ -98,4 +98,4 @@ export class DelayedSpinner {
}
}

export const SHOULD_SHOW_SPINNERS = process.stdout.isTTY && !isCI();
const SHOULD_SHOW_SPINNERS = process.stdout.isTTY && !isCI();

0 comments on commit 0df7ef5

Please sign in to comment.