From 07d0d44392ee67411b05ebb7f60bc408cfbfff58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Kwas=CC=81niewski?= Date: Wed, 20 Dec 2023 16:32:32 +0100 Subject: [PATCH 1/5] feat: warn about multiple podfiles only if provided platform is unsupported --- .../src/commands/buildCommand/createBuild.ts | 1 + .../src/commands/buildCommand/getXcodeProjectAndDir.ts | 7 ++++++- .../src/commands/runCommand/createRun.ts | 1 + packages/cli-platform-apple/src/config/findPodfilePath.ts | 8 +++++++- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/cli-platform-apple/src/commands/buildCommand/createBuild.ts b/packages/cli-platform-apple/src/commands/buildCommand/createBuild.ts index 65adca423..1634f4d6f 100644 --- a/packages/cli-platform-apple/src/commands/buildCommand/createBuild.ts +++ b/packages/cli-platform-apple/src/commands/buildCommand/createBuild.ts @@ -36,6 +36,7 @@ const createBuild = let {xcodeProject, sourceDir} = getXcodeProjectAndDir( platform, + platformName, installedPods, ); diff --git a/packages/cli-platform-apple/src/commands/buildCommand/getXcodeProjectAndDir.ts b/packages/cli-platform-apple/src/commands/buildCommand/getXcodeProjectAndDir.ts index e59fdc406..bbf65f87c 100644 --- a/packages/cli-platform-apple/src/commands/buildCommand/getXcodeProjectAndDir.ts +++ b/packages/cli-platform-apple/src/commands/buildCommand/getXcodeProjectAndDir.ts @@ -2,14 +2,19 @@ import fs from 'fs'; import {IOSProjectConfig} from '@react-native-community/cli-types'; import {CLIError} from '@react-native-community/cli-tools'; import findXcodeProject from '../../config/findXcodeProject'; +import {getPlatformInfo} from '../runCommand/getPlatformInfo'; +import {ApplePlatform} from '../../types'; export function getXcodeProjectAndDir( iosProjectConfig: IOSProjectConfig | undefined, + platformName: ApplePlatform, installedPods?: boolean, ) { + const {readableName: platformReadableName} = getPlatformInfo(platformName); + if (!iosProjectConfig) { throw new CLIError( - 'iOS project folder not found. Are you sure this is a React Native project?', + `${platformReadableName} project folder not found. Make sure that project.${platformName}.sourceDir points to a directory with your Xcode project and that you are running this command inside of React Native project.`, ); } diff --git a/packages/cli-platform-apple/src/commands/runCommand/createRun.ts b/packages/cli-platform-apple/src/commands/runCommand/createRun.ts index 316f82bf5..32439b1cb 100644 --- a/packages/cli-platform-apple/src/commands/runCommand/createRun.ts +++ b/packages/cli-platform-apple/src/commands/runCommand/createRun.ts @@ -102,6 +102,7 @@ const createRun = let {xcodeProject, sourceDir} = getXcodeProjectAndDir( platform, + platformName, installedPods, ); diff --git a/packages/cli-platform-apple/src/config/findPodfilePath.ts b/packages/cli-platform-apple/src/config/findPodfilePath.ts index 55477e56b..e6149c4ec 100644 --- a/packages/cli-platform-apple/src/config/findPodfilePath.ts +++ b/packages/cli-platform-apple/src/config/findPodfilePath.ts @@ -10,6 +10,7 @@ import {inlineString, logger} from '@react-native-community/cli-tools'; import path from 'path'; import findAllPodfilePaths from './findAllPodfilePaths'; import {ApplePlatform} from '../types'; +import {supportedPlatforms} from './supportedPlatforms'; // Regexp matching all test projects const TEST_PROJECTS = /test|example|sample/i; @@ -50,8 +51,13 @@ export default function findPodfilePath( */ .sort((project) => (path.dirname(project) === platformName ? -1 : 1)); + const supportedPlatformsArray: string[] = Object.values(supportedPlatforms); + const containsOnlySupportedPodfiles = podfiles.every((podfile) => + supportedPlatformsArray.includes(podfile.split('/')[0]), + ); + if (podfiles.length > 0) { - if (podfiles.length > 1) { + if (podfiles.length > 1 && !containsOnlySupportedPodfiles) { logger.warn( inlineString(` Multiple Podfiles were found: ${podfiles}. Choosing ${podfiles[0]} automatically. From 4eaea89c8adf0018f7692f5911bcadd951bcea5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Kwas=CC=81niewski?= Date: Thu, 21 Dec 2023 13:28:29 +0100 Subject: [PATCH 2/5] refactor: rename platform to platformConfig --- .../src/commands/buildCommand/createBuild.ts | 14 +++++++------- .../src/commands/logCommand/createLog.ts | 6 +++--- .../src/commands/runCommand/createRun.ts | 12 ++++++------ 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/packages/cli-platform-apple/src/commands/buildCommand/createBuild.ts b/packages/cli-platform-apple/src/commands/buildCommand/createBuild.ts index 1634f4d6f..d56af3a51 100644 --- a/packages/cli-platform-apple/src/commands/buildCommand/createBuild.ts +++ b/packages/cli-platform-apple/src/commands/buildCommand/createBuild.ts @@ -12,18 +12,18 @@ import {supportedPlatforms} from '../../config/supportedPlatforms'; const createBuild = ({platformName}: BuilderCommand) => async (_: Array, ctx: Config, args: BuildFlags) => { - const platform = ctx.project[platformName] as IOSProjectConfig; + const platformConfig = ctx.project[platformName] as IOSProjectConfig; if ( - platform === undefined || + platformConfig === undefined || supportedPlatforms[platformName] === undefined ) { - throw new CLIError(`Unable to find ${platform} platform config`); + throw new CLIError(`Unable to find ${platformConfig} platform config`); } let installedPods = false; - if (platform?.automaticPodsInstallation || args.forcePods) { - const isAppRunningNewArchitecture = platform?.sourceDir - ? await getArchitecture(platform?.sourceDir) + if (platformConfig?.automaticPodsInstallation || args.forcePods) { + const isAppRunningNewArchitecture = platformConfig?.sourceDir + ? await getArchitecture(platformConfig?.sourceDir) : undefined; await resolvePods(ctx.root, ctx.dependencies, platformName, { @@ -35,7 +35,7 @@ const createBuild = } let {xcodeProject, sourceDir} = getXcodeProjectAndDir( - platform, + platformConfig, platformName, installedPods, ); diff --git a/packages/cli-platform-apple/src/commands/logCommand/createLog.ts b/packages/cli-platform-apple/src/commands/logCommand/createLog.ts index 6d1f6763a..68c73e66f 100644 --- a/packages/cli-platform-apple/src/commands/logCommand/createLog.ts +++ b/packages/cli-platform-apple/src/commands/logCommand/createLog.ts @@ -20,14 +20,14 @@ type Args = { const createLog = ({platformName}: BuilderCommand) => async (_: Array, ctx: Config, args: Args) => { - const platform = ctx.project[platformName] as IOSProjectConfig; + const platformConfig = ctx.project[platformName] as IOSProjectConfig; const {readableName: platformReadableName} = getPlatformInfo(platformName); if ( - platform === undefined || + platformConfig === undefined || supportedPlatforms[platformName] === undefined ) { - throw new CLIError(`Unable to find ${platform} platform config`); + throw new CLIError(`Unable to find ${platformConfig} platform config`); } // Here we're using two command because first command `xcrun simctl list --json devices` outputs `state` but doesn't return `available`. But second command `xcrun xcdevice list` outputs `available` but doesn't output `state`. So we need to connect outputs of both commands. diff --git a/packages/cli-platform-apple/src/commands/runCommand/createRun.ts b/packages/cli-platform-apple/src/commands/runCommand/createRun.ts index 32439b1cb..90b9f2e58 100644 --- a/packages/cli-platform-apple/src/commands/runCommand/createRun.ts +++ b/packages/cli-platform-apple/src/commands/runCommand/createRun.ts @@ -51,12 +51,12 @@ const createRun = async (_: Array, ctx: Config, args: FlagsT) => { // React Native docs assume platform is always ios/android link.setPlatform('ios'); - const platform = ctx.project[platformName] as IOSProjectConfig; + const platformConfig = ctx.project[platformName] as IOSProjectConfig; const {sdkNames, readableName: platformReadableName} = getPlatformInfo(platformName); if ( - platform === undefined || + platformConfig === undefined || supportedPlatforms[platformName] === undefined ) { throw new CLIError( @@ -67,9 +67,9 @@ const createRun = let {packager, port} = args; let installedPods = false; // check if pods need to be installed - if (platform?.automaticPodsInstallation || args.forcePods) { - const isAppRunningNewArchitecture = platform?.sourceDir - ? await getArchitecture(platform?.sourceDir) + if (platformConfig?.automaticPodsInstallation || args.forcePods) { + const isAppRunningNewArchitecture = platformConfig?.sourceDir + ? await getArchitecture(platformConfig?.sourceDir) : undefined; await resolvePods(ctx.root, ctx.dependencies, platformName, { @@ -101,7 +101,7 @@ const createRun = } let {xcodeProject, sourceDir} = getXcodeProjectAndDir( - platform, + platformConfig, platformName, installedPods, ); From 064de9dc3f260bc8e60c366951ef38ed5e0a5ed0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Kwas=CC=81niewski?= Date: Thu, 21 Dec 2023 13:28:42 +0100 Subject: [PATCH 3/5] fix: avoid negation use containsUnsupportedPodfiles --- packages/cli-platform-apple/src/config/findPodfilePath.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/cli-platform-apple/src/config/findPodfilePath.ts b/packages/cli-platform-apple/src/config/findPodfilePath.ts index e6149c4ec..b4330063e 100644 --- a/packages/cli-platform-apple/src/config/findPodfilePath.ts +++ b/packages/cli-platform-apple/src/config/findPodfilePath.ts @@ -52,12 +52,12 @@ export default function findPodfilePath( .sort((project) => (path.dirname(project) === platformName ? -1 : 1)); const supportedPlatformsArray: string[] = Object.values(supportedPlatforms); - const containsOnlySupportedPodfiles = podfiles.every((podfile) => - supportedPlatformsArray.includes(podfile.split('/')[0]), + const containsUnsupportedPodfiles = podfiles.every( + (podfile) => !supportedPlatformsArray.includes(podfile.split('/')[0]), ); if (podfiles.length > 0) { - if (podfiles.length > 1 && !containsOnlySupportedPodfiles) { + if (podfiles.length > 1 && containsUnsupportedPodfiles) { logger.warn( inlineString(` Multiple Podfiles were found: ${podfiles}. Choosing ${podfiles[0]} automatically. From 13b3c612aafd43cdb06caf39aec51b6701617d78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Kwa=C5=9Bniewski?= Date: Thu, 21 Dec 2023 17:24:19 +0100 Subject: [PATCH 4/5] Update createBuild.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Michał Pierzchała --- .../cli-platform-apple/src/commands/buildCommand/createBuild.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli-platform-apple/src/commands/buildCommand/createBuild.ts b/packages/cli-platform-apple/src/commands/buildCommand/createBuild.ts index d56af3a51..8706ca674 100644 --- a/packages/cli-platform-apple/src/commands/buildCommand/createBuild.ts +++ b/packages/cli-platform-apple/src/commands/buildCommand/createBuild.ts @@ -17,7 +17,7 @@ const createBuild = platformConfig === undefined || supportedPlatforms[platformName] === undefined ) { - throw new CLIError(`Unable to find ${platformConfig} platform config`); + throw new CLIError(`Unable to find ${platformName} platform config`); } let installedPods = false; From 22b4124b977a191a779d4660c0b96a9fa1ab2b01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Kwa=C5=9Bniewski?= Date: Thu, 21 Dec 2023 17:28:03 +0100 Subject: [PATCH 5/5] Update createLog.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Michał Pierzchała --- .../cli-platform-apple/src/commands/logCommand/createLog.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli-platform-apple/src/commands/logCommand/createLog.ts b/packages/cli-platform-apple/src/commands/logCommand/createLog.ts index 68c73e66f..7a5555ff3 100644 --- a/packages/cli-platform-apple/src/commands/logCommand/createLog.ts +++ b/packages/cli-platform-apple/src/commands/logCommand/createLog.ts @@ -27,7 +27,7 @@ const createLog = platformConfig === undefined || supportedPlatforms[platformName] === undefined ) { - throw new CLIError(`Unable to find ${platformConfig} platform config`); + throw new CLIError(`Unable to find ${platformName} platform config`); } // Here we're using two command because first command `xcrun simctl list --json devices` outputs `state` but doesn't return `available`. But second command `xcrun xcdevice list` outputs `available` but doesn't output `state`. So we need to connect outputs of both commands.