Skip to content

Commit 043c831

Browse files
feat: warn about multiple podfiles only if provided platform is unsupported (#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]>
1 parent bcdfcd7 commit 043c831

File tree

5 files changed

+31
-18
lines changed

5 files changed

+31
-18
lines changed

packages/cli-platform-apple/src/commands/buildCommand/createBuild.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ import {supportedPlatforms} from '../../config/supportedPlatforms';
1212
const createBuild =
1313
({platformName}: BuilderCommand) =>
1414
async (_: Array<string>, ctx: Config, args: BuildFlags) => {
15-
const platform = ctx.project[platformName] as IOSProjectConfig;
15+
const platformConfig = ctx.project[platformName] as IOSProjectConfig;
1616
if (
17-
platform === undefined ||
17+
platformConfig === undefined ||
1818
supportedPlatforms[platformName] === undefined
1919
) {
20-
throw new CLIError(`Unable to find ${platform} platform config`);
20+
throw new CLIError(`Unable to find ${platformName} platform config`);
2121
}
2222

2323
let installedPods = false;
24-
if (platform?.automaticPodsInstallation || args.forcePods) {
25-
const isAppRunningNewArchitecture = platform?.sourceDir
26-
? await getArchitecture(platform?.sourceDir)
24+
if (platformConfig?.automaticPodsInstallation || args.forcePods) {
25+
const isAppRunningNewArchitecture = platformConfig?.sourceDir
26+
? await getArchitecture(platformConfig?.sourceDir)
2727
: undefined;
2828

2929
await resolvePods(ctx.root, ctx.dependencies, platformName, {
@@ -35,7 +35,8 @@ const createBuild =
3535
}
3636

3737
let {xcodeProject, sourceDir} = getXcodeProjectAndDir(
38-
platform,
38+
platformConfig,
39+
platformName,
3940
installedPods,
4041
);
4142

packages/cli-platform-apple/src/commands/buildCommand/getXcodeProjectAndDir.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,19 @@ import fs from 'fs';
22
import {IOSProjectConfig} from '@react-native-community/cli-types';
33
import {CLIError} from '@react-native-community/cli-tools';
44
import findXcodeProject from '../../config/findXcodeProject';
5+
import {getPlatformInfo} from '../runCommand/getPlatformInfo';
6+
import {ApplePlatform} from '../../types';
57

68
export function getXcodeProjectAndDir(
79
iosProjectConfig: IOSProjectConfig | undefined,
10+
platformName: ApplePlatform,
811
installedPods?: boolean,
912
) {
13+
const {readableName: platformReadableName} = getPlatformInfo(platformName);
14+
1015
if (!iosProjectConfig) {
1116
throw new CLIError(
12-
'iOS project folder not found. Are you sure this is a React Native project?',
17+
`${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.`,
1318
);
1419
}
1520

packages/cli-platform-apple/src/commands/logCommand/createLog.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ type Args = {
2121
const createLog =
2222
({platformName}: BuilderCommand) =>
2323
async (_: Array<string>, ctx: Config, args: Args) => {
24-
const platform = ctx.project[platformName] as IOSProjectConfig;
24+
const platformConfig = ctx.project[platformName] as IOSProjectConfig;
2525
const {readableName: platformReadableName} = getPlatformInfo(platformName);
2626

2727
if (
28-
platform === undefined ||
28+
platformConfig === undefined ||
2929
supportedPlatforms[platformName] === undefined
3030
) {
31-
throw new CLIError(`Unable to find ${platform} platform config`);
31+
throw new CLIError(`Unable to find ${platformName} platform config`);
3232
}
3333

3434
// 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.

packages/cli-platform-apple/src/commands/runCommand/createRun.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ const createRun =
5151
async (_: Array<string>, ctx: Config, args: FlagsT) => {
5252
// React Native docs assume platform is always ios/android
5353
link.setPlatform('ios');
54-
const platform = ctx.project[platformName] as IOSProjectConfig;
54+
const platformConfig = ctx.project[platformName] as IOSProjectConfig;
5555
const {sdkNames, readableName: platformReadableName} =
5656
getPlatformInfo(platformName);
5757

5858
if (
59-
platform === undefined ||
59+
platformConfig === undefined ||
6060
supportedPlatforms[platformName] === undefined
6161
) {
6262
throw new CLIError(
@@ -67,9 +67,9 @@ const createRun =
6767
let {packager, port} = args;
6868
let installedPods = false;
6969
// check if pods need to be installed
70-
if (platform?.automaticPodsInstallation || args.forcePods) {
71-
const isAppRunningNewArchitecture = platform?.sourceDir
72-
? await getArchitecture(platform?.sourceDir)
70+
if (platformConfig?.automaticPodsInstallation || args.forcePods) {
71+
const isAppRunningNewArchitecture = platformConfig?.sourceDir
72+
? await getArchitecture(platformConfig?.sourceDir)
7373
: undefined;
7474

7575
await resolvePods(ctx.root, ctx.dependencies, platformName, {
@@ -101,7 +101,8 @@ const createRun =
101101
}
102102

103103
let {xcodeProject, sourceDir} = getXcodeProjectAndDir(
104-
platform,
104+
platformConfig,
105+
platformName,
105106
installedPods,
106107
);
107108

packages/cli-platform-apple/src/config/findPodfilePath.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {inlineString, logger} from '@react-native-community/cli-tools';
1010
import path from 'path';
1111
import findAllPodfilePaths from './findAllPodfilePaths';
1212
import {ApplePlatform} from '../types';
13+
import {supportedPlatforms} from './supportedPlatforms';
1314

1415
// Regexp matching all test projects
1516
const TEST_PROJECTS = /test|example|sample/i;
@@ -50,8 +51,13 @@ export default function findPodfilePath(
5051
*/
5152
.sort((project) => (path.dirname(project) === platformName ? -1 : 1));
5253

54+
const supportedPlatformsArray: string[] = Object.values(supportedPlatforms);
55+
const containsUnsupportedPodfiles = podfiles.every(
56+
(podfile) => !supportedPlatformsArray.includes(podfile.split('/')[0]),
57+
);
58+
5359
if (podfiles.length > 0) {
54-
if (podfiles.length > 1) {
60+
if (podfiles.length > 1 && containsUnsupportedPodfiles) {
5561
logger.warn(
5662
inlineString(`
5763
Multiple Podfiles were found: ${podfiles}. Choosing ${podfiles[0]} automatically.

0 commit comments

Comments
 (0)