Skip to content

Commit 770f0c6

Browse files
committed
detect wrong dependencies
1 parent a7ee439 commit 770f0c6

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@ import path from 'path';
44
import semver from 'semver';
55
import {HealthCheckInterface} from '../../types';
66
import {logManualInstallation} from './common';
7-
import {findProjectRoot} from '@react-native-community/cli-tools';
7+
import {findProjectRoot, logger} from '@react-native-community/cli-tools';
88

99
const RNPackages = [
1010
'@react-native/babel-plugin-codegen',
1111
'@react-native/assets-registry',
12-
'@react-native/eslint-config',
1312
'@react-native/eslint-plugin-specs',
1413
'@react-native/hermes-inspector-msggen',
15-
'@react-native/metro-config',
1614
'@react-native/normalize-colors',
1715
'@react-native/js-polyfills',
1816
'@react-native/bots',
@@ -23,18 +21,21 @@ const RNPackages = [
2321
'@react-native/virtualized-lists',
2422
];
2523

26-
const getPackageJson = (root: string): Record<string, any> => {
24+
const getPackageJson = (root?: string): Record<string, any> => {
2725
try {
26+
root = root || findProjectRoot();
2827
const packageJson = JSON.parse(
2928
fs.readFileSync(path.join(root, 'package.json'), 'utf8'),
3029
);
3130
return packageJson;
3231
} catch (e) {
32+
logger.log(); // for extra space
33+
logger.error(`Couldn't find a "package.json" in ${root || process.cwd()}.`);
3334
return {};
3435
}
3536
};
3637

37-
const findDependencies = (root: string): Record<string, string> => {
38+
const findDependencies = (root?: string): Record<string, string> => {
3839
const {devDependencies = {}, dependencies = {}} = getPackageJson(root);
3940
return {
4041
...devDependencies,
@@ -48,8 +49,7 @@ export default {
4849
description: 'NPM dependencies needed for the project to work correctly',
4950
getDiagnostics: async (_, config) => {
5051
try {
51-
const root = config?.root || findProjectRoot();
52-
const dependencies = findDependencies(root);
52+
const dependencies = findDependencies(config?.root);
5353
const reactNativeVersion = dependencies['react-native'];
5454
const reactNativeCoercedVersion = semver.coerce(reactNativeVersion);
5555
const issues: string[] = [];
@@ -65,13 +65,13 @@ export default {
6565
);
6666
if (verisonDiff === 'major' || verisonDiff === 'minor') {
6767
issues.push(
68-
` - ${chalk.red.bold(
68+
` - ${chalk.red(
6969
'error',
7070
)} ${pkg}: "${packageVersion}" is not compatible with react-native: "${reactNativeVersion}"`,
7171
);
7272
} else {
7373
issues.push(
74-
` - ${chalk.yellow.bold(
74+
` - ${chalk.yellow(
7575
'warn',
7676
)} ${pkg} is part of React Native and should not be a dependency in your package.json`,
7777
);

0 commit comments

Comments
 (0)