Skip to content
Merged
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
2 changes: 1 addition & 1 deletion __e2e__/__snapshots__/default.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ Options:

Commands:
init [options] <projectName> Initialize a new React Native project named <projectName> in a directory of the same name.
doctor [options] [EXPERIMENTAL] Diagnose and fix common Node.js, iOS, Android & React Native issues."
doctor [options] Diagnose and fix common Node.js, iOS, Android & React Native issues."
`;
1 change: 0 additions & 1 deletion jest/setupUnitTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@ jest.mock('@react-native-community/cli-tools', () => {
},
};
});

jest.setTimeout(20000);
33 changes: 33 additions & 0 deletions packages/cli-config/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "@react-native-community/cli-config",
"version": "6.0.1",
"license": "MIT",
"main": "build/index.js",
"publishConfig": {
"access": "public"
},
"types": "build/index.d.ts",
"dependencies": {
"cosmiconfig": "^5.1.0",
"deepmerge": "^3.2.0",
"@react-native-community/cli-tools": "^6.2.0",
"joi": "^17.2.1",
"glob": "^7.1.3"
},
"files": [
"build",
"!*.d.ts",
"!*.map"
],
"devDependencies": {
"@types/cosmiconfig": "^5.0.3",
"@react-native-community/cli-types": "^6.0.0",
"@types/glob": "^7.1.1"
},
"homepage": "https://github.com/react-native-community/cli/tree/master/packages/cli-config",
"repository": {
"type": "git",
"url": "https://github.com/react-native-community/cli.git",
"directory": "packages/cli-config"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ Object {

exports[`should skip packages that have invalid configuration: dependencies config 1`] = `Object {}`;

exports[`should skip packages that have invalid configuration: logged warning 1`] = `"Package react-native has been ignored because it contains invalid configuration. Reason: \\"dependency.invalidProperty\\" is not allowed"`;
exports[`should skip packages that have invalid configuration: logged warning 1`] = `"warn Package react-native has been ignored because it contains invalid configuration. Reason: \\"dependency.invalidProperty\\" is not allowed"`;

exports[`supports dependencies from user configuration with custom build type 1`] = `
Object {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import findDependencies from '../findDependencies';
import {
cleanup,
writeFiles,
getTempDirectory,
} from '../../../../../../jest/helpers';
import {cleanup, writeFiles, getTempDirectory} from '../../../../jest/helpers';

beforeEach(async () => {
await cleanup(DIR);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import path from 'path';
import slash from 'slash';
import loadConfig from '..';
import {logger} from '@react-native-community/cli-tools';
import {
cleanup,
writeFiles,
getTempDirectory,
} from '../../../../../../jest/helpers';

jest.mock('../resolveNodeModuleDir');
import {cleanup, writeFiles, getTempDirectory} from '../../../../jest/helpers';

let DIR = getTempDirectory('config_test');

jest.dontMock('@react-native-community/cli-tools');

const spy = jest.spyOn(global.console, 'warn').mockImplementation(jest.fn());

const iosPath = slash(
require.resolve('@react-native-community/cli-platform-ios'),
);
Expand Down Expand Up @@ -45,8 +42,11 @@ const REACT_NATIVE_MOCK = {
const removeString = (config, str) =>
JSON.parse(
JSON.stringify(config, (_key, value) =>
// In certain cases, `str` (which is a temporary location) will be `/tmp`
// which is a symlink to `/private/tmp` on OS X. In this case, tests will fail.
// Following RegExp makes sure we strip the entire path.
typeof value === 'string'
? slash(value.replace(str, '<<REPLACED>>'))
? slash(value.replace(new RegExp(`(.*)${str}`), '<<REPLACED>>'))
: value,
),
);
Expand Down Expand Up @@ -202,7 +202,6 @@ test('should skip packages that have invalid configuration', () => {
}
}`,
});
const spy = jest.spyOn(logger, 'warn');
const {dependencies} = loadConfig(DIR);
expect(dependencies).toMatchSnapshot('dependencies config');
expect(spy.mock.calls[0][0]).toMatchSnapshot('logged warning');
Expand All @@ -220,7 +219,6 @@ test('does not use restricted "react-native" key to resolve config from package.
}
}`,
});
const spy = jest.spyOn(logger, 'warn');
const {dependencies} = loadConfig(DIR);
expect(dependencies).toHaveProperty('react-native-netinfo');
expect(spy).not.toHaveBeenCalled();
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@ import {
UserConfig,
Config,
} from '@react-native-community/cli-types';
import {logger, inlineString} from '@react-native-community/cli-tools';
import {
logger,
inlineString,
findProjectRoot,
resolveNodeModuleDir,
} from '@react-native-community/cli-tools';
import findDependencies from './findDependencies';
import findProjectRoot from './findProjectRoot';
import resolveReactNativePath from './resolveReactNativePath';
import findAssets from './findAssets';
import {
readConfigFromDisk,
readDependencyConfigFromDisk,
} from './readConfigFromDisk';
import assign from '../assign';
import merge from '../merge';
import resolveNodeModuleDir from './resolveNodeModuleDir';
import assign from './assign';
import merge from './merge';

function getDependencyConfig(
root: string,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {CLIError} from '@react-native-community/cli-tools';

import resolveNodeModuleDir from './resolveNodeModuleDir';
import {
CLIError,
resolveNodeModuleDir,
} from '@react-native-community/cli-tools';

/**
* Finds path to React Native inside `node_modules` or throws
Expand Down
8 changes: 8 additions & 0 deletions packages/cli-config/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "build"
},
"references": [{"path": "../tools"}, {"path": "../cli-types"}]
}
46 changes: 46 additions & 0 deletions packages/cli-doctor/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"name": "@react-native-community/cli-doctor",
"version": "6.0.1",
"license": "MIT",
"main": "build/index.js",
"publishConfig": {
"access": "public"
},
"types": "build/index.d.ts",
"dependencies": {
"@react-native-community/cli-tools": "^6.2.0",
"@react-native-community/cli-config": "^6.0.1",
"chalk": "^3.0.0",
"envinfo": "^7.7.2",
"hermes-profile-transformer": "^0.0.6",
"ip": "^1.1.5",
"node-stream-zip": "^1.9.1",
"command-exists": "^1.2.8",
"prompts": "^2.4.0",
"semver": "^6.3.0",
"strip-ansi": "^5.2.0",
"ora": "^5.4.1",
"execa": "^1.0.0",
"wcwidth": "^1.0.1",
"sudo-prompt": "^9.0.0"
},
"files": [
"build",
"!*.d.ts",
"!*.map"
],
"devDependencies": {
"@types/command-exists": "^1.2.0",
"@react-native-community/cli-types": "^6.0.0",
"@types/ip": "^1.1.0",
"@types/semver": "^6.0.2",
"@types/wcwidth": "^1.0.0",
"@types/prompts": "^2.0.9"
},
"homepage": "https://github.com/react-native-community/cli/tree/master/packages/cli-doctor",
"repository": {
"type": "git",
"url": "https://github.com/react-native-community/cli.git",
"directory": "packages/cli-doctor"
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import info from '../info';
import {logger} from '@react-native-community/cli-tools';
import loadConfig from '../../../tools/config';
import loadConfig from '@react-native-community/cli-config';

jest.mock('../../../tools/config');
jest.mock('@react-native-community/cli-config');

beforeEach(() => {
jest.resetAllMocks();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import chalk from 'chalk';
import {logger} from '@react-native-community/cli-tools';
import {getHealthchecks, HEALTHCHECK_TYPES} from './healthchecks';
import {getLoader} from '../../tools/loader';
import printFixOptions, {KEYS} from './printFixOptions';
import runAutomaticFix, {AUTOMATIC_FIX_LEVELS} from './runAutomaticFix';
import {logger, getLoader} from '@react-native-community/cli-tools';
import {getHealthchecks, HEALTHCHECK_TYPES} from '../tools/healthchecks';
import printFixOptions, {KEYS} from '../tools/printFixOptions';
import runAutomaticFix, {AUTOMATIC_FIX_LEVELS} from '../tools/runAutomaticFix';
import {DetachedCommandFunction} from '@react-native-community/cli-types';
import {
DetachedCommandFunction,
HealthCheckCategory,
HealthCheckCategoryResult,
HealthCheckInterface,
} from '@react-native-community/cli-types';
import {HealthCheckCategoryResult, HealthCheckResult} from './types';
import getEnvironmentInfo from '../../tools/envinfo';
import {logMessage} from './healthchecks/common';
HealthCheckCategory,
HealthCheckResult,
} from '../types';
import getEnvironmentInfo from '../tools/envinfo';
import {logMessage} from '../tools/healthchecks/common';

const printCategory = ({label, key}: {label: string; key: number}) => {
if (key > 0) {
Expand Down Expand Up @@ -109,9 +109,8 @@ const getAutomaticFixForPlatform = (
}
};

export default (async (_, options) => {
const Loader = getLoader();
const loader = new Loader();
const doctorCommand = (async (_, options) => {
const loader = getLoader();

loader.start('Running diagnostics...');

Expand Down Expand Up @@ -264,3 +263,22 @@ export default (async (_, options) => {
printFixOptions({onKeyPress});
}
}) as DetachedCommandFunction<FlagsT>;

export default {
func: doctorCommand,
detached: true,
name: 'doctor',
description:
'Diagnose and fix common Node.js, iOS, Android & React Native issues.',
options: [
{
name: '--fix',
description: 'Attempt to fix all diagnosed issues.',
},
{
name: '--contributor',
description:
'Add healthchecks required to installations required for contributing to React Native.',
},
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

// @ts-ignore untyped
import getEnvironmentInfo from '../../tools/envinfo';
import getEnvironmentInfo from '../tools/envinfo';
import {logger, releaseChecker} from '@react-native-community/cli-tools';
import {Config} from '@react-native-community/cli-types';

Expand Down
11 changes: 11 additions & 0 deletions packages/cli-doctor/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import doctor from './commands/doctor';
import info from './commands/info';

export const commands = {info, doctor};

/**
* @todo
* We should not rely on this file from other packages, e.g. CLI. We probably need to
* refactor the init in order to remove that connection.
*/
export {default as installPods} from './tools/installPods';
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import execa from 'execa';
import type {Ora} from 'ora';
import {logError} from '../commands/doctor/healthchecks/common';
import {Loader} from '../types';
import {logError} from './healthchecks/common';

type InstallArgs = {
pkg: string;
label?: string;
loader: Ora;
loader: Loader;
onSuccess?: () => void;
onFail?: () => void;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {fetchToTemp} from '@react-native-community/cli-tools';

import * as ora from 'ora';
import {Loader} from '../types';
import {unzip} from './unzip';
import {deleteFile} from './deleteFile';

Expand All @@ -14,7 +13,7 @@ export const downloadAndUnzip = async ({
component,
installPath,
}: {
loader: ora.Ora;
loader: Loader;
component: string;
downloadUrl: string;
installPath: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @ts-ignore
import envinfo from 'envinfo';
import {EnvironmentInfo} from '@react-native-community/cli-types';
import {platform} from 'os';
import {EnvironmentInfo} from '../types';

/**
* Returns information about the running system.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import androidHomeEnvVariables from '../androidHomeEnvVariable';
import {NoopLoader} from '../../../../tools/loader';
import {EnvironmentInfo} from '@react-native-community/cli-types';
import {NoopLoader} from '@react-native-community/cli-tools';
import {EnvironmentInfo} from '../../../types';

import * as common from '../common';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import androidNDK from '../androidNDK';
import getEnvironmentInfo from '../../../../tools/envinfo';
import {EnvironmentInfo} from '@react-native-community/cli-types';
import {NoopLoader} from '../../../../tools/loader';
import getEnvironmentInfo from '../../envinfo';
import {EnvironmentInfo} from '../../../types';
import {NoopLoader} from '@react-native-community/cli-tools';

import * as common from '../common';

Expand All @@ -19,12 +19,6 @@ describe('androidNDK', () => {
jest.resetAllMocks();
});

it('returns a message if the Android SDK is not installed', async () => {
environmentInfo.SDKs['Android SDK'] = 'Not Found';
const diagnostics = await androidNDK.getDiagnostics(environmentInfo);
expect(diagnostics.needsToBeFixed).toBe(true);
});

it('returns a message if the Android NDK is not installed', async () => {
// To avoid having to provide fake versions for all the Android SDK tools
// @ts-ignore
Expand Down
Loading