Skip to content

fix(platform-ios): fix sourceDir detection #1444

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions packages/platform-android/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ export function projectConfig(
userConfig.buildGradlePath || 'build.gradle',
);

const dependencyConfiguration =
userConfig.dependencyConfiguration;
const dependencyConfiguration = userConfig.dependencyConfiguration;

return {
sourceDir,
Expand Down Expand Up @@ -159,8 +158,7 @@ export function dependencyConfig(
userConfig.packageInstance || `new ${packageClassName}()`;

const buildTypes = userConfig.buildTypes || [];
const dependencyConfiguration =
userConfig.dependencyConfiguration;
const dependencyConfiguration = userConfig.dependencyConfiguration;

return {
sourceDir,
Expand Down
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not change this one to be honest, sourceDir is not needed for autolinking, so there's no need to adjust it for cases when xcodeproj doesn't exist. It is needed for legacy link command and in the case of a missing xcodeproj, that would fail anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like it is being used for autolinking:

project_root = Pathname.new(config["project"]["ios"]["sourceDir"])

Without this change, we hit errors similar to this when running pod install:

[!] No podspec found for `ReactTestApp-DevSupport` in `..`

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You’re right 😅


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
25 changes: 15 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==

base@^0.11.1:
version "0.11.2"
Expand Down Expand Up @@ -9363,14 +9363,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"

pn@^1.1.0:
version "1.1.0"
Expand Down Expand Up @@ -12259,6 +12259,11 @@ [email protected]:
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"
resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.2.tgz#bb72779f5fa465186b1f438f674fa347fdb5db54"
Expand Down