Skip to content
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
21 changes: 21 additions & 0 deletions __mocks__/nanospinner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
function createSpinner() {
const spinner = {
start: () => spinner,
stop: () => spinner,
success: () => spinner,
error: () => spinner,
warn: () => spinner,
info: () => spinner,
clear: () => spinner,
render: () => spinner,
update: () => spinner,
reset: () => spinner,
spin: () => spinner,
write: () => spinner,
loop: () => spinner,
isSpinning: () => false,
};
return spinner;
}

module.exports = {createSpinner};
10 changes: 5 additions & 5 deletions docs/healthChecks.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = {
}),
runAutomaticFix: async ({loader}) => {
await installBar();
loader.succeed();
loader.success();
},
},
],
Expand Down Expand Up @@ -116,7 +116,7 @@ This function will be used to try to fix the issue when `react-native doctor` is

```ts
type RunAutomaticFix = (args: {
loader: Ora;
loader: Loader;
logManualInstallation: ({
healthcheck,
url,
Expand All @@ -134,7 +134,7 @@ type RunAutomaticFix = (args: {

##### `loader`

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.
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.

##### `logManualInstallation`

Expand All @@ -150,7 +150,7 @@ A health check that requires the user to manually go download/install something.

```ts
async function needToInstallFoo({loader, logManualInstallation}) {
loader.fail();
loader.error();

return logManualInstallation({
healthcheck: 'Foo',
Expand All @@ -167,5 +167,5 @@ async function fixFoo({loader}) {
await exec(`foo --install`);
await exec(`foo --fix`);

loader.succeed();
loader.success();
}
12 changes: 6 additions & 6 deletions docs/init.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,23 @@ module.exports = {

## Post init script loading

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.
For a simple usage in a custom template, `ora` can be used like this in a postInitScript :
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.
For a simple usage in a custom template, `nanospinner` can be used like this in a postInitScript :

```javascript
#!/usr/bin/env node
const ora = require('ora');
const {createSpinner} = require('nanospinner');

const spinner = ora('Executing post init script ');
const spinner = createSpinner('Executing post init script ');

new Promise((resolve) => {
spinner.start();
// do something
resolve();
}).then(() => {
spinner.succeed();
spinner.success();
}).catch(() => {
spinner.fail();
spinner.error();
throw new Error('Something went wrong during the post init script execution');
});
```
Expand Down
4 changes: 2 additions & 2 deletions packages/cli-clean/src/clean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,10 @@ export async function clean(
spinner.start(label);
await action()
.then(() => {
spinner.succeed();
spinner.success();
})
.catch((e) => {
spinner.fail(`${label} » ${e}`);
spinner.error(`${label} » ${e}`);
});
}
}
Expand Down
3 changes: 1 addition & 2 deletions packages/cli-config-apple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
"picocolors": "^1.1.1"
},
"devDependencies": {
"@react-native-community/cli-types": "20.1.3",
"ora": "^5.4.1"
"@react-native-community/cli-types": "20.1.3"
},
"files": [
"build",
Expand Down
18 changes: 9 additions & 9 deletions packages/cli-config-apple/src/tools/installPods.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs';
import execa from 'execa';
import type {Ora} from 'ora';
import type {Loader} from '@react-native-community/cli-tools';
import pico from 'picocolors';
import {
logger,
Expand All @@ -23,7 +23,7 @@ interface RunPodInstallOptions {
newArchEnabled?: boolean;
}

async function runPodInstall(loader: Ora, options: RunPodInstallOptions) {
async function runPodInstall(loader: Loader, options: RunPodInstallOptions) {
const shouldHandleRepoUpdate = options?.shouldHandleRepoUpdate || true;
try {
loader.start(
Expand Down Expand Up @@ -66,7 +66,7 @@ async function runPodInstall(loader: Ora, options: RunPodInstallOptions) {
newArchEnabled: options?.newArchEnabled,
});
} else {
loader.fail();
loader.error();
logger.error(stderr);

throw new CLIError(
Expand All @@ -80,7 +80,7 @@ async function runPodInstall(loader: Ora, options: RunPodInstallOptions) {
}
}

async function runPodUpdate(loader: Ora) {
async function runPodUpdate(loader: Loader) {
try {
loader.start(
`Updating CocoaPods repositories ${pico.dim(
Expand All @@ -91,7 +91,7 @@ async function runPodUpdate(loader: Ora) {
} catch (error) {
// "pod" command outputs errors to stdout (at least some of them)
logger.log((error as any).stderr || (error as any).stdout);
loader.fail();
loader.error();

throw new CLIError(
`Failed to update CocoaPods repositories for iOS project.\nPlease try again manually: "pod repo update".\nCocoaPods documentation: ${pico.dim(
Expand All @@ -113,17 +113,17 @@ async function installCocoaPodsWithGem() {
}
}

async function installCocoaPods(loader: Ora) {
async function installCocoaPods(loader: Loader) {
loader.stop();

loader.start('Installing CocoaPods');

try {
await installCocoaPodsWithGem();

return loader.succeed();
return loader.success();
} catch (error) {
loader.fail();
loader.error();
logger.error((error as any).stderr);

throw new CLIError(
Expand All @@ -134,7 +134,7 @@ async function installCocoaPods(loader: Ora) {
}
}

async function installPods(loader?: Ora, options?: PodInstallOptions) {
async function installPods(loader?: Loader, options?: PodInstallOptions) {
loader = loader || new NoopLoader();
try {
if (!options?.iosFolderPath && !fs.existsSync('ios')) {
Expand Down
8 changes: 4 additions & 4 deletions packages/cli-config-apple/src/tools/pods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ async function install(
iosFolderPath,
});
cacheManager.set(packageJson.name, 'dependencies', currentDependenciesHash);
loader.succeed();
loader.success();
} catch (error) {
loader.fail();
loader.error();
throw new CLIError(
`Something went wrong while installing CocoaPods. Please run ${pico.bold(
'pod install',
Expand Down Expand Up @@ -204,9 +204,9 @@ export default async function resolvePods(
'podfileLock',
currentPodfileLockChecksum ?? '',
);
loader.succeed();
loader.success();
} catch (error) {
loader.fail();
loader.error();
throw new CLIError(
`Something went wrong while installing CocoaPods. Please run ${pico.bold(
'pod install',
Expand Down
8 changes: 4 additions & 4 deletions packages/cli-config-apple/src/tools/runBundleInstall.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import execa from 'execa';
import {CLIError, logger, link} from '@react-native-community/cli-tools';
import type {Ora} from 'ora';
import type {Loader} from '@react-native-community/cli-tools';

async function runBundleInstall(loader: Ora) {
async function runBundleInstall(loader: Loader) {
try {
loader.start('Installing Ruby Gems');

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

loader.succeed();
loader.success();
}

export default runBundleInstall;
1 change: 0 additions & 1 deletion packages/cli-doctor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"envinfo": "^7.13.0",
"execa": "^5.0.0",
"node-stream-zip": "^1.9.1",
"ora": "^5.4.1",
"picocolors": "^1.1.1",
"semver": "^7.5.2",
"wcwidth": "^1.0.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-doctor/src/tools/brewInstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async function brewInstall({
return onSuccess();
}

return loader.succeed();
return loader.success();
} catch (error) {
if (typeof onFail === 'function') {
return onFail();
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-doctor/src/tools/downloadAndUnzip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const downloadAndUnzip = async ({

const installer = await fetchToTemp(downloadUrl);

loader.text = `Installing ${component} in "${installPath}"`;
loader.update(`Installing ${component} in "${installPath}"`);
try {
await unzip(installer, installPath);
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ describe('androidSDK', () => {

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

expect(loaderFailSpy).toHaveBeenCalledTimes(0);
expect(loaderErrorSpy).toHaveBeenCalledTimes(0);
expect(logSpy).toHaveBeenCalledTimes(0);

expect(loaderSucceedSpy).toBeCalledWith(
expect(loaderSuccessSpy).toBeCalledWith(
'Android SDK configured. You might need to restart your PC for all changes to take effect.',
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ describe('androidStudio', () => {

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

expect(loaderFailSpy).toHaveBeenCalledTimes(0);
expect(loaderErrorSpy).toHaveBeenCalledTimes(0);
expect(logSpy).toHaveBeenCalledTimes(0);
expect(downloadAndUnzipSpy).toBeCalledTimes(1);
expect(loaderSucceedSpy).toBeCalledWith(
expect(loaderSuccessSpy).toBeCalledWith(
`Android Studio installed successfully in "${
downloadAndUnzipSpy.mock.calls[0][0].installPath || ''
}".`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ describe('jdk', () => {

it('downloads and unzips JDK on Windows when missing', async () => {
const loader = new tools.NoopLoader();
const loaderSucceedSpy = jest.spyOn(loader, 'succeed');
const loaderFailSpy = jest.spyOn(loader, 'fail');
const loaderSuccessSpy = jest.spyOn(loader, 'success');
const loaderErrorSpy = jest.spyOn(loader, 'error');
const downloadAndUnzipSpy = jest
.spyOn(downloadAndUnzip, 'downloadAndUnzip')
.mockImplementation(() => Promise.resolve());
Expand All @@ -85,10 +85,10 @@ describe('jdk', () => {
environmentInfo,
});

expect(loaderFailSpy).toHaveBeenCalledTimes(0);
expect(loaderErrorSpy).toHaveBeenCalledTimes(0);
expect(logSpy).toHaveBeenCalledTimes(0);
expect(downloadAndUnzipSpy).toBeCalledTimes(1);
expect(loaderSucceedSpy).toBeCalledWith(
expect(loaderSuccessSpy).toBeCalledWith(
'JDK installed successfully. Please restart your shell to see the changes',
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ describe('watchman', () => {
});

const loaderSpy = new NoopLoader();
const loaderSucceedSpy = jest.spyOn(loaderSpy, 'succeed');
const loaderFailSpy = jest.spyOn(loaderSpy, 'fail');
const loaderSuccessSpy = jest.spyOn(loaderSpy, 'success');
const loaderErrorSpy = jest.spyOn(loaderSpy, 'error');
const brewInstallSpy = jest
.spyOn(brewInstall, 'brewInstall')
.mockImplementation(({loader}) => {
loader.succeed();
loader.success();
return Promise.resolve();
});

Expand All @@ -102,9 +102,9 @@ describe('watchman', () => {
value: originalPlatform,
});

expect(loaderFailSpy).toHaveBeenCalledTimes(0);
expect(loaderErrorSpy).toHaveBeenCalledTimes(0);
expect(logSpy).toHaveBeenCalledTimes(0);
expect(brewInstallSpy).toBeCalledTimes(1);
expect(loaderSucceedSpy).toBeCalledTimes(1);
expect(loaderSuccessSpy).toBeCalledTimes(1);
});
});
4 changes: 2 additions & 2 deletions packages/cli-doctor/src/tools/healthchecks/adb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default {
}
},
runAutomaticFix: async ({loader, logManualInstallation}) => {
loader.fail();
loader.error();
let hash: string;
switch (link.getOS()) {
case 'macos':
Expand All @@ -59,7 +59,7 @@ export default {
if (device && device.connected) {
tryRunAdbReverse(process.env.RCT_METRO_PORT || 8081, device.deviceId);
}
return loader.succeed();
return loader.success();
} catch (e) {
return logManualInstallation({
healthcheck: 'Adb',
Expand Down
Loading
Loading