Skip to content

Commit 2ea0b5e

Browse files
Merge pull request #4579 from NativeScript/vladimirov/apply-cocoapods-correct-order
fix: fix the order of applying Podfiles
2 parents f031e8d + 8e6f70e commit 2ea0b5e

File tree

4 files changed

+148
-145
lines changed

4 files changed

+148
-145
lines changed

lib/services/cocoapods-platform-manager.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ export class CocoaPodsPlatformManager implements ICocoaPodsPlatformManager {
1313
if (shouldReplacePlatformSection) {
1414
this.$logger.warn(`Multiple identical platforms with different versions have been detected during the processing of podfiles. The current platform's content "${platformSectionData.podfilePlatformData.content}" from ${platformSectionData.podfilePlatformData.path} will be replaced with "${podfilePlatformData.content}" from ${podfilePlatformData.path}`);
1515
const newSection = this.buildPlatformSection(podfilePlatformData);
16-
projectPodfileContent = projectPodfileContent.replace(platformSectionData.platformSectionContent, newSection);
16+
projectPodfileContent = projectPodfileContent.replace(platformSectionData.platformSectionContent, newSection.trim());
1717
}
1818
} else {
19-
projectPodfileContent += this.buildPlatformSection(podfilePlatformData);
19+
projectPodfileContent = projectPodfileContent.trim() + EOL + EOL + this.buildPlatformSection(podfilePlatformData);
2020
}
2121

2222
return projectPodfileContent;
@@ -29,7 +29,7 @@ export class CocoaPodsPlatformManager implements ICocoaPodsPlatformManager {
2929
const allPodfiles = projectPodfileContent.match(podfileContentRegExp) || [];
3030
const selectedPlatformData = this.selectPlatformDataFromProjectPodfile(allPodfiles);
3131
const newPlatformSection = selectedPlatformData ? this.buildPlatformSection(selectedPlatformData) : "";
32-
const regExp = new RegExp(`\\r?\\n${platformSectionData.platformSectionContent}\\r?\\n`, "mg");
32+
const regExp = new RegExp(`${platformSectionData.platformSectionContent}\\r?\\n`, "mg");
3333
projectPodfileContent = projectPodfileContent.replace(regExp, newPlatformSection);
3434
}
3535

lib/services/cocoapods-service.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { EOL } from "os";
22
import * as path from "path";
33
import { PluginNativeDirNames, PODFILE_NAME, NS_BASE_PODFILE } from "../constants";
4+
import { regExpEscape } from "../common/helpers";
45

56
export class CocoaPodsService implements ICocoaPodsService {
67
private static PODFILE_POST_INSTALL_SECTION_NAME = "post_install";
@@ -100,7 +101,7 @@ export class CocoaPodsService implements ICocoaPodsService {
100101
finalPodfileContent = this.$cocoaPodsPlatformManager.addPlatformSection(projectData, podfilePlatformData, finalPodfileContent);
101102
}
102103

103-
finalPodfileContent = `${podfileContent}${EOL}${finalPodfileContent}`;
104+
finalPodfileContent = `${finalPodfileContent.trim()}${EOL}${EOL}${podfileContent.trim()}${EOL}`;
104105
this.saveProjectPodfile(projectData, finalPodfileContent, nativeProjectPath);
105106
}
106107
}
@@ -115,8 +116,8 @@ export class CocoaPodsService implements ICocoaPodsService {
115116
projectPodFileContent = this.$cocoaPodsPlatformManager.removePlatformSection(moduleName, projectPodFileContent, podfilePath);
116117

117118
const defaultPodfileBeginning = this.getPodfileHeader(projectData.projectName);
118-
const defaultContentWithPostInstallHook = `${defaultPodfileBeginning}${EOL}${this.getPostInstallHookHeader()}end${EOL}end`;
119-
const defaultContentWithoutPostInstallHook = `${defaultPodfileBeginning}end`;
119+
const defaultContentWithPostInstallHook = `${defaultPodfileBeginning}${this.getPostInstallHookHeader()}end${EOL}end`;
120+
const defaultContentWithoutPostInstallHook = `${defaultPodfileBeginning}${EOL}end`;
120121
const trimmedProjectPodFileContent = projectPodFileContent.trim();
121122
if (!trimmedProjectPodFileContent || trimmedProjectPodFileContent === defaultContentWithPostInstallHook || trimmedProjectPodFileContent === defaultContentWithoutPostInstallHook) {
122123
this.$fs.deleteFile(this.getProjectPodfilePath(projectRoot));
@@ -147,7 +148,9 @@ export class CocoaPodsService implements ICocoaPodsService {
147148
if (postInstallHookContent) {
148149
const index = finalPodfileContent.indexOf(postInstallHookStart);
149150
if (index !== -1) {
150-
finalPodfileContent = finalPodfileContent.replace(postInstallHookStart, `${postInstallHookStart}${postInstallHookContent}`);
151+
const regExp = new RegExp(`(${regExpEscape(postInstallHookStart)}[\\s\\S]*?)(\\bend\\b)`, "m");
152+
finalPodfileContent = finalPodfileContent.replace(regExp, `$1${postInstallHookContent.trimRight()}${EOL}$2`);
153+
151154
} else {
152155
if (finalPodfileContent.length > 0) {
153156
finalPodfileContent += `${EOL}${EOL}`;

0 commit comments

Comments
 (0)