Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
okwasniewski marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -20,14 +20,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
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
Loading