From 75d84776d9b857f1b62f2f2e4a41a7eb7a279475 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Thu, 17 Sep 2020 16:03:49 +0200 Subject: [PATCH] bring warnings back --- .../src/commands/runAndroid/index.ts | 6 ++- .../src/link/warnAboutManuallyLinkedLibs.ts | 53 +++++++++++++++++++ .../platform-ios/src/commands/runIOS/index.ts | 2 + .../src/link/warnAboutManuallyLinkedLibs.ts | 53 +++++++++++++++++++ 4 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 packages/platform-android/src/link/warnAboutManuallyLinkedLibs.ts create mode 100644 packages/platform-ios/src/link/warnAboutManuallyLinkedLibs.ts diff --git a/packages/platform-android/src/commands/runAndroid/index.ts b/packages/platform-android/src/commands/runAndroid/index.ts index 612ebb612..aba543a02 100644 --- a/packages/platform-android/src/commands/runAndroid/index.ts +++ b/packages/platform-android/src/commands/runAndroid/index.ts @@ -21,9 +21,11 @@ import { getDefaultUserTerminal, CLIError, } from '@react-native-community/cli-tools'; +import warnAboutManuallyLinkedLibs from '../../link/warnAboutManuallyLinkedLibs'; import {getAndroidProject, getPackageName} from '../../utils/getAndroidProject'; -function displayWarnings(args: Flags) { +function displayWarnings(config: Config, args: Flags) { + warnAboutManuallyLinkedLibs(config); if (args.appFolder) { logger.warn( 'Using deprecated "--appFolder" flag. Use "project.android.appName" in react-native.config.js instead.', @@ -57,7 +59,7 @@ type AndroidProject = NonNullable; * Starts the app on a connected Android emulator or device. */ async function runAndroid(_argv: Array, config: Config, args: Flags) { - displayWarnings(args); + displayWarnings(config, args); const androidProject = getAndroidProject(config); if (args.jetifier) { diff --git a/packages/platform-android/src/link/warnAboutManuallyLinkedLibs.ts b/packages/platform-android/src/link/warnAboutManuallyLinkedLibs.ts new file mode 100644 index 000000000..a3c12b41e --- /dev/null +++ b/packages/platform-android/src/link/warnAboutManuallyLinkedLibs.ts @@ -0,0 +1,53 @@ +import chalk from 'chalk'; +import {logger} from '@react-native-community/cli-tools'; +import getLinkConfig from './index'; +import {Config} from '@react-native-community/cli-types'; + +// TODO: move to cli-tools once platform-ios and platform-android are migrated +// to TS and unify with iOS implementation +export default function warnAboutManuallyLinkedLibs( + config: Config, + platform: string = 'android', + linkConfig: ReturnType< + Config['platforms']['android']['linkConfig'] + > = getLinkConfig(), +) { + let deps: Array = []; + + for (let key in config.dependencies) { + const dependency = config.dependencies[key]; + const projectConfig = config.project[platform]; + try { + const dependencyConfig = dependency.platforms[platform]; + if (projectConfig && dependencyConfig) { + const x = linkConfig.isInstalled( + projectConfig, + dependency.name, + dependencyConfig, + ); + deps = deps.concat(x ? dependency.name : []); + } + } catch (error) { + logger.debug('Checking manually linked modules failed.', error); + } + } + + const installedModules = [...new Set(deps)]; + + if (installedModules.length) { + logger.error( + `React Native CLI uses autolinking for native dependencies, but the following modules are linked manually: \n${installedModules + .map( + (x) => + ` - ${chalk.bold(x)} ${chalk.dim( + `(to unlink run: "react-native unlink ${x}")`, + )}`, + ) + .join( + '\n', + )}\nThis is likely happening when upgrading React Native from below 0.60 to 0.60 or above. Going forward, you can unlink this dependency via "react-native unlink " and it will be included in your app automatically. If a library isn't compatible with autolinking, disregard this message and notify the library maintainers.\nRead more about autolinking: ${chalk.dim.underline( + 'https://github.com/react-native-community/cli/blob/master/docs/autolinking.md', + )}`, + ); + } +} diff --git a/packages/platform-ios/src/commands/runIOS/index.ts b/packages/platform-ios/src/commands/runIOS/index.ts index 8bff687c5..baebfd1c3 100644 --- a/packages/platform-ios/src/commands/runIOS/index.ts +++ b/packages/platform-ios/src/commands/runIOS/index.ts @@ -18,6 +18,7 @@ import {Config} from '@react-native-community/cli-types'; import findXcodeProject, {ProjectInfo} from './findXcodeProject'; import parseIOSDevicesList from './parseIOSDevicesList'; import findMatchingSimulator from './findMatchingSimulator'; +import warnAboutManuallyLinkedLibs from '../../link/warnAboutManuallyLinkedLibs'; import warnAboutPodInstall from '../../link/warnAboutPodInstall'; import { logger, @@ -47,6 +48,7 @@ function runIOS(_: Array, ctx: Config, args: FlagsT) { ); } + warnAboutManuallyLinkedLibs(ctx); warnAboutPodInstall(ctx); process.chdir(args.projectPath); diff --git a/packages/platform-ios/src/link/warnAboutManuallyLinkedLibs.ts b/packages/platform-ios/src/link/warnAboutManuallyLinkedLibs.ts new file mode 100644 index 000000000..d4eace0bd --- /dev/null +++ b/packages/platform-ios/src/link/warnAboutManuallyLinkedLibs.ts @@ -0,0 +1,53 @@ +import chalk from 'chalk'; +import {logger} from '@react-native-community/cli-tools'; +import {Config} from '@react-native-community/cli-types'; +import getLinkConfig from './index'; + +// TODO: move to cli-tools once platform-ios and platform-android are migrated +// to TS and unify with Android implementation +export default function warnAboutManuallyLinkedLibs( + config: Config, + platform: string = 'ios', + linkConfig: ReturnType< + Config['platforms']['ios']['linkConfig'] + > = getLinkConfig(), +) { + let deps: Array = []; + + for (let key in config.dependencies) { + const dependency = config.dependencies[key]; + const projectConfig = config.project[platform]; + try { + const dependencyConfig = dependency.platforms[platform]; + if (projectConfig && dependencyConfig) { + const x = linkConfig.isInstalled( + projectConfig, + dependency.name, + dependencyConfig, + ); + deps = deps.concat(x ? dependency.name : []); + } + } catch (error) { + logger.debug('Checking manually linked modules failed.', error); + } + } + + const installedModules = [...new Set(deps)]; + + if (installedModules.length) { + logger.error( + `React Native CLI uses autolinking for native dependencies, but the following modules are linked manually: \n${installedModules + .map( + (x) => + ` - ${chalk.bold(x)} ${chalk.dim( + `(to unlink run: "react-native unlink ${x}")`, + )}`, + ) + .join( + '\n', + )}\nThis is likely happening when upgrading React Native from below 0.60 to 0.60 or above. Going forward, you can unlink this dependency via "react-native unlink " and it will be included in your app automatically. If a library isn't compatible with autolinking, disregard this message and notify the library maintainers.\nRead more about autolinking: ${chalk.dim.underline( + 'https://github.com/react-native-community/cli/blob/master/docs/autolinking.md', + )}`, + ); + } +}