Skip to content

Commit 9d7c292

Browse files
committed
fix(platform-ios): detect Podfile and .xcworkspace
1 parent fa0d09b commit 9d7c292

File tree

7 files changed

+68
-59
lines changed

7 files changed

+68
-59
lines changed

packages/platform-ios/src/config/__tests__/findPodfilePath.test.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

packages/platform-ios/src/config/__tests__/findProject.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
*/
88

9-
import findProject from '../findProject';
9+
import {findXcodeProject as findProject} from '../findProject';
1010
import * as projects from '../__fixtures__/projects';
1111

1212
jest.mock('path');

packages/platform-ios/src/config/findPodfilePath.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

packages/platform-ios/src/config/findProject.ts

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88

99
import glob from 'glob';
1010
import path from 'path';
11+
import isXcodeProject from './isXcodeProject';
1112

1213
/**
1314
* Glob pattern to look for xcodeproj
1415
*/
15-
const GLOB_PATTERN = '**/*.xcodeproj';
16+
const GLOB_PATTERN = '**/*.{xcodeproj,xcworkspace}';
1617

1718
/**
1819
* Regexp matching all test projects
@@ -29,17 +30,9 @@ const IOS_BASE = 'ios';
2930
*/
3031
const GLOB_EXCLUDE_PATTERN = ['**/@(Pods|node_modules|Carthage)/**'];
3132

32-
/**
33-
* Finds iOS project by looking for all .xcodeproj files
34-
* in given folder.
35-
*
36-
* Returns first match if files are found or null
37-
*
38-
* Note: `./ios/*.xcodeproj` are returned regardless of the name
39-
*/
40-
export default function findProject(folder: string): string | null {
41-
const projects = glob
42-
.sync(GLOB_PATTERN, {
33+
function findProject(folder: string, pattern: string): string[] {
34+
return glob
35+
.sync(pattern, {
4336
cwd: folder,
4437
ignore: GLOB_EXCLUDE_PATTERN,
4538
})
@@ -48,10 +41,37 @@ export default function findProject(folder: string): string | null {
4841
path.dirname(project) === IOS_BASE || !TEST_PROJECTS.test(project),
4942
)
5043
.sort((project) => (path.dirname(project) === IOS_BASE ? -1 : 1));
44+
}
5145

46+
/**
47+
* Finds a `Podfile` in given folder.
48+
*
49+
* Returns first match if files are found or null
50+
*
51+
* Note: `./ios/Podfile` are returned regardless of the name
52+
*/
53+
export function findPodfile(folder: string): string | null {
54+
const projects = findProject(folder, '**/Podfile');
5255
if (projects.length === 0) {
5356
return null;
5457
}
5558

5659
return projects[0];
5760
}
61+
62+
/**
63+
* Finds iOS project by looking for all .xcodeproj files
64+
* in given folder.
65+
*
66+
* Returns first match if files are found or null
67+
*
68+
* Note: `./ios/*.xcodeproj` are returned regardless of the name
69+
*/
70+
export function findXcodeProject(folder: string): string | null {
71+
const projects = findProject(folder, GLOB_PATTERN);
72+
if (projects.length === 0) {
73+
return null;
74+
}
75+
76+
return projects.find(isXcodeProject) || projects[0];
77+
}

packages/platform-ios/src/config/index.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@
88

99
import path from 'path';
1010
import {memoize} from 'lodash';
11-
import findProject from './findProject';
12-
import findPodfilePath from './findPodfilePath';
11+
import {findPodfile, findXcodeProject} from './findProject';
1312
import findPodspec from './findPodspec';
13+
import isXcodeProject from './isXcodeProject';
1414
import {
1515
IOSProjectParams,
1616
IOSDependencyParams,
1717
} from '@react-native-community/cli-types';
1818

19-
const memoizedFindProject = memoize(findProject);
19+
const memoizedFindPodfile = memoize(findPodfile);
20+
const memoizedFindProject = memoize(findXcodeProject);
2021

2122
/**
2223
* For libraries specified without an extension, add '.tbd' for those that
@@ -38,31 +39,41 @@ export function projectConfig(folder: string, userConfig: IOSProjectParams) {
3839
if (!userConfig) {
3940
return;
4041
}
42+
43+
const podfile = memoizedFindPodfile(folder);
4144
const project = userConfig.project || memoizedFindProject(folder);
4245

4346
/**
4447
* No iOS config found here
4548
*/
46-
if (!project) {
49+
if (!project && !podfile) {
4750
return null;
4851
}
4952

50-
const projectPath = path.join(folder, project);
51-
const sourceDir = path.dirname(projectPath);
53+
const projectPath = project && path.join(folder, project);
54+
55+
// Source files may be referenced from anywhere in a `.xcodeproj`. CocoaPods,
56+
// on the other hand, is a lot stricter because files cannot live outside the
57+
// folder in which `Podfile` resides. If we found a `Podfile`, it's a strong
58+
// indication that source files are in that directory.
59+
const sourceDir = path.resolve(path.dirname(podfile || projectPath || ''));
5260

5361
return {
5462
sourceDir,
5563
folder,
56-
pbxprojPath: path.join(projectPath, 'project.pbxproj'),
57-
podfile: findPodfilePath(projectPath),
64+
pbxprojPath:
65+
projectPath && isXcodeProject(projectPath)
66+
? path.join(projectPath, 'project.pbxproj')
67+
: null,
68+
podfile: podfile && path.resolve(podfile),
5869
podspecPath:
5970
userConfig.podspecPath ||
6071
// podspecs are usually placed in the root dir of the library or in the
6172
// iOS project path
6273
findPodspec(folder) ||
6374
findPodspec(sourceDir),
6475
projectPath,
65-
projectName: path.basename(projectPath),
76+
projectName: projectPath && path.basename(projectPath),
6677
libraryFolder: userConfig.libraryFolder || 'Libraries',
6778
sharedLibraries: mapSharedLibaries(userConfig.sharedLibraries || []),
6879
plist: userConfig.plist || [],
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
export default function isXcodeProject(projectPath: string): boolean {
9+
return projectPath.endsWith('.xcodeproj');
10+
}

packages/platform-ios/src/link/warnAboutManuallyLinkedLibs.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@ export default function warnAboutManuallyLinkedLibs(
1212
Config['platforms']['ios']['linkConfig']
1313
> = getLinkConfig(),
1414
) {
15-
let deps: Array<string> = [];
1615
const projectConfig = config.project[platform];
16+
if (projectConfig.pbxprojPath === null) {
17+
return;
18+
}
19+
20+
let deps: Array<string> = [];
1721

1822
for (let key in config.dependencies) {
1923
const dependency = config.dependencies[key];

0 commit comments

Comments
 (0)