Skip to content

cleanup(core): migrate to nanospinner #29138

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@
"metro-resolver": "~0.80.4",
"mini-css-extract-plugin": "~2.4.7",
"minimatch": "9.0.3",
"nanospinner": "1.2.2",
"next-sitemap": "^3.1.10",
"ng-packagr": "19.2.0",
"npm-package-arg": "11.0.1",
Expand Down
4 changes: 4 additions & 0 deletions packages/nx/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
{
"name": "fs-extra",
"message": "Please use equivalent utilities from `node:fs` instead."
},
{
"name": "ora",
"message": "Please use `nanospinner` instead."
}
],
"patterns": [
Expand Down
2 changes: 1 addition & 1 deletion packages/nx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@
"jsonc-parser": "3.2.0",
"lines-and-columns": "2.0.3",
"minimatch": "9.0.3",
"nanospinner": "1.2.2",
"node-machine-id": "1.1.12",
"npm-run-path": "^4.0.1",
"open": "^8.4.0",
"ora": "5.3.0",
"resolve.exports": "2.0.3",
"semver": "^7.5.3",
"string-width": "^4.2.3",
Expand Down
17 changes: 8 additions & 9 deletions packages/nx/src/command-line/add/add.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { exec } from 'child_process';
import { existsSync } from 'fs';
import * as ora from 'ora';
import * as yargsParser from 'yargs-parser';
import { createSpinner } from 'nanospinner';
import { readNxJson, type NxJsonConfiguration } from '../../config/nx-json';
import { runNxAsync } from '../../utils/child-process';
import { writeJsonFile } from '../../utils/fileutils';
Expand Down Expand Up @@ -44,7 +43,7 @@ async function installPackage(
version: string,
nxJson: NxJsonConfiguration
): Promise<void> {
const spinner = ora(`Installing ${pkgName}@${version}...`);
const spinner = createSpinner(`Installing ${pkgName}@${version}...`);
spinner.start();

if (existsSync('package.json')) {
Expand All @@ -65,7 +64,7 @@ async function installPackage(
},
(error, stdout) => {
if (error) {
spinner.fail();
spinner.error();
output.addNewline();
logger.error(stdout);
output.error({
Expand Down Expand Up @@ -93,7 +92,7 @@ async function installPackage(
nxJson.installation.plugins[pkgName] = undefined;
writeJsonFile('nx.json', nxJson);

spinner.fail();
spinner.error();
output.addNewline();
logger.error(e.message);
output.error({
Expand All @@ -103,7 +102,7 @@ async function installPackage(
}
}

spinner.succeed();
spinner.success();
}

async function initializePlugin(
Expand All @@ -122,7 +121,7 @@ async function initializePlugin(
updatePackageScripts = true;
}

const spinner = ora(`Initializing ${pkgName}...`);
const spinner = createSpinner(`Initializing ${pkgName}...`);
spinner.start();

try {
Expand All @@ -133,7 +132,7 @@ async function initializePlugin(
options.verbose
);
} catch (e) {
spinner.fail();
spinner.error();
output.addNewline();
output.error({
title: `Failed to initialize ${pkgName}`,
Expand All @@ -142,7 +141,7 @@ async function initializePlugin(
process.exit(1);
}

spinner.succeed();
spinner.success();
}

function parsePackageSpecifier(
Expand Down
9 changes: 5 additions & 4 deletions packages/nx/src/command-line/connect/connect-to-nx-cloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
import { nxVersion } from '../../utils/versions';
import { workspaceRoot } from '../../utils/workspace-root';
import chalk = require('chalk');
import * as ora from 'ora';
import { createSpinner } from 'nanospinner';
import * as open from 'open';

export function onlyDefaultRunnerIsUsed(nxJson: NxJsonConfiguration) {
Expand Down Expand Up @@ -116,12 +116,13 @@ export async function connectToNxCloudCommand(
options?.generateToken !== true
);
try {
const cloudConnectSpinner = ora(
const cloudConnectSpinner = createSpinner(
`Opening Nx Cloud ${connectCloudUrl} in your browser to connect your workspace.`
).start();
);
cloudConnectSpinner.start();
await sleep(2000);
await open(connectCloudUrl);
cloudConnectSpinner.succeed();
cloudConnectSpinner.success();
} catch (e) {
output.note({
title: `Your Nx Cloud workspace is ready.`,
Expand Down
15 changes: 8 additions & 7 deletions packages/nx/src/command-line/import/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { stat, mkdir, rm } from 'node:fs/promises';
import { tmpdir } from 'tmp';
import { prompt } from 'enquirer';
import { output } from '../../utils/output';
import * as createSpinner from 'ora';
import { detectPlugins } from '../init/init-v2';
import { createSpinner } from 'nanospinner';
import { readNxJson } from '../../config/nx-json';
import { workspaceRoot } from '../../utils/workspace-root';
import {
Expand Down Expand Up @@ -114,7 +114,8 @@ export async function importHandler(options: ImportOptions) {
const sourceTempRepoPath = join(tempImportDirectory, 'repo');
const spinner = createSpinner(
`Cloning ${sourceRepository} into a temporary directory: ${sourceTempRepoPath} (Use --depth to limit commit history and speed up clone times)`
).start();
);
spinner.start();
try {
await rm(tempImportDirectory, { recursive: true });
} catch {}
Expand All @@ -131,14 +132,14 @@ export async function importHandler(options: ImportOptions) {
}
);
} catch (e) {
spinner.fail(
spinner.error(
`Failed to clone ${sourceRepository} into ${sourceTempRepoPath}`
);
let errorMessage = `Failed to clone ${sourceRepository} into ${sourceTempRepoPath}. Please double check the remote and try again.\n${e.message}`;

throw new Error(errorMessage);
}
spinner.succeed(`Cloned into ${sourceTempRepoPath}`);
spinner.success(`Cloned into ${sourceTempRepoPath}`);

// Detecting the package manager before preparing the source repo for import.
const sourcePackageManager = detectPackageManager(sourceGitClient.root);
Expand Down Expand Up @@ -203,7 +204,7 @@ export async function importHandler(options: ImportOptions) {
const tempImportBranch = getTempImportBranch(ref);
await sourceGitClient.addFetchRemote(importRemoteName, ref);
await sourceGitClient.fetch(importRemoteName, ref);
spinner.succeed(`Fetched ${ref} from ${sourceRepository}`);
spinner.success(`Fetched ${ref} from ${sourceRepository}`);
spinner.start(
`Checking out a temporary branch, ${tempImportBranch} based on ${ref}`
);
Expand All @@ -212,7 +213,7 @@ export async function importHandler(options: ImportOptions) {
base: `${importRemoteName}/${ref}`,
});

spinner.succeed(`Created a ${tempImportBranch} branch based on ${ref}`);
spinner.success(`Created a ${tempImportBranch} branch based on ${ref}`);

try {
await stat(absSource);
Expand Down Expand Up @@ -256,7 +257,7 @@ export async function importHandler(options: ImportOptions) {
spinner.start('Cleaning up temporary files and remotes');
await rm(tempImportDirectory, { recursive: true });
await destinationGitClient.deleteGitRemote(importRemoteName);
spinner.succeed('Cleaned up temporary files and remotes');
spinner.success('Cleaned up temporary files and remotes');

const pmc = getPackageManagerCommand();
const nxJson = readNxJson(workspaceRoot);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GitRepository } from '../../../utils/git-utils';
import * as createSpinner from 'ora';
import { createSpinner } from 'nanospinner';

export async function mergeRemoteSource(
destinationGitClient: GitRepository,
Expand All @@ -9,14 +9,13 @@ export async function mergeRemoteSource(
remoteName: string,
branchName: string
) {
const spinner = createSpinner();
spinner.start(
const spinner = createSpinner(
`Merging ${branchName} from ${sourceRemoteUrl} into ${destination}`
);

spinner.start(`Fetching ${tempBranch} from ${remoteName}`);
await destinationGitClient.fetch(remoteName, tempBranch);
spinner.succeed(`Fetched ${tempBranch} from ${remoteName}`);
spinner.success(`Fetched ${tempBranch} from ${remoteName}`);

spinner.start(
`Merging files and git history from ${branchName} from ${sourceRemoteUrl} into ${destination}`
Expand All @@ -26,7 +25,7 @@ export async function mergeRemoteSource(
`feat(repo): merge ${branchName} from ${sourceRemoteUrl}`
);

spinner.succeed(
spinner.success(
`Merged files and git history from ${branchName} from ${sourceRemoteUrl} into ${destination}`
);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as createSpinner from 'ora';
import { join, relative } from 'path';
import { createSpinner } from 'nanospinner';
import { GitRepository } from '../../../utils/git-utils';

export async function prepareSourceRepo(
Expand All @@ -10,9 +10,8 @@ export async function prepareSourceRepo(
tempImportBranch: string,
sourceRemoteUrl: string
) {
const spinner = createSpinner().start(
`Fetching ${ref} from ${sourceRemoteUrl}`
);
const spinner = createSpinner(`Fetching ${ref} from ${sourceRemoteUrl}`);
spinner.start();
const relativeSourceDir = relative(
gitClient.root,
join(gitClient.root, source)
Expand All @@ -23,10 +22,10 @@ export async function prepareSourceRepo(
: `Filtering git history`;

if (await gitClient.hasFilterRepoInstalled()) {
spinner.start(message);
spinner.write(message);
await gitClient.filterRepo(relativeSourceDir, relativeDestination);
} else {
spinner.start(
spinner.write(
`${message} (this might take a few minutes -- install git-filter-repo for faster performance)`
);
await gitClient.filterBranch(
Expand All @@ -35,13 +34,13 @@ export async function prepareSourceRepo(
tempImportBranch
);
}
spinner.succeed(
spinner.success(
relativeSourceDir.trim()
? `Filtered git history to only include files in ${relativeSourceDir}`
: `Filtered git history`
);

spinner.succeed(
spinner.success(
`${sourceRemoteUrl} has been prepared to be imported into this workspace on a temporary branch: ${tempImportBranch} in ${gitClient.root}`
);
}
Expand Down
6 changes: 3 additions & 3 deletions packages/nx/src/command-line/init/configure-plugins.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as createSpinner from 'ora';
import { createSpinner } from 'nanospinner';
import { bold } from 'chalk';
import { execSync } from 'child_process';

Expand Down Expand Up @@ -132,10 +132,10 @@ export async function runPluginInitGenerators(
pmc
);
succeededPlugins.push(plugin);
spinner.succeed('Installed plugin ' + plugin);
spinner.success('Installed plugin ' + plugin);
} catch (e) {
failedPlugins[plugin] = e;
spinner.fail('Failed to install plugin ' + plugin);
spinner.error('Failed to install plugin ' + plugin);
}
}

Expand Down
10 changes: 5 additions & 5 deletions packages/nx/src/command-line/sync/sync.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as ora from 'ora';
import { createSpinner } from 'nanospinner';
import { readNxJson } from '../../config/nx-json';
import { createProjectGraphAsync } from '../../project-graph/project-graph';
import { output } from '../../utils/output';
Expand Down Expand Up @@ -103,14 +103,14 @@ export function syncHandler(options: SyncOptions): Promise<number> {
bodyLines: resultBodyLines,
});

const spinner = ora('Syncing the workspace...');
const spinner = createSpinner('Syncing the workspace...');
spinner.start();

try {
const flushResult = await flushSyncGeneratorChanges(results);

if ('generatorFailures' in flushResult) {
spinner.fail();
spinner.error();
output.error({
title: 'Failed to sync the workspace',
bodyLines: getFlushFailureMessageLines(
Expand All @@ -123,7 +123,7 @@ export function syncHandler(options: SyncOptions): Promise<number> {
return 1;
}
} catch (e) {
spinner.fail();
spinner.error();
output.error({
title: 'Failed to sync the workspace',
bodyLines: [
Expand All @@ -147,7 +147,7 @@ export function syncHandler(options: SyncOptions): Promise<number> {
'The workspace was synced successfully!';
const successSubtitle =
'Please make sure to commit the changes to your repository.';
spinner.succeed(`${successTitle}\n\n${successSubtitle}`);
spinner.success(`${successTitle}\n\n${successSubtitle}`);

if (anySyncGeneratorsFailed) {
output.error({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const { FileLock } = require('../../native-bindings.js');
const ora = require('ora');
const { createSpinner } = require('nanospinner');
const tmp = require('os').tmpdir();

(async () => {
const lock = new FileLock(
require('path').join(tmp, 'nx-unit-tests', 'file-lock-fixture')
);
if (lock.locked) {
const s = ora('Waiting for lock').start();
const s = createSpinner('Waiting for lock').start();
await lock.wait();
s.stop();
console.log('waited for lock');
Expand Down
8 changes: 4 additions & 4 deletions packages/nx/src/tasks-runner/run-command.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { prompt } from 'enquirer';
import { join } from 'node:path';
import { stripVTControlCharacters } from 'node:util';
import * as ora from 'ora';
import { createSpinner } from 'nanospinner';
import type { Observable } from 'rxjs';
import {
NxJsonConfiguration,
Expand Down Expand Up @@ -651,14 +651,14 @@ async function ensureWorkspaceIsInSyncAndGetGraphs(
(await promptForApplyingSyncGeneratorChanges());

if (applyChanges) {
const spinner = ora('Syncing the workspace...');
const spinner = createSpinner('Syncing the workspace...');
spinner.start();

// Flush sync generator changes to disk
const flushResult = await flushSyncGeneratorChanges(results);

if ('generatorFailures' in flushResult) {
spinner.fail();
spinner.error();
output.error({
title: 'Failed to sync the workspace',
bodyLines: [
Expand Down Expand Up @@ -697,7 +697,7 @@ async function ensureWorkspaceIsInSyncAndGetGraphs(
: // The user was prompted and we already logged a message about erroring in CI
// so here we just tell them to commit the changes.
'Please make sure to commit the changes to your repository.';
spinner.succeed(`${successTitle}\n\n${successSubtitle}`);
spinner.success(`${successTitle}\n\n${successSubtitle}`);

if (anySyncGeneratorsFailed) {
output.warn({
Expand Down
Loading
Loading