Skip to content

Commit aa981e8

Browse files
authored
fix: xcworkspaces parsing should handle many xcprojects (#2522)
1 parent 9da12a4 commit aa981e8

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import type {IOSProjectInfo} from '@react-native-community/cli-types';
2+
3+
import execa from 'execa';
4+
import fs from 'fs';
5+
import {getInfo} from '../getInfo';
6+
7+
jest.mock('execa', () => ({
8+
sync: jest.fn(),
9+
}));
10+
11+
jest.mock('fs', () => ({
12+
readFileSync: jest.fn(),
13+
}));
14+
15+
describe('getInfo', () => {
16+
it('handles non-project / workspace locations in a ', () => {
17+
const name = `YourProjectName`;
18+
(fs.readFileSync as jest.Mock)
19+
.mockReturnValueOnce(`<?xml version="1.0" encoding="UTF-8"?>
20+
<Workspace
21+
version = "1.0">
22+
<FileRef
23+
location = "group:${name}.xcodeproj">
24+
</FileRef>
25+
<FileRef
26+
location = "group:Pods/Pods.xcodeproj">
27+
</FileRef>
28+
<FileRef
29+
location = "group:container/some_other_file.mm">
30+
</FileRef>
31+
</Workspace>`);
32+
(execa.sync as jest.Mock).mockReturnValue({stdout: '{}'});
33+
getInfo({isWorkspace: true, name} as IOSProjectInfo, 'some/path');
34+
35+
const execaSync = execa.sync as jest.Mock;
36+
// Should not call on Pods or the other misc groups
37+
expect(execaSync.mock.calls).toEqual([
38+
[
39+
'xcodebuild',
40+
['-list', '-json', '-project', `some/path/${name}.xcodeproj`],
41+
],
42+
]);
43+
});
44+
});

packages/cli-platform-apple/src/tools/getInfo.ts

+4
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ export function getInfo(
5959
return refs.reduce<IosInfo | undefined>((result, ref) => {
6060
const location = ref['@_location'];
6161

62+
if (!location.endsWith('.xcodeproj')) {
63+
return result;
64+
}
65+
6266
// Ignore the project generated by CocoaPods
6367
if (location.endsWith('/Pods.xcodeproj')) {
6468
return result;

0 commit comments

Comments
 (0)