diff --git a/lib/services/cocoapods-platform-manager.ts b/lib/services/cocoapods-platform-manager.ts index 8f34fd4952..febd9fa38b 100644 --- a/lib/services/cocoapods-platform-manager.ts +++ b/lib/services/cocoapods-platform-manager.ts @@ -45,7 +45,7 @@ export class CocoaPodsPlatformManager implements ICocoaPodsPlatformManager { } private getPlatformSectionData(projectPodfileContent: string): { podfilePlatformData: IPodfilePlatformData, platformSectionContent: string } { - const platformSectionRegExp = new RegExp(`${this.getPlatformSectionHeader()} ([\\s\\S]*?)with (.*)[\\s\\S]*?${this.getPlatformSectionFooter()}`, "m"); + const platformSectionRegExp = new RegExp(`${this.getPlatformSectionHeader()} ([\\s\\S]*?)with[\\s\\S]*?\\n([\\s\\S]*?(?:,\\s*?['"](.+)['"])?)\\n${this.getPlatformSectionFooter()}`, "m"); const match = platformSectionRegExp.exec(projectPodfileContent); let result = null; if (match && match[0]) { @@ -53,8 +53,8 @@ export class CocoaPodsPlatformManager implements ICocoaPodsPlatformManager { platformSectionContent: match[0], podfilePlatformData: { path: match[1].trim(), - content: "", - version: match[2] + content: match[2], + version: match[3] } }; } @@ -104,7 +104,7 @@ export class CocoaPodsPlatformManager implements ICocoaPodsPlatformManager { const appResourcesPodfilePath = path.join(projectData.getAppResourcesDirectoryPath(), "iOS", PODFILE_NAME); const isFromAppResources = oldPodfilePlatformData.path !== appResourcesPodfilePath && currentPodfilePlatformData.path === appResourcesPodfilePath; const isFromAppResourcesWithGreaterPlatformVersion = oldPodfilePlatformData.path === appResourcesPodfilePath && currentPodfilePlatformData.path === appResourcesPodfilePath && semver.gt(semver.coerce(currentPodfilePlatformData.version), semver.coerce(oldPodfilePlatformData.version)); - const isPodfileWithGreaterPlatformVersion = !currentPodfilePlatformData.version || semver.gt(semver.coerce(currentPodfilePlatformData.version), semver.coerce(oldPodfilePlatformData.version)); + const isPodfileWithGreaterPlatformVersion = !currentPodfilePlatformData.version || (oldPodfilePlatformData.version && semver.gt(semver.coerce(currentPodfilePlatformData.version), semver.coerce(oldPodfilePlatformData.version))); const result = isFromAppResources || isFromAppResourcesWithGreaterPlatformVersion || isPodfileWithGreaterPlatformVersion; return result; } diff --git a/test/cocoapods-service.ts b/test/cocoapods-service.ts index d264c686d5..8f20ed93a5 100644 --- a/test/cocoapods-service.ts +++ b/test/cocoapods-service.ts @@ -1044,6 +1044,39 @@ target "projectName" do # platform :ios, '10.0' # End Podfile +# Begin Podfile - node_modules/myPluginWithoutPlatform/Podfile +pod 'myPod' ~> 0.3.4 +# End Podfile# NativeScriptPlatformSection node_modules/myFirstPluginWithPlatform/Podfile with +platform :ios +# End NativeScriptPlatformSection +end` + }, + { + name: "shouldn't replace the platform without version when no Podfile in App_Resources", + pods: [{ + name: 'myPluginWithoutPlatform', + path: 'node_modules/myPluginWithoutPlatform/Podfile', + content: `pod 'myPod' ~> 0.3.4` + }, { + name: 'myFirstPluginWithPlatform', + path: 'node_modules/myFirstPluginWithPlatform/Podfile', + content: `platform :ios` + }, { + name: 'mySecondPluginWithPlatform', + path: 'node_modules/mySecondPluginWithPlatform/Podfile', + content: `platform :ios, '10.0'` + }], + expectedProjectPodfileContent: `use_frameworks! + +target "projectName" do +# Begin Podfile - node_modules/mySecondPluginWithPlatform/Podfile +# platform :ios, '10.0' +# End Podfile + +# Begin Podfile - node_modules/myFirstPluginWithPlatform/Podfile +# platform :ios +# End Podfile + # Begin Podfile - node_modules/myPluginWithoutPlatform/Podfile pod 'myPod' ~> 0.3.4 # End Podfile# NativeScriptPlatformSection node_modules/myFirstPluginWithPlatform/Podfile with