Skip to content

fix: fix the order of applying Podfiles #4579

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 1 commit into from
May 8, 2019
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: 3 additions & 3 deletions lib/services/cocoapods-platform-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ export class CocoaPodsPlatformManager implements ICocoaPodsPlatformManager {
if (shouldReplacePlatformSection) {
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}`);
const newSection = this.buildPlatformSection(podfilePlatformData);
projectPodfileContent = projectPodfileContent.replace(platformSectionData.platformSectionContent, newSection);
projectPodfileContent = projectPodfileContent.replace(platformSectionData.platformSectionContent, newSection.trim());
}
} else {
projectPodfileContent += this.buildPlatformSection(podfilePlatformData);
projectPodfileContent = projectPodfileContent.trim() + EOL + EOL + this.buildPlatformSection(podfilePlatformData);
}

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

Expand Down
11 changes: 7 additions & 4 deletions lib/services/cocoapods-service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { EOL } from "os";
import * as path from "path";
import { PluginNativeDirNames, PODFILE_NAME, NS_BASE_PODFILE } from "../constants";
import { regExpEscape } from "../common/helpers";

export class CocoaPodsService implements ICocoaPodsService {
private static PODFILE_POST_INSTALL_SECTION_NAME = "post_install";
Expand Down Expand Up @@ -100,7 +101,7 @@ export class CocoaPodsService implements ICocoaPodsService {
finalPodfileContent = this.$cocoaPodsPlatformManager.addPlatformSection(projectData, podfilePlatformData, finalPodfileContent);
}

finalPodfileContent = `${podfileContent}${EOL}${finalPodfileContent}`;
finalPodfileContent = `${finalPodfileContent.trim()}${EOL}${EOL}${podfileContent.trim()}${EOL}`;
this.saveProjectPodfile(projectData, finalPodfileContent, nativeProjectPath);
}
}
Expand All @@ -115,8 +116,8 @@ export class CocoaPodsService implements ICocoaPodsService {
projectPodFileContent = this.$cocoaPodsPlatformManager.removePlatformSection(moduleName, projectPodFileContent, podfilePath);

const defaultPodfileBeginning = this.getPodfileHeader(projectData.projectName);
const defaultContentWithPostInstallHook = `${defaultPodfileBeginning}${EOL}${this.getPostInstallHookHeader()}end${EOL}end`;
const defaultContentWithoutPostInstallHook = `${defaultPodfileBeginning}end`;
const defaultContentWithPostInstallHook = `${defaultPodfileBeginning}${this.getPostInstallHookHeader()}end${EOL}end`;
const defaultContentWithoutPostInstallHook = `${defaultPodfileBeginning}${EOL}end`;
const trimmedProjectPodFileContent = projectPodFileContent.trim();
if (!trimmedProjectPodFileContent || trimmedProjectPodFileContent === defaultContentWithPostInstallHook || trimmedProjectPodFileContent === defaultContentWithoutPostInstallHook) {
this.$fs.deleteFile(this.getProjectPodfilePath(projectRoot));
Expand Down Expand Up @@ -147,7 +148,9 @@ export class CocoaPodsService implements ICocoaPodsService {
if (postInstallHookContent) {
const index = finalPodfileContent.indexOf(postInstallHookStart);
if (index !== -1) {
finalPodfileContent = finalPodfileContent.replace(postInstallHookStart, `${postInstallHookStart}${postInstallHookContent}`);
const regExp = new RegExp(`(${regExpEscape(postInstallHookStart)}[\\s\\S]*?)(\\bend\\b)`, "m");
finalPodfileContent = finalPodfileContent.replace(regExp, `$1${postInstallHookContent.trimRight()}${EOL}$2`);

} else {
if (finalPodfileContent.length > 0) {
finalPodfileContent += `${EOL}${EOL}`;
Expand Down
Loading