From 1e8769cc025634927fd8fdfced345dbe74fc0364 Mon Sep 17 00:00:00 2001 From: Bartosz Kaszubowski Date: Wed, 9 Aug 2023 17:17:53 +0200 Subject: [PATCH] [pod-install] show alternative message in managed projects (#4566) Co-authored-by: Brent Vatne --- packages/expo-doctor/src/doctor.ts | 2 +- packages/pod-install/package.json | 1 + packages/pod-install/src/index.ts | 26 +++++++++++++++++++++----- packages/pod-install/src/utils.ts | 12 ++++++++++++ 4 files changed, 35 insertions(+), 6 deletions(-) create mode 100644 packages/pod-install/src/utils.ts diff --git a/packages/expo-doctor/src/doctor.ts b/packages/expo-doctor/src/doctor.ts index 3ad006a230..25a6264fa0 100644 --- a/packages/expo-doctor/src/doctor.ts +++ b/packages/expo-doctor/src/doctor.ts @@ -2,8 +2,8 @@ import { getConfig } from '@expo/config'; import chalk from 'chalk'; import semver from 'semver'; -import { ExpoConfigCommonIssueCheck } from './checks/ExpoConfigCommonIssueCheck'; import { DirectPackageInstallCheck } from './checks/DirectPackageInstallCheck'; +import { ExpoConfigCommonIssueCheck } from './checks/ExpoConfigCommonIssueCheck'; import { ExpoConfigSchemaCheck } from './checks/ExpoConfigSchemaCheck'; import { GlobalPackageInstalledCheck } from './checks/GlobalPackageInstalledCheck'; import { GlobalPrereqsVersionCheck } from './checks/GlobalPrereqsVersionCheck'; diff --git a/packages/pod-install/package.json b/packages/pod-install/package.json index eaf3bb4972..13a5e108a6 100644 --- a/packages/pod-install/package.json +++ b/packages/pod-install/package.json @@ -35,6 +35,7 @@ "@expo/package-manager": "0.0.56", "chalk": "^4.0.0", "commander": "2.20.0", + "terminal-link": "^2.1.1", "update-check": "1.5.3" } } diff --git a/packages/pod-install/src/index.ts b/packages/pod-install/src/index.ts index 2b44e3ec96..85b08873cb 100644 --- a/packages/pod-install/src/index.ts +++ b/packages/pod-install/src/index.ts @@ -3,9 +3,11 @@ import { CocoaPodsPackageManager } from '@expo/package-manager/build/CocoaPodsPackageManager'; import chalk from 'chalk'; import { Command } from 'commander'; -import { resolve } from 'path'; +import { existsSync, readFileSync } from 'fs'; +import { join, resolve } from 'path'; import shouldUpdate from './update'; +import { learnMore } from './utils'; const packageJSON = require('../package.json'); @@ -29,10 +31,7 @@ const info = (message: string) => { }; async function runAsync(): Promise { - if (typeof projectRoot === 'string') { - projectRoot = projectRoot.trim(); - } - projectRoot = resolve(projectRoot); + projectRoot = resolve(projectRoot.trim()); if (process.platform !== 'darwin') { info(chalk.red('CocoaPods is only supported on darwin machines')); @@ -41,6 +40,23 @@ async function runAsync(): Promise { const possibleProjectRoot = CocoaPodsPackageManager.getPodProjectRoot(projectRoot); if (!possibleProjectRoot) { + const packageJsonPath = join(projectRoot, 'package.json'); + + if (existsSync(packageJsonPath)) { + const jsonData = JSON.parse(readFileSync(packageJsonPath).toString()); + const hasExpoPackage = jsonData.dependencies?.hasOwnProperty('expo'); + + if (hasExpoPackage) { + info( + chalk.yellow( + `No 'ios' directory found, skipping installing pods. Pods will be automatically installed when the 'ios' directory is generated with 'npx expo prebuild' or 'npx expo run:ios'.`, + learnMore('https://docs.expo.dev/workflow/prebuild/') + ) + ); + return; + } + } + info(chalk.yellow('CocoaPods is not supported in this project')); return; } else { diff --git a/packages/pod-install/src/utils.ts b/packages/pod-install/src/utils.ts new file mode 100644 index 0000000000..1ce17ffb94 --- /dev/null +++ b/packages/pod-install/src/utils.ts @@ -0,0 +1,12 @@ +import chalk from 'chalk'; +import terminalLink from 'terminal-link'; + +/** + * When linking isn't available, format the learn more link better. + * @param url + */ +export function learnMore(url: string): string { + return terminalLink(chalk.underline('Learn more.'), url, { + fallback: (_, url) => `Learn more: ${chalk.underline(url)}`, + }); +}