Skip to content

Commit 0296d31

Browse files
authored
fix(ios): fix crash when --mode is specified (#1958)
Assumptions about where the `.xcodeproj` lives causes `checkIfConfigurationExists` to crash because `undefined` was passed as project.
1 parent 0791509 commit 0296d31

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

packages/cli-platform-ios/src/tools/__tests__/checkIfConfigurationExists.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type {IosProjectInfo} from '../../types';
12
import {checkIfConfigurationExists} from '../checkIfConfigurationExists';
23

34
const CONFIGURATIONS = ['Debug', 'Release'];
@@ -26,4 +27,11 @@ describe('checkIfConfigurationExists', () => {
2627

2728
expect(checkConfig).not.toThrow();
2829
});
30+
31+
test('should not throw an error if project could not be found', () => {
32+
const checkConfig = () =>
33+
checkIfConfigurationExists(undefined as IosProjectInfo, 'Debug');
34+
35+
expect(checkConfig).not.toThrow();
36+
});
2937
});

packages/cli-platform-ios/src/tools/checkIfConfigurationExists.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
import {CLIError} from '@react-native-community/cli-tools';
1+
import {CLIError, logger} from '@react-native-community/cli-tools';
22
import {IosProjectInfo} from '../types';
33

44
export function checkIfConfigurationExists(
55
project: IosProjectInfo,
66
mode: string,
77
) {
8+
if (!project) {
9+
logger.warn(`Unable to check whether "${mode}" exists in your project`);
10+
return;
11+
}
12+
813
if (!project.configurations.includes(mode)) {
914
throw new CLIError(
1015
`Configuration "${mode}" does not exist in your project. Please use one of the existing configurations: ${project.configurations.join(

0 commit comments

Comments
 (0)