Skip to content

Commit 59cfbd9

Browse files
authored
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 44f5413 commit 59cfbd9

File tree

4 files changed

+33
-17
lines changed

4 files changed

+33
-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: 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: 10 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
base64-js@^1.5.1:
31863186
version "1.5.1"
@@ -9376,14 +9376,14 @@ [email protected]:
93769376
resolved "https://registry.yarnpkg.com/pkginfo/-/pkginfo-0.4.1.tgz#b5418ef0439de5425fc4995042dced14fb2a84ff"
93779377
integrity sha1-tUGO8EOd5UJfxJlQQtztFPsqhP8=
93789378

9379-
plist@^3.0.1:
9380-
version "3.0.1"
9381-
resolved "https://registry.yarnpkg.com/plist/-/plist-3.0.1.tgz#a9b931d17c304e8912ef0ba3bdd6182baf2e1f8c"
9382-
integrity sha512-GpgvHHocGRyQm74b6FWEZZVRroHKE1I0/BTjAmySaohK+cUn+hZpbqXkc3KWgW3gQYkqcQej35FohcT0FRlkRQ==
9379+
plist@^3.0.1, plist@^3.0.2:
9380+
version "3.0.2"
9381+
resolved "https://registry.yarnpkg.com/plist/-/plist-3.0.2.tgz#74bbf011124b90421c22d15779cee60060ba95bc"
9382+
integrity sha512-MSrkwZBdQ6YapHy87/8hDU8MnIcyxBKjeF+McXnr5A9MtffPewTs7G3hlpodT5TacyfIyFTaJEhh3GGcmasTgQ==
93839383
dependencies:
9384-
base64-js "^1.2.3"
9384+
base64-js "^1.5.1"
93859385
xmlbuilder "^9.0.7"
9386-
xmldom "0.1.x"
9386+
xmldom "^0.5.0"
93879387

93889388
plist@^3.0.2:
93899389
version "3.0.2"

0 commit comments

Comments
 (0)