From bb126281615c80aeb95b0255e7f265c33373eae9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Thu, 17 Sep 2020 14:50:28 +0200 Subject: [PATCH 1/5] fix: pass Android manifest parse errors through; remove manual link warnings --- packages/cli/src/index.ts | 15 +++--- .../src/commands/runAndroid/index.ts | 6 +-- .../src/config/readManifest.ts | 11 +++- .../src/link/warnAboutManuallyLinkedLibs.ts | 53 ------------------- .../platform-ios/src/commands/runIOS/index.ts | 2 - .../src/link/warnAboutManuallyLinkedLibs.ts | 53 ------------------- 6 files changed, 20 insertions(+), 120 deletions(-) delete mode 100644 packages/platform-android/src/link/warnAboutManuallyLinkedLibs.ts delete mode 100644 packages/platform-ios/src/link/warnAboutManuallyLinkedLibs.ts diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts index 5436845ff..127d51ac4 100644 --- a/packages/cli/src/index.ts +++ b/packages/cli/src/index.ts @@ -31,17 +31,20 @@ const handleError = (err: Error) => { } else { // Some error messages (esp. custom ones) might have `.` at the end already. const message = err.message.replace(/\.$/, ''); - logger.error( - `${message}. ${chalk.dim( + logger.error(`${message}.`); + } + if (err.stack) { + logger.log(err.stack); + } + if (!commander.verbose) { + logger.info( + chalk.dim( `Run CLI with ${chalk.reset('--verbose')} ${chalk.dim( 'flag for more details.', )}`, - )}`, + ), ); } - if (err.stack) { - logger.log(chalk.dim(err.stack)); - } process.exit(1); }; diff --git a/packages/platform-android/src/commands/runAndroid/index.ts b/packages/platform-android/src/commands/runAndroid/index.ts index aba543a02..612ebb612 100644 --- a/packages/platform-android/src/commands/runAndroid/index.ts +++ b/packages/platform-android/src/commands/runAndroid/index.ts @@ -21,11 +21,9 @@ import { getDefaultUserTerminal, CLIError, } from '@react-native-community/cli-tools'; -import warnAboutManuallyLinkedLibs from '../../link/warnAboutManuallyLinkedLibs'; import {getAndroidProject, getPackageName} from '../../utils/getAndroidProject'; -function displayWarnings(config: Config, args: Flags) { - warnAboutManuallyLinkedLibs(config); +function displayWarnings(args: Flags) { if (args.appFolder) { logger.warn( 'Using deprecated "--appFolder" flag. Use "project.android.appName" in react-native.config.js instead.', @@ -59,7 +57,7 @@ type AndroidProject = NonNullable; * Starts the app on a connected Android emulator or device. */ async function runAndroid(_argv: Array, config: Config, args: Flags) { - displayWarnings(config, args); + displayWarnings(args); const androidProject = getAndroidProject(config); if (args.jetifier) { diff --git a/packages/platform-android/src/config/readManifest.ts b/packages/platform-android/src/config/readManifest.ts index 452e55ae7..0e69f21e9 100644 --- a/packages/platform-android/src/config/readManifest.ts +++ b/packages/platform-android/src/config/readManifest.ts @@ -5,10 +5,17 @@ * LICENSE file in the root directory of this source tree. * */ - import fs from 'fs'; import xml from 'xmldoc'; +import {CLIError} from '@react-native-community/cli-tools'; export default function readManifest(manifestPath: string) { - return new xml.XmlDocument(fs.readFileSync(manifestPath, 'utf8')); + try { + return new xml.XmlDocument(fs.readFileSync(manifestPath, 'utf8')); + } catch (error) { + throw new CLIError( + `Failed to parse Android Manifest file at ${manifestPath}`, + error, + ); + } } diff --git a/packages/platform-android/src/link/warnAboutManuallyLinkedLibs.ts b/packages/platform-android/src/link/warnAboutManuallyLinkedLibs.ts deleted file mode 100644 index 3dbbc1106..000000000 --- a/packages/platform-android/src/link/warnAboutManuallyLinkedLibs.ts +++ /dev/null @@ -1,53 +0,0 @@ -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]; - try { - const projectConfig = config.project[platform]; - 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 baebfd1c3..8bff687c5 100644 --- a/packages/platform-ios/src/commands/runIOS/index.ts +++ b/packages/platform-ios/src/commands/runIOS/index.ts @@ -18,7 +18,6 @@ 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, @@ -48,7 +47,6 @@ 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 deleted file mode 100644 index c228b07fb..000000000 --- a/packages/platform-ios/src/link/warnAboutManuallyLinkedLibs.ts +++ /dev/null @@ -1,53 +0,0 @@ -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]; - try { - const projectConfig = config.project[platform]; - 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', - )}`, - ); - } -} 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 2/5] 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', + )}`, + ); + } +} From 63b7d47706ea98646ff9c1087854cc5460327521 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Thu, 17 Sep 2020 16:07:59 +0200 Subject: [PATCH 3/5] fix prettier --- packages/cli/src/commands/init/templateName.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli/src/commands/init/templateName.ts b/packages/cli/src/commands/init/templateName.ts index b0a7a2b98..e013d09f7 100644 --- a/packages/cli/src/commands/init/templateName.ts +++ b/packages/cli/src/commands/init/templateName.ts @@ -95,7 +95,7 @@ export function processTemplateName(templateName: string) { return handleVersionedPackage(templateName); } if ( - !['github', '@'].some(str => templateName.includes(str)) && + !['github', '@'].some((str) => templateName.includes(str)) && templateName.includes('/') ) { return handleGitHubRepo(templateName); From 3a46d9d629615b543c3ff8bb0ea57b3175a36173 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Thu, 17 Sep 2020 16:16:04 +0200 Subject: [PATCH 4/5] remove try/catch; move projectConfig retrieval outside of for loop --- .../src/link/warnAboutManuallyLinkedLibs.ts | 25 +++++++++---------- .../src/link/warnAboutManuallyLinkedLibs.ts | 25 +++++++++---------- 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/packages/platform-android/src/link/warnAboutManuallyLinkedLibs.ts b/packages/platform-android/src/link/warnAboutManuallyLinkedLibs.ts index a3c12b41e..26dad89b8 100644 --- a/packages/platform-android/src/link/warnAboutManuallyLinkedLibs.ts +++ b/packages/platform-android/src/link/warnAboutManuallyLinkedLibs.ts @@ -13,23 +13,22 @@ export default function warnAboutManuallyLinkedLibs( > = getLinkConfig(), ) { let deps: Array = []; + const projectConfig = config.project[platform]; 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 dependencyConfig = dependency.platforms[platform]; + if (projectConfig && dependencyConfig) { + const x = linkConfig.isInstalled( + projectConfig, + dependency.name, + dependencyConfig, + ); + deps = deps.concat(x ? dependency.name : []); } + + logger.debug('Checking manually linked modules failed.'); } const installedModules = [...new Set(deps)]; diff --git a/packages/platform-ios/src/link/warnAboutManuallyLinkedLibs.ts b/packages/platform-ios/src/link/warnAboutManuallyLinkedLibs.ts index d4eace0bd..a9ab2a2a0 100644 --- a/packages/platform-ios/src/link/warnAboutManuallyLinkedLibs.ts +++ b/packages/platform-ios/src/link/warnAboutManuallyLinkedLibs.ts @@ -13,23 +13,22 @@ export default function warnAboutManuallyLinkedLibs( > = getLinkConfig(), ) { let deps: Array = []; + const projectConfig = config.project[platform]; 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 dependencyConfig = dependency.platforms[platform]; + if (projectConfig && dependencyConfig) { + const x = linkConfig.isInstalled( + projectConfig, + dependency.name, + dependencyConfig, + ); + deps = deps.concat(x ? dependency.name : []); } + + logger.debug('Checking manually linked modules failed.'); } const installedModules = [...new Set(deps)]; From 3111a00e48bddad77311be41fd8b3b297f01fef1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Thu, 17 Sep 2020 16:17:48 +0200 Subject: [PATCH 5/5] remove debug logs --- .../platform-android/src/link/warnAboutManuallyLinkedLibs.ts | 2 -- packages/platform-ios/src/link/warnAboutManuallyLinkedLibs.ts | 2 -- 2 files changed, 4 deletions(-) diff --git a/packages/platform-android/src/link/warnAboutManuallyLinkedLibs.ts b/packages/platform-android/src/link/warnAboutManuallyLinkedLibs.ts index 26dad89b8..28badad2d 100644 --- a/packages/platform-android/src/link/warnAboutManuallyLinkedLibs.ts +++ b/packages/platform-android/src/link/warnAboutManuallyLinkedLibs.ts @@ -27,8 +27,6 @@ export default function warnAboutManuallyLinkedLibs( ); deps = deps.concat(x ? dependency.name : []); } - - logger.debug('Checking manually linked modules failed.'); } const installedModules = [...new Set(deps)]; diff --git a/packages/platform-ios/src/link/warnAboutManuallyLinkedLibs.ts b/packages/platform-ios/src/link/warnAboutManuallyLinkedLibs.ts index a9ab2a2a0..9aac5d0d8 100644 --- a/packages/platform-ios/src/link/warnAboutManuallyLinkedLibs.ts +++ b/packages/platform-ios/src/link/warnAboutManuallyLinkedLibs.ts @@ -27,8 +27,6 @@ export default function warnAboutManuallyLinkedLibs( ); deps = deps.concat(x ? dependency.name : []); } - - logger.debug('Checking manually linked modules failed.'); } const installedModules = [...new Set(deps)];