@@ -4,15 +4,13 @@ import path from 'path';
4
4
import semver from 'semver' ;
5
5
import { HealthCheckInterface } from '../../types' ;
6
6
import { logManualInstallation } from './common' ;
7
- import { findProjectRoot } from '@react-native-community/cli-tools' ;
7
+ import { findProjectRoot , logger } from '@react-native-community/cli-tools' ;
8
8
9
9
const RNPackages = [
10
10
'@react-native/babel-plugin-codegen' ,
11
11
'@react-native/assets-registry' ,
12
- '@react-native/eslint-config' ,
13
12
'@react-native/eslint-plugin-specs' ,
14
13
'@react-native/hermes-inspector-msggen' ,
15
- '@react-native/metro-config' ,
16
14
'@react-native/normalize-colors' ,
17
15
'@react-native/js-polyfills' ,
18
16
'@react-native/bots' ,
@@ -23,18 +21,21 @@ const RNPackages = [
23
21
'@react-native/virtualized-lists' ,
24
22
] ;
25
23
26
- const getPackageJson = ( root : string ) : Record < string , any > => {
24
+ const getPackageJson = ( root ? : string ) : Record < string , any > => {
27
25
try {
26
+ root = root || findProjectRoot ( ) ;
28
27
const packageJson = JSON . parse (
29
28
fs . readFileSync ( path . join ( root , 'package.json' ) , 'utf8' ) ,
30
29
) ;
31
30
return packageJson ;
32
31
} catch ( e ) {
32
+ logger . log ( ) ; // for extra space
33
+ logger . error ( `Couldn't find a "package.json" in ${ root || process . cwd ( ) } .` ) ;
33
34
return { } ;
34
35
}
35
36
} ;
36
37
37
- const findDependencies = ( root : string ) : Record < string , string > => {
38
+ const findDependencies = ( root ? : string ) : Record < string , string > => {
38
39
const { devDependencies = { } , dependencies = { } } = getPackageJson ( root ) ;
39
40
return {
40
41
...devDependencies ,
@@ -48,8 +49,7 @@ export default {
48
49
description : 'NPM dependencies needed for the project to work correctly' ,
49
50
getDiagnostics : async ( _ , config ) => {
50
51
try {
51
- const root = config ?. root || findProjectRoot ( ) ;
52
- const dependencies = findDependencies ( root ) ;
52
+ const dependencies = findDependencies ( config ?. root ) ;
53
53
const reactNativeVersion = dependencies [ 'react-native' ] ;
54
54
const reactNativeCoercedVersion = semver . coerce ( reactNativeVersion ) ;
55
55
const issues : string [ ] = [ ] ;
@@ -65,13 +65,13 @@ export default {
65
65
) ;
66
66
if ( verisonDiff === 'major' || verisonDiff === 'minor' ) {
67
67
issues . push (
68
- ` - ${ chalk . red . bold (
68
+ ` - ${ chalk . red (
69
69
'error' ,
70
70
) } ${ pkg } : "${ packageVersion } " is not compatible with react-native: "${ reactNativeVersion } "`,
71
71
) ;
72
72
} else {
73
73
issues . push (
74
- ` - ${ chalk . yellow . bold (
74
+ ` - ${ chalk . yellow (
75
75
'warn' ,
76
76
) } ${ pkg } is part of React Native and should not be a dependency in your package.json`,
77
77
) ;
0 commit comments