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 and thymikee committed Aug 5, 2021
1 parent 84e9f0b commit d5089ec
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 20 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
26 changes: 13 additions & 13 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3197,10 +3197,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.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==

base@^0.11.1:
version "0.11.2"
Expand Down Expand Up @@ -9452,13 +9452,13 @@ [email protected]:
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==
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"

pn@^1.1.0:
version "1.1.0"
Expand Down Expand Up @@ -12363,10 +12363,10 @@ xmldoc@^1.1.2:
dependencies:
sax "^1.2.1"

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

xtend@^4.0.0, xtend@~4.0.1:
version "4.0.2"
Expand Down

0 comments on commit d5089ec

Please sign in to comment.