From 59cfbd9f3519bb39d1d120bc5781041b1b97ac71 Mon Sep 17 00:00:00 2001 From: Tommy Nguyen <4123478+tido64@users.noreply.github.com> Date: Thu, 5 Aug 2021 06:39:38 +0200 Subject: [PATCH] fix(platform-ios): fix `sourceDir` detection (#1444) * fix(platform-ios): fix `sourceDir` detection See also #1054 and #1436. Resolves #1435. * yarn lint --fix --- .../config/__tests__/findPodfilePath.test.ts | 4 ++-- .../src/config/findPodfilePath.ts | 17 +++++++++++++--- packages/platform-ios/src/config/index.ts | 9 +++++++-- yarn.lock | 20 +++++++++---------- 4 files changed, 33 insertions(+), 17 deletions(-) diff --git a/packages/platform-ios/src/config/__tests__/findPodfilePath.test.ts b/packages/platform-ios/src/config/__tests__/findPodfilePath.test.ts index f3da6da8e..d8bfe7904 100644 --- a/packages/platform-ios/src/config/__tests__/findPodfilePath.test.ts +++ b/packages/platform-ios/src/config/__tests__/findPodfilePath.test.ts @@ -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'); }); }); diff --git a/packages/platform-ios/src/config/findPodfilePath.ts b/packages/platform-ios/src/config/findPodfilePath.ts index 695be0888..814b3aabd 100644 --- a/packages/platform-ios/src/config/findPodfilePath.ts +++ b/packages/platform-ios/src/config/findPodfilePath.ts @@ -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; } diff --git a/packages/platform-ios/src/config/index.ts b/packages/platform-ios/src/config/index.ts index 965f397be..21574257c 100644 --- a/packages/platform-ios/src/config/index.ts +++ b/packages/platform-ios/src/config/index.ts @@ -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 diff --git a/yarn.lock b/yarn.lock index 84fa1bf38..d6bfd31be 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -9376,14 +9376,14 @@ pkginfo@0.x.x: 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"