Skip to content

Commit

Permalink
feat: warn about multiple podfiles only if provided platform is unsup…
Browse files Browse the repository at this point in the history
…ported (#2223)

* feat: warn about multiple podfiles only if provided platform is unsupported

* refactor: rename platform to platformConfig

* fix: avoid negation use containsUnsupportedPodfiles

* Update createBuild.ts

Co-authored-by: Michał Pierzchała <[email protected]>

* Update createLog.ts

Co-authored-by: Michał Pierzchała <[email protected]>

---------

Co-authored-by: Michał Pierzchała <[email protected]>
  • Loading branch information
okwasniewski and thymikee authored Dec 21, 2023
1 parent bcdfcd7 commit 043c831
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ import {supportedPlatforms} from '../../config/supportedPlatforms';
const createBuild =
({platformName}: BuilderCommand) =>
async (_: Array<string>, 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 ${platformName} 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, {
Expand All @@ -35,7 +35,8 @@ const createBuild =
}

let {xcodeProject, sourceDir} = getXcodeProjectAndDir(
platform,
platformConfig,
platformName,
installedPods,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.`,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ type Args = {
const createLog =
({platformName}: BuilderCommand) =>
async (_: Array<string>, 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 ${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.
Expand Down
13 changes: 7 additions & 6 deletions packages/cli-platform-apple/src/commands/runCommand/createRun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ const createRun =
async (_: Array<string>, 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(
Expand All @@ -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, {
Expand Down Expand Up @@ -101,7 +101,8 @@ const createRun =
}

let {xcodeProject, sourceDir} = getXcodeProjectAndDir(
platform,
platformConfig,
platformName,
installedPods,
);

Expand Down
8 changes: 7 additions & 1 deletion packages/cli-platform-apple/src/config/findPodfilePath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -50,8 +51,13 @@ export default function findPodfilePath(
*/
.sort((project) => (path.dirname(project) === platformName ? -1 : 1));

const supportedPlatformsArray: string[] = Object.values(supportedPlatforms);
const containsUnsupportedPodfiles = podfiles.every(
(podfile) => !supportedPlatformsArray.includes(podfile.split('/')[0]),
);

if (podfiles.length > 0) {
if (podfiles.length > 1) {
if (podfiles.length > 1 && containsUnsupportedPodfiles) {
logger.warn(
inlineString(`
Multiple Podfiles were found: ${podfiles}. Choosing ${podfiles[0]} automatically.
Expand Down

0 comments on commit 043c831

Please sign in to comment.