Skip to content

Commit

Permalink
fix(platform-ios): fix sourceDir detection (#1444)
Browse files Browse the repository at this point in the history
* fix(platform-ios): fix `sourceDir` detection

See also #1054 and #1436.

Resolves #1435.

* yarn lint --fix
  • Loading branch information
tido64 authored Aug 5, 2021
1 parent 44f5413 commit 59cfbd9
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ const fs = require('fs');
describe('ios::findPodfilePath', () => {
it('returns null if there is no Podfile', () => {
fs.__setMockFilesystem(projects.withoutPods);
expect(findPodfilePath('')).toBeNull();
expect(findPodfilePath(process.cwd(), '')).toBeNull();
});

it('returns Podfile path if it exists', () => {
fs.__setMockFilesystem(projects.withPods);
expect(findPodfilePath('/ios')).toContain('Podfile');
expect(findPodfilePath(process.cwd(), '/ios')).toContain('Podfile');
});
});
17 changes: 14 additions & 3 deletions packages/platform-ios/src/config/findPodfilePath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,22 @@
*/

import fs from 'fs';
import glob from 'glob';
import path from 'path';

export default function findPodfilePath(projectFolder: string) {
export default function findPodfilePath(folder: string, projectFolder: string) {
const podFilePath = path.join(projectFolder, '..', 'Podfile');
const podFileExists = fs.existsSync(podFilePath);
if (fs.existsSync(podFilePath)) {
return podFilePath;
}

return podFileExists ? podFilePath : null;
const podfiles = glob.sync('**/Podfile', {
cwd: folder,
ignore: 'node_modules/**',
});
if (podfiles.length > 0) {
return path.join(folder, podfiles[0]);
}

return null;
}
9 changes: 7 additions & 2 deletions packages/platform-ios/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,18 @@ export function projectConfig(folder: string, userConfig: IOSProjectParams) {
}

const projectPath = path.join(folder, project);
const sourceDir = path.dirname(projectPath);
const podfile = findPodfilePath(folder, projectPath);

// This is a temporary fix for #1435. In certain repos, the Xcode project can
// be generated by a tool. The only file that we can assume to exist on disk
// is `Podfile`.
const sourceDir = podfile ? path.dirname(podfile) : path.dirname(projectPath);

return {
sourceDir,
folder,
pbxprojPath: path.join(projectPath, 'project.pbxproj'),
podfile: findPodfilePath(projectPath),
podfile,
podspecPath:
userConfig.podspecPath ||
// podspecs are usually placed in the root dir of the library or in the
Expand Down
20 changes: 10 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3177,10 +3177,10 @@ balanced-match@^1.0.0:
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767"
integrity sha1-ibTRmasr7kneFk6gK4nORi1xt2c=

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

base64-js@^1.5.1:
version "1.5.1"
Expand Down Expand Up @@ -9376,14 +9376,14 @@ [email protected]:
resolved "https://registry.yarnpkg.com/pkginfo/-/pkginfo-0.4.1.tgz#b5418ef0439de5425fc4995042dced14fb2a84ff"
integrity sha1-tUGO8EOd5UJfxJlQQtztFPsqhP8=

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

plist@^3.0.2:
version "3.0.2"
Expand Down

0 comments on commit 59cfbd9

Please sign in to comment.