Skip to content

Commit e11faaa

Browse files
author
Fatme
authored
Merge pull request #4385 from NativeScript/fatme/fix-podfile-without-platform-version
fix: process correctly podfiles without platform's version
2 parents 408bf2f + 60aba19 commit e11faaa

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

lib/services/cocoapods-platform-manager.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,16 @@ export class CocoaPodsPlatformManager implements ICocoaPodsPlatformManager {
4848
}
4949

5050
private getPlatformSectionData(projectPodfileContent: string): { podfilePlatformData: IPodfilePlatformData, platformSectionContent: string } {
51-
const platformSectionRegExp = new RegExp(`${this.getPlatformSectionHeader()} ([\\s\\S]*?)with (.*)[\\s\\S]*?${this.getPlatformSectionFooter()}`, "m");
51+
const platformSectionRegExp = new RegExp(`${this.getPlatformSectionHeader()} ([\\s\\S]*?)with[\\s\\S]*?\\n([\\s\\S]*?(?:,\\s*?['"](.+)['"])?)\\n${this.getPlatformSectionFooter()}`, "m");
5252
const match = platformSectionRegExp.exec(projectPodfileContent);
5353
let result = null;
5454
if (match && match[0]) {
5555
result = {
5656
platformSectionContent: match[0],
5757
podfilePlatformData: {
5858
path: match[1].trim(),
59-
content: "",
60-
version: match[2]
59+
content: match[2],
60+
version: match[3]
6161
}
6262
};
6363
}
@@ -107,7 +107,7 @@ export class CocoaPodsPlatformManager implements ICocoaPodsPlatformManager {
107107
const appResourcesPodfilePath = path.join(projectData.getAppResourcesDirectoryPath(), "iOS", PODFILE_NAME);
108108
const isFromAppResources = oldPodfilePlatformData.path !== appResourcesPodfilePath && currentPodfilePlatformData.path === appResourcesPodfilePath;
109109
const isFromAppResourcesWithGreaterPlatformVersion = oldPodfilePlatformData.path === appResourcesPodfilePath && currentPodfilePlatformData.path === appResourcesPodfilePath && semver.gt(semver.coerce(currentPodfilePlatformData.version), semver.coerce(oldPodfilePlatformData.version));
110-
const isPodfileWithGreaterPlatformVersion = !currentPodfilePlatformData.version || semver.gt(semver.coerce(currentPodfilePlatformData.version), semver.coerce(oldPodfilePlatformData.version));
110+
const isPodfileWithGreaterPlatformVersion = !currentPodfilePlatformData.version || (oldPodfilePlatformData.version && semver.gt(semver.coerce(currentPodfilePlatformData.version), semver.coerce(oldPodfilePlatformData.version)));
111111
const result = isFromAppResources || isFromAppResourcesWithGreaterPlatformVersion || isPodfileWithGreaterPlatformVersion;
112112
return result;
113113
}

test/cocoapods-service.ts

+33
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,39 @@ target "projectName" do
10441044
# platform :ios, '10.0'
10451045
# End Podfile
10461046
1047+
# Begin Podfile - node_modules/myPluginWithoutPlatform/Podfile
1048+
pod 'myPod' ~> 0.3.4
1049+
# End Podfile# NativeScriptPlatformSection node_modules/myFirstPluginWithPlatform/Podfile with
1050+
platform :ios
1051+
# End NativeScriptPlatformSection
1052+
end`
1053+
},
1054+
{
1055+
name: "shouldn't replace the platform without version when no Podfile in App_Resources",
1056+
pods: [{
1057+
name: 'myPluginWithoutPlatform',
1058+
path: 'node_modules/myPluginWithoutPlatform/Podfile',
1059+
content: `pod 'myPod' ~> 0.3.4`
1060+
}, {
1061+
name: 'myFirstPluginWithPlatform',
1062+
path: 'node_modules/myFirstPluginWithPlatform/Podfile',
1063+
content: `platform :ios`
1064+
}, {
1065+
name: 'mySecondPluginWithPlatform',
1066+
path: 'node_modules/mySecondPluginWithPlatform/Podfile',
1067+
content: `platform :ios, '10.0'`
1068+
}],
1069+
expectedProjectPodfileContent: `use_frameworks!
1070+
1071+
target "projectName" do
1072+
# Begin Podfile - node_modules/mySecondPluginWithPlatform/Podfile
1073+
# platform :ios, '10.0'
1074+
# End Podfile
1075+
1076+
# Begin Podfile - node_modules/myFirstPluginWithPlatform/Podfile
1077+
# platform :ios
1078+
# End Podfile
1079+
10471080
# Begin Podfile - node_modules/myPluginWithoutPlatform/Podfile
10481081
pod 'myPod' ~> 0.3.4
10491082
# End Podfile# NativeScriptPlatformSection node_modules/myFirstPluginWithPlatform/Podfile with

0 commit comments

Comments
 (0)