Skip to content

Commit 4ce20fa

Browse files
committed
chore: migrate from ora to nanospinner
1 parent 46436a1 commit 4ce20fa

33 files changed

+171
-122
lines changed

docs/healthChecks.md

+17-18
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

+14-10
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

+2-2
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
},
1515
"devDependencies": {
1616
"@react-native-community/cli-types": "19.0.0-alpha.0",
17-
"ora": "^5.4.1"
17+
"nanospinner": "^1.0.0"
1818
},
1919
"files": [
2020
"build",

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

+9-9
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

+6-6
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',
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

+1-1
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

+1-1
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

+1-1
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__/watchman.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ describe('watchman', () => {
8787
const brewInstallSpy = jest
8888
.spyOn(brewInstall, 'brewInstall')
8989
.mockImplementation(({loader}) => {
90-
loader.succeed();
90+
loader.success();
9191
return Promise.resolve();
9292
});
9393

packages/cli-doctor/src/tools/healthchecks/adb.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export default {
3838
}
3939
},
4040
runAutomaticFix: async ({loader, logManualInstallation}) => {
41-
loader.fail();
41+
loader.error();
4242
let hash: string;
4343
switch (link.getOS()) {
4444
case 'macos':
@@ -59,7 +59,7 @@ export default {
5959
if (device && device.connected) {
6060
tryRunAdbReverse(process.env.RCT_METRO_PORT || 8081, device.deviceId);
6161
}
62-
return loader.succeed();
62+
return loader.success();
6363
} catch (e) {
6464
return logManualInstallation({
6565
healthcheck: 'Adb',

packages/cli-doctor/src/tools/healthchecks/androidHomeEnvVariable.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ export default {
2929
runAutomaticFix: async ({loader, logManualInstallation}) => {
3030
// Variable could have been added if installing Android Studio so double checking
3131
if (process.env.ANDROID_HOME) {
32-
loader.succeed();
32+
loader.success();
3333

3434
return;
3535
}
3636

37-
loader.fail();
37+
loader.error();
3838

3939
logManualInstallation({
4040
message,

packages/cli-doctor/src/tools/healthchecks/androidNDK.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export default {
2525
const isNDKInstalled =
2626
androidSdk !== 'Not Found' && androidSdk['Android NDK'] !== 'Not Found';
2727

28-
loader.fail();
28+
loader.error();
2929

3030
if (isNDKInstalled) {
3131
return logManualInstallation({

0 commit comments

Comments
 (0)