Skip to content

Commit d24109d

Browse files
authored
chore: migrate from ora to nanospinner
1 parent a856ce0 commit d24109d

36 files changed

+196
-140
lines changed

docs/healthChecks.md

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Health Check Plugins
22

3-
Plugins can be used to extend the health checks that `npx react-native doctor` runs. This can be used to add additional checks for out of tree platforms, or other checks that are specific to a community module.
3+
Plugins can be used to extend the health checks that `npx react-native doctor` runs. This can be used to add additional checks for out of tree platforms, or other checks that are specific to a community module.
44

5-
See [`Plugins`](./plugins.md) for information about how plugins work.
5+
See [`Plugins`](./plugins.md) for information about how plugins work.
66

77
## How does it work?
88

@@ -21,7 +21,7 @@ module.exports = {
2121
}),
2222
runAutomaticFix: async ({loader}) => {
2323
await installBar();
24-
loader.succeed();
24+
loader.success();
2525
},
2626
},
2727
],
@@ -61,9 +61,7 @@ type HealthCheckInterface = {
6161
visible?: boolean | void;
6262
isRequired?: boolean;
6363
description: string;
64-
getDiagnostics: (
65-
environmentInfo: EnvironmentInfo,
66-
) => Promise<{
64+
getDiagnostics: (environmentInfo: EnvironmentInfo) => Promise<{
6765
version?: string;
6866
versions?: [string];
6967
versionRange?: string;
@@ -94,7 +92,7 @@ Longer description of this health check
9492

9593
##### `getDiagnostics`
9694

97-
Functions which performs the actual check. Simple checks can just return `needsToBeFixed`. Checks which are looking at versions of an installed component (such as the version of node), can also return `version`, `versions` and `versionRange` to provide better information to be displayed in `react-native doctor` when running the check
95+
Functions which performs the actual check. Simple checks can just return `needsToBeFixed`. Checks which are looking at versions of an installed component (such as the version of node), can also return `version`, `versions` and `versionRange` to provide better information to be displayed in `react-native doctor` when running the check
9896

9997
##### `win32AutomaticFix`
10098

@@ -116,7 +114,7 @@ This function will be used to try to fix the issue when `react-native doctor` is
116114

117115
```ts
118116
type RunAutomaticFix = (args: {
119-
loader: Ora;
117+
loader: Spinner;
120118
logManualInstallation: ({
121119
healthcheck,
122120
url,
@@ -134,7 +132,7 @@ type RunAutomaticFix = (args: {
134132

135133
##### `loader`
136134

137-
A reference to a [`ora`](https://www.npmjs.com/package/ora) instance which should be used to report success / failure, and progress of the fix. The fix function should always call either `loader.succeed()` or `loader.fail()` before returning.
135+
A reference to a [`nanospinner`](https://www.npmjs.com/package/nanospinner) instance which should be used to report success / failure, and progress of the fix. The fix function should always call either `loader.success()` or `loader.error()` before returning.
138136

139137
##### `logManualInstallation`
140138

@@ -146,26 +144,27 @@ Provides information about the current system
146144

147145
### Examples of RunAutomaticFix implementations
148146

149-
A health check that requires the user to manually go download/install something. This check will immediately display a message to notify the user how to fix the issue.
147+
A health check that requires the user to manually go download/install something. This check will immediately display a message to notify the user how to fix the issue.
150148

151149
```ts
152150
async function needToInstallFoo({loader, logManualInstallation}) {
153-
loader.fail();
151+
loader.error();
154152

155-
return logManualInstallation({
156-
healthcheck: 'Foo',
157-
url: 'https:/foo.com/download',
158-
});
153+
return logManualInstallation({
154+
healthcheck: 'Foo',
155+
url: 'https:/foo.com/download',
156+
});
159157
}
160158
```
161159

162-
A health check that runs some commands locally which may fix the issue. This check will display a spinner while the exec commands are running. Then once the commands are complete, the spinner will change to a checkmark.
160+
A health check that runs some commands locally which may fix the issue. This check will display a spinner while the exec commands are running. Then once the commands are complete, the spinner will change to a checkmark.
163161

164162
```ts
165-
import { exec } from 'promisify-child-process';
163+
import {exec} from 'promisify-child-process';
166164
async function fixFoo({loader}) {
167165
await exec(`foo --install`);
168166
await exec(`foo --fix`);
169167

170-
loader.succeed();
168+
loader.success();
171169
}
170+
```

docs/init.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,25 +78,29 @@ module.exports = {
7878

7979
## Post init script loading
8080

81-
The responsibility of showing the user progress of the "Executing post init script" goes to the implementor. In the cli, the `ora` package is used to display progress.
82-
For a simple usage in a custom template, `ora` can be used like this in a postInitScript :
81+
The responsibility of showing the user progress of the "Executing post init script" goes to the implementor. In the cli, the `nanospinner` package is used to display progress.
82+
For a simple usage in a custom template, `nanospinner` can be used like this in a postInitScript :
8383

8484
```javascript
8585
#!/usr/bin/env node
86-
const ora = require('ora');
86+
const {createSpinner} = require('nanospinner');
8787

88-
const spinner = ora('Executing post init script ');
88+
const spinner = createSpinner('Executing post init script ');
8989

9090
new Promise((resolve) => {
9191
spinner.start();
9292
// do something
9393
resolve();
94-
}).then(() => {
95-
spinner.succeed();
96-
}).catch(() => {
97-
spinner.fail();
98-
throw new Error('Something went wrong during the post init script execution');
99-
});
94+
})
95+
.then(() => {
96+
spinner.success();
97+
})
98+
.catch(() => {
99+
spinner.error();
100+
throw new Error(
101+
'Something went wrong during the post init script execution',
102+
);
103+
});
100104
```
101105

102106
You can find example custom template [here](https://github.com/Esemesek/react-native-new-template).

packages/cli-clean/src/clean.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,10 @@ export async function clean(
235235
spinner.start(label);
236236
await action()
237237
.then(() => {
238-
spinner.succeed();
238+
spinner.success();
239239
})
240240
.catch((e) => {
241-
spinner.fail(`${label} » ${e}`);
241+
spinner.error(`${label} » ${e}`);
242242
});
243243
}
244244
}

packages/cli-config-apple/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
"fast-glob": "^3.3.2"
1414
},
1515
"devDependencies": {
16-
"@react-native-community/cli-types": "19.0.0",
17-
"ora": "^5.4.1"
16+
"@react-native-community/cli-types": "19.0.0-alpha.0",
17+
"nanospinner": "^1.0.0"
1818
},
1919
"files": [
2020
"build",

packages/cli-config-apple/src/tools/installPods.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import fs from 'fs';
22
import execa from 'execa';
3-
import type {Ora} from 'ora';
3+
import type {Spinner} from 'nanospinner';
44
import chalk from 'chalk';
55
import {
66
logger,
@@ -22,7 +22,7 @@ interface RunPodInstallOptions {
2222
newArchEnabled?: boolean;
2323
}
2424

25-
async function runPodInstall(loader: Ora, options: RunPodInstallOptions) {
25+
async function runPodInstall(loader: Spinner, options: RunPodInstallOptions) {
2626
const shouldHandleRepoUpdate = options?.shouldHandleRepoUpdate || true;
2727
try {
2828
loader.start(
@@ -56,7 +56,7 @@ async function runPodInstall(loader: Ora, options: RunPodInstallOptions) {
5656
newArchEnabled: options?.newArchEnabled,
5757
});
5858
} else {
59-
loader.fail();
59+
loader.error();
6060
logger.error(stderr);
6161

6262
throw new CLIError(
@@ -70,7 +70,7 @@ async function runPodInstall(loader: Ora, options: RunPodInstallOptions) {
7070
}
7171
}
7272

73-
async function runPodUpdate(loader: Ora) {
73+
async function runPodUpdate(loader: Spinner) {
7474
try {
7575
loader.start(
7676
`Updating CocoaPods repositories ${chalk.dim(
@@ -81,7 +81,7 @@ async function runPodUpdate(loader: Ora) {
8181
} catch (error) {
8282
// "pod" command outputs errors to stdout (at least some of them)
8383
logger.log((error as any).stderr || (error as any).stdout);
84-
loader.fail();
84+
loader.error();
8585

8686
throw new CLIError(
8787
`Failed to update CocoaPods repositories for iOS project.\nPlease try again manually: "pod repo update".\nCocoaPods documentation: ${chalk.dim.underline(
@@ -103,17 +103,17 @@ async function installCocoaPodsWithGem() {
103103
}
104104
}
105105

106-
async function installCocoaPods(loader: Ora) {
106+
async function installCocoaPods(loader: Spinner) {
107107
loader.stop();
108108

109109
loader.start('Installing CocoaPods');
110110

111111
try {
112112
await installCocoaPodsWithGem();
113113

114-
return loader.succeed();
114+
return loader.success();
115115
} catch (error) {
116-
loader.fail();
116+
loader.error();
117117
logger.error((error as any).stderr);
118118

119119
throw new CLIError(
@@ -124,7 +124,7 @@ async function installCocoaPods(loader: Ora) {
124124
}
125125
}
126126

127-
async function installPods(loader?: Ora, options?: PodInstallOptions) {
127+
async function installPods(loader?: Spinner, options?: PodInstallOptions) {
128128
loader = loader || new NoopLoader();
129129
try {
130130
if (!options?.iosFolderPath && !fs.existsSync('ios')) {

packages/cli-config-apple/src/tools/pods.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ async function install(
9494
root: string,
9595
reactNativePath: string,
9696
) {
97-
const loader = getLoader('Installing CocoaPods...');
97+
const loader = getLoader({text: 'Installing CocoaPods...'});
9898
try {
9999
await runCodegen({
100100
root,
@@ -106,9 +106,9 @@ async function install(
106106
iosFolderPath,
107107
});
108108
cacheManager.set(packageJson.name, 'dependencies', currentDependenciesHash);
109-
loader.succeed();
109+
loader.success();
110110
} catch (error) {
111-
loader.fail();
111+
loader.error();
112112
throw new CLIError(
113113
`Something when wrong while installing CocoaPods. Please run ${chalk.bold(
114114
'pod install',
@@ -182,7 +182,7 @@ export default async function resolvePods(
182182
currentPodfileLockChecksum ?? '',
183183
);
184184
} else {
185-
const loader = getLoader('Installing CocoaPods...');
185+
const loader = getLoader({text: 'Installing CocoaPods...'});
186186
try {
187187
await installPods(loader, {
188188
skipBundleInstall: !!cachedDependenciesHash,
@@ -202,9 +202,9 @@ export default async function resolvePods(
202202
'podfileLock',
203203
currentPodfileLockChecksum ?? '',
204204
);
205-
loader.succeed();
205+
loader.success();
206206
} catch (error) {
207-
loader.fail();
207+
loader.error();
208208
throw new CLIError(
209209
`Something when wrong while installing CocoaPods. Please run ${chalk.bold(
210210
'pod install',
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import execa from 'execa';
22
import {CLIError, logger, link} from '@react-native-community/cli-tools';
3-
import type {Ora} from 'ora';
3+
import type {Spinner} from 'nanospinner';
44

5-
async function runBundleInstall(loader: Ora) {
5+
async function runBundleInstall(loader: Spinner) {
66
try {
77
loader.start('Installing Ruby Gems');
88

99
await execa('bundle', ['install']);
1010
} catch (error) {
11-
loader.fail();
11+
loader.error();
1212
logger.error((error as any).stderr || (error as any).stdout);
1313
throw new CLIError(
1414
`Looks like your iOS environment is not properly set. Please go to ${link.docs(
@@ -19,7 +19,7 @@ async function runBundleInstall(loader: Ora) {
1919
);
2020
}
2121

22-
loader.succeed();
22+
loader.success();
2323
}
2424

2525
export default runBundleInstall;

packages/cli-doctor/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
"deepmerge": "^4.3.0",
1919
"envinfo": "^7.13.0",
2020
"execa": "^5.0.0",
21+
"nanospinner": "^1.0.0",
2122
"node-stream-zip": "^1.9.1",
22-
"ora": "^5.4.1",
2323
"semver": "^7.5.2",
2424
"wcwidth": "^1.0.1",
2525
"yaml": "^2.2.1"

packages/cli-doctor/src/tools/brewInstall.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ async function brewInstall({
2626
return onSuccess();
2727
}
2828

29-
return loader.succeed();
29+
return loader.success();
3030
} catch (error) {
3131
if (typeof onFail === 'function') {
3232
return onFail();

packages/cli-doctor/src/tools/downloadAndUnzip.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const downloadAndUnzip = async ({
2424

2525
const installer = await fetchToTemp(downloadUrl);
2626

27-
loader.text = `Installing ${component} in "${installPath}"`;
27+
loader.update(`Installing ${component} in "${installPath}"`);
2828
try {
2929
await unzip(installer, installPath);
3030
} finally {

packages/cli-doctor/src/tools/healthchecks/__tests__/androidSDK.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ describe('androidSDK', () => {
8181
'android/build.gradle': `
8282
buildscript {
8383
ext {
84-
buildToolsVersion = findProperty('android.buildToolsVersion') ?: '34.0.0'
84+
buildToolsVersion = findProperty('android.buildToolsVersion') ?: '34.0.0'
8585
minSdkVersion = 16
8686
compileSdkVersion = 28
8787
targetSdkVersion = 28
@@ -123,8 +123,8 @@ describe('androidSDK', () => {
123123

124124
it('installs the SDK if it is missing on Windows', async () => {
125125
const loader = new tools.NoopLoader();
126-
const loaderSucceedSpy = jest.spyOn(loader, 'succeed');
127-
const loaderFailSpy = jest.spyOn(loader, 'fail');
126+
const loaderSuccessSpy = jest.spyOn(loader, 'success');
127+
const loaderErrorSpy = jest.spyOn(loader, 'error');
128128
const downloadAndUnzipSpy = jest
129129
.spyOn(downloadAndUnzip, 'downloadAndUnzip')
130130
.mockImplementation(() => Promise.resolve());
@@ -178,10 +178,10 @@ describe('androidSDK', () => {
178178
expect(requiredComponents.includes(call[0])).toBeTruthy();
179179
}
180180

181-
expect(loaderFailSpy).toHaveBeenCalledTimes(0);
181+
expect(loaderErrorSpy).toHaveBeenCalledTimes(0);
182182
expect(logSpy).toHaveBeenCalledTimes(0);
183183

184-
expect(loaderSucceedSpy).toBeCalledWith(
184+
expect(loaderSuccessSpy).toBeCalledWith(
185185
'Android SDK configured. You might need to restart your PC for all changes to take effect.',
186186
);
187187
});

packages/cli-doctor/src/tools/healthchecks/__tests__/androidStudio.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ describe('androidStudio', () => {
5353

5454
it('downloads and unzips Android Studio on Windows when missing', async () => {
5555
const loader = new NoopLoader();
56-
const loaderSucceedSpy = jest.spyOn(loader, 'succeed');
57-
const loaderFailSpy = jest.spyOn(loader, 'fail');
56+
const loaderSuccessSpy = jest.spyOn(loader, 'success');
57+
const loaderErrorSpy = jest.spyOn(loader, 'error');
5858
const downloadAndUnzipSpy = jest
5959
.spyOn(downloadAndUnzip, 'downloadAndUnzip')
6060
.mockImplementation(() => Promise.resolve());
@@ -65,10 +65,10 @@ describe('androidStudio', () => {
6565
environmentInfo,
6666
});
6767

68-
expect(loaderFailSpy).toHaveBeenCalledTimes(0);
68+
expect(loaderErrorSpy).toHaveBeenCalledTimes(0);
6969
expect(logSpy).toHaveBeenCalledTimes(0);
7070
expect(downloadAndUnzipSpy).toBeCalledTimes(1);
71-
expect(loaderSucceedSpy).toBeCalledWith(
71+
expect(loaderSuccessSpy).toBeCalledWith(
7272
`Android Studio installed successfully in "${
7373
downloadAndUnzipSpy.mock.calls[0][0].installPath || ''
7474
}".`,

0 commit comments

Comments
 (0)