Skip to content

Commit

Permalink
detect cli internal packages in dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
tarunrajput committed Jul 25, 2023
1 parent ecc76f4 commit d308daa
Showing 1 changed file with 58 additions and 1 deletion.
59 changes: 58 additions & 1 deletion packages/cli-doctor/src/tools/healthchecks/dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,30 @@ const RNPackages = [
'@react-native/codegen-typescript-test',
'@react-native/codegen',
'@react-native/gradle-plugin',
'@react-native/typescript-config',
'@react-native/virtualized-lists',
];

const cliPackages = [
'@react-native-community/cli',
'@react-native-community/cli-platform-android',
'@react-native-community/cli-platform-ios',
'@react-native-community/cli-tools',
'@react-native-community/cli-doctor',
'@react-native-community/cli-hermes',
'@react-native-community/cli-plugin-metro',
'@react-native-community/cli-clean',
'@react-native-community/cli-config',
'@react-native-community/cli-debugger-ui',
'@react-native-community/cli-server-api',
'@react-native-community/cli-types',
];

const reactNativeCliCompatiblityMatrix = {
12: ['0.73'],
11: ['0.72'],
10: ['0.71'],
};

const getPackageJson = (root?: string): Record<string, any> => {
try {
root = root || findProjectRoot();
Expand Down Expand Up @@ -79,6 +99,43 @@ export default {
}
}
});

if (dependencies['react-native-cli']) {
issues.push(
` - ${chalk.red(
'error',
)} react-native-cli is legacy and should not be listed as a dependency in your package.json`,
);
}

cliPackages.forEach((pkg) => {
if (dependencies[pkg]) {
const packageVersion = dependencies[pkg];
const packageMajorVersion = semver.coerce(packageVersion)?.major;
const RNVersion = `${reactNativeCoercedVersion?.major}.${reactNativeCoercedVersion?.minor}`;

if (packageMajorVersion) {
const compatibleRNVersions =
reactNativeCliCompatiblityMatrix[
packageMajorVersion as keyof typeof reactNativeCliCompatiblityMatrix
] || [];
if (!compatibleRNVersions.includes(RNVersion)) {
issues.push(
` - ${chalk.red(
'error',
)} ${pkg}: "${packageVersion}" is not compatible with react-native: "${reactNativeVersion}"`,
);
} else {
issues.push(
` - ${chalk.yellow(
'warn',
)} ${pkg} comes included with React Native and should not be listed as a dependency in your package.json`,
);
}
}
}
});

if (issues.length) {
issues.unshift('There are some issues with your project dependencies');
return {
Expand Down

0 comments on commit d308daa

Please sign in to comment.