Skip to content

Commit d5089ec

Browse files
tido64thymikee
authored andcommitted
fix(platform-ios): fix sourceDir detection (#1444)
* fix(platform-ios): fix `sourceDir` detection See also #1054 and #1436. Resolves #1435. * yarn lint --fix
1 parent 84e9f0b commit d5089ec

File tree

4 files changed

+36
-20
lines changed

4 files changed

+36
-20
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: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,22 @@
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', {
20+
cwd: folder,
21+
ignore: 'node_modules/**',
22+
});
23+
if (podfiles.length > 0) {
24+
return path.join(folder, podfiles[0]);
25+
}
26+
27+
return null;
1728
}

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: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3197,10 +3197,10 @@ balanced-match@^1.0.0:
31973197
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767"
31983198
integrity sha1-ibTRmasr7kneFk6gK4nORi1xt2c=
31993199

3200-
base64-js@^1.0.2, base64-js@^1.2.3:
3201-
version "1.3.1"
3202-
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.3.1.tgz#58ece8cb75dd07e71ed08c736abc5fac4dbf8df1"
3203-
integrity sha512-mLQ4i2QO1ytvGWFWmcngKO//JXAQueZvwEKtjgQFM4jIK0kU+ytMfplL8j+n5mspOfjHwoAg+9yhb7BwAHm36g==
3200+
base64-js@^1.0.2, base64-js@^1.5.1:
3201+
version "1.5.1"
3202+
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.5.1.tgz#1b1b440160a5bf7ad40b650f095963481903930a"
3203+
integrity sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==
32043204

32053205
base@^0.11.1:
32063206
version "0.11.2"
@@ -9452,13 +9452,13 @@ [email protected]:
94529452
integrity sha1-tUGO8EOd5UJfxJlQQtztFPsqhP8=
94539453

94549454
plist@^3.0.1:
9455-
version "3.0.1"
9456-
resolved "https://registry.yarnpkg.com/plist/-/plist-3.0.1.tgz#a9b931d17c304e8912ef0ba3bdd6182baf2e1f8c"
9457-
integrity sha512-GpgvHHocGRyQm74b6FWEZZVRroHKE1I0/BTjAmySaohK+cUn+hZpbqXkc3KWgW3gQYkqcQej35FohcT0FRlkRQ==
9455+
version "3.0.2"
9456+
resolved "https://registry.yarnpkg.com/plist/-/plist-3.0.2.tgz#74bbf011124b90421c22d15779cee60060ba95bc"
9457+
integrity sha512-MSrkwZBdQ6YapHy87/8hDU8MnIcyxBKjeF+McXnr5A9MtffPewTs7G3hlpodT5TacyfIyFTaJEhh3GGcmasTgQ==
94589458
dependencies:
9459-
base64-js "^1.2.3"
9459+
base64-js "^1.5.1"
94609460
xmlbuilder "^9.0.7"
9461-
xmldom "0.1.x"
9461+
xmldom "^0.5.0"
94629462

94639463
pn@^1.1.0:
94649464
version "1.1.0"
@@ -12363,10 +12363,10 @@ xmldoc@^1.1.2:
1236312363
dependencies:
1236412364
sax "^1.2.1"
1236512365

12366-
xmldom@0.1.x:
12367-
version "0.1.31"
12368-
resolved "https://registry.yarnpkg.com/xmldom/-/xmldom-0.1.31.tgz#b76c9a1bd9f0a9737e5a72dc37231cf38375e2ff"
12369-
integrity sha512-yS2uJflVQs6n+CyjHoaBmVSqIDevTAWrzMmjG1Gc7h1qQ7uVozNhEPJAwZXWyGQ/Gafo3fCwrcaokezLPupVyQ==
12366+
xmldom@^0.5.0:
12367+
version "0.5.0"
12368+
resolved "https://registry.yarnpkg.com/xmldom/-/xmldom-0.5.0.tgz#193cb96b84aa3486127ea6272c4596354cb4962e"
12369+
integrity sha512-Foaj5FXVzgn7xFzsKeNIde9g6aFBxTPi37iwsno8QvApmtg7KYrr+OPyRHcJF7dud2a5nGRBXK3n0dL62Gf7PA==
1237012370

1237112371
xtend@^4.0.0, xtend@~4.0.1:
1237212372
version "4.0.2"

0 commit comments

Comments
 (0)