Skip to content

Commit a86abe3

Browse files
committed
fix(platform-ios): fix sourceDir detection
See also react-native-community#1054 and react-native-community#1436. Resolves react-native-community#1435.
1 parent 6615eb3 commit a86abe3

File tree

4 files changed

+35
-17
lines changed

4 files changed

+35
-17
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ const fs = require('fs');
99
describe('ios::findPodfilePath', () => {
1010
it('returns null if there is no Podfile', () => {
1111
fs.__setMockFilesystem(projects.withoutPods);
12-
expect(findPodfilePath('')).toBeNull();
12+
expect(findPodfilePath(process.cwd(), '')).toBeNull();
1313
});
1414

1515
it('returns Podfile path if it exists', () => {
1616
fs.__setMockFilesystem(projects.withPods);
17-
expect(findPodfilePath('/ios')).toContain('Podfile');
17+
expect(findPodfilePath(process.cwd(), '/ios')).toContain('Podfile');
1818
});
1919
});

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,19 @@
77
*/
88

99
import fs from 'fs';
10+
import glob from 'glob';
1011
import path from 'path';
1112

12-
export default function findPodfilePath(projectFolder: string) {
13+
export default function findPodfilePath(folder: string, projectFolder: string) {
1314
const podFilePath = path.join(projectFolder, '..', 'Podfile');
14-
const podFileExists = fs.existsSync(podFilePath);
15+
if (fs.existsSync(podFilePath)) {
16+
return podFilePath;
17+
}
1518

16-
return podFileExists ? podFilePath : null;
19+
const podfiles = glob.sync('**/Podfile', {cwd: folder, ignore: "node_modules/**"});
20+
if (podfiles.length > 0) {
21+
return path.join(folder, podfiles[0]);
22+
}
23+
24+
return null;
1725
}

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,18 @@ export function projectConfig(folder: string, userConfig: IOSProjectParams) {
4848
}
4949

5050
const projectPath = path.join(folder, project);
51-
const sourceDir = path.dirname(projectPath);
51+
const podfile = findPodfilePath(folder, projectPath);
52+
53+
// This is a temporary fix for #1435. In certain repos, the Xcode project can
54+
// be generated by a tool. The only file that we can assume to exist on disk
55+
// is `Podfile`.
56+
const sourceDir = podfile ? path.dirname(podfile) : path.dirname(projectPath);
5257

5358
return {
5459
sourceDir,
5560
folder,
5661
pbxprojPath: path.join(projectPath, 'project.pbxproj'),
57-
podfile: findPodfilePath(projectPath),
62+
podfile,
5863
podspecPath:
5964
userConfig.podspecPath ||
6065
// podspecs are usually placed in the root dir of the library or in the

yarn.lock

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3177,10 +3177,10 @@ balanced-match@^1.0.0:
31773177
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767"
31783178
integrity sha1-ibTRmasr7kneFk6gK4nORi1xt2c=
31793179

3180-
base64-js@^1.0.2, base64-js@^1.2.3:
3181-
version "1.3.1"
3182-
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.3.1.tgz#58ece8cb75dd07e71ed08c736abc5fac4dbf8df1"
3183-
integrity sha512-mLQ4i2QO1ytvGWFWmcngKO//JXAQueZvwEKtjgQFM4jIK0kU+ytMfplL8j+n5mspOfjHwoAg+9yhb7BwAHm36g==
3180+
base64-js@^1.0.2, base64-js@^1.2.3, base64-js@^1.5.1:
3181+
version "1.5.1"
3182+
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.5.1.tgz#1b1b440160a5bf7ad40b650f095963481903930a"
3183+
integrity sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==
31843184

31853185
base@^0.11.1:
31863186
version "0.11.2"
@@ -9363,14 +9363,14 @@ [email protected]:
93639363
resolved "https://registry.yarnpkg.com/pkginfo/-/pkginfo-0.4.1.tgz#b5418ef0439de5425fc4995042dced14fb2a84ff"
93649364
integrity sha1-tUGO8EOd5UJfxJlQQtztFPsqhP8=
93659365

9366-
plist@^3.0.1:
9367-
version "3.0.1"
9368-
resolved "https://registry.yarnpkg.com/plist/-/plist-3.0.1.tgz#a9b931d17c304e8912ef0ba3bdd6182baf2e1f8c"
9369-
integrity sha512-GpgvHHocGRyQm74b6FWEZZVRroHKE1I0/BTjAmySaohK+cUn+hZpbqXkc3KWgW3gQYkqcQej35FohcT0FRlkRQ==
9366+
plist@^3.0.1, plist@^3.0.2:
9367+
version "3.0.2"
9368+
resolved "https://registry.yarnpkg.com/plist/-/plist-3.0.2.tgz#74bbf011124b90421c22d15779cee60060ba95bc"
9369+
integrity sha512-MSrkwZBdQ6YapHy87/8hDU8MnIcyxBKjeF+McXnr5A9MtffPewTs7G3hlpodT5TacyfIyFTaJEhh3GGcmasTgQ==
93709370
dependencies:
9371-
base64-js "^1.2.3"
9371+
base64-js "^1.5.1"
93729372
xmlbuilder "^9.0.7"
9373-
xmldom "0.1.x"
9373+
xmldom "^0.5.0"
93749374

93759375
pn@^1.1.0:
93769376
version "1.1.0"
@@ -12259,6 +12259,11 @@ [email protected]:
1225912259
resolved "https://registry.yarnpkg.com/xmldom/-/xmldom-0.1.31.tgz#b76c9a1bd9f0a9737e5a72dc37231cf38375e2ff"
1226012260
integrity sha512-yS2uJflVQs6n+CyjHoaBmVSqIDevTAWrzMmjG1Gc7h1qQ7uVozNhEPJAwZXWyGQ/Gafo3fCwrcaokezLPupVyQ==
1226112261

12262+
xmldom@^0.5.0:
12263+
version "0.5.0"
12264+
resolved "https://registry.yarnpkg.com/xmldom/-/xmldom-0.5.0.tgz#193cb96b84aa3486127ea6272c4596354cb4962e"
12265+
integrity sha512-Foaj5FXVzgn7xFzsKeNIde9g6aFBxTPi37iwsno8QvApmtg7KYrr+OPyRHcJF7dud2a5nGRBXK3n0dL62Gf7PA==
12266+
1226212267
xtend@^4.0.0, xtend@~4.0.1:
1226312268
version "4.0.2"
1226412269
resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.2.tgz#bb72779f5fa465186b1f438f674fa347fdb5db54"

0 commit comments

Comments
 (0)