Skip to content

Commit c7876f1

Browse files
committed
fix: apply pod install after merging all pod files (from node_modules and from App_Resources)
1 parent 8b01617 commit c7876f1

10 files changed

+36
-55
lines changed

lib/definitions/project.d.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,7 @@ interface IPlatformProjectService extends NodeJS.EventEmitter, IPlatformProjectS
400400
*/
401401
removePluginNativeCode(pluginData: IPluginData, projectData: IProjectData): Promise<void>;
402402

403-
afterPrepareAllPlugins(projectData: IProjectData): Promise<void>;
404-
beforePrepareAllPlugins(projectData: IProjectData, dependencies?: IDependencyData[]): Promise<void>;
403+
handleNativeDependenciesChange(projectData: IProjectData): Promise<void>;
405404

406405
/**
407406
* Gets the path wheren App_Resources should be copied.

lib/services/android-project-service.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -577,11 +577,7 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
577577
}
578578
}
579579

580-
public async afterPrepareAllPlugins(projectData: IProjectData): Promise<void> {
581-
return;
582-
}
583-
584-
public async beforePrepareAllPlugins(projectData: IProjectData, dependencies?: IDependencyData[]): Promise<void> {
580+
public async handleNativeDependenciesChange(projectData: IProjectData, dependencies?: IDependencyData[]): Promise<void> {
585581
const shouldUseNewRoutine = this.runtimeVersionIsGreaterThanOrEquals(projectData, "3.3.0");
586582

587583
if (dependencies) {

lib/services/ios-project-service.ts

+26-27
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,7 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
800800
}
801801

802802
this.$pluginVariablesService.interpolateAppIdentifier(this.getPlatformData(projectData).configurationFilePath, projectData.projectIdentifiers.ios);
803+
await this.mergeProjectPodFile(projectData);
803804
}
804805

805806
private getInfoPlistPath(projectData: IProjectData): string {
@@ -976,34 +977,10 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
976977
this.$cocoapodsService.removePodfileFromProject(pluginData.name, this.$cocoapodsService.getPluginPodfilePath(pluginData), projectData, projectRoot);
977978
}
978979

979-
public async afterPrepareAllPlugins(projectData: IProjectData): Promise<void> {
980-
await this.installPodsIfAny(projectData);
981-
}
982-
983-
public async installPodsIfAny(projectData: IProjectData): Promise<void> {
980+
public async handleNativeDependenciesChange(projectData: IProjectData): Promise<void> {
984981
const projectRoot = this.getPlatformData(projectData).projectRoot;
985-
const mainPodfilePath = path.join(projectData.appResourcesDirectoryPath, this.getPlatformData(projectData).normalizedPlatformName, constants.PODFILE_NAME);
986-
if (this.$fs.exists(this.$cocoapodsService.getProjectPodfilePath(projectRoot)) || this.$fs.exists(mainPodfilePath)) {
987-
const xcodeProjPath = this.getXcodeprojPath(projectData);
988-
const xcuserDataPath = path.join(xcodeProjPath, "xcuserdata");
989-
const sharedDataPath = path.join(xcodeProjPath, "xcshareddata");
990-
991-
if (!this.$fs.exists(xcuserDataPath) && !this.$fs.exists(sharedDataPath)) {
992-
this.$logger.info("Creating project scheme...");
993-
await this.checkIfXcodeprojIsRequired();
994-
995-
const createSchemeRubyScript = `ruby -e "require 'xcodeproj'; xcproj = Xcodeproj::Project.open('${projectData.projectName}.xcodeproj'); xcproj.recreate_user_schemes; xcproj.save"`;
996-
await this.$childProcess.exec(createSchemeRubyScript, { cwd: this.getPlatformData(projectData).projectRoot });
997-
}
998-
999-
await this.$cocoapodsService.applyPodfileToProject(constants.NS_BASE_PODFILE, mainPodfilePath, projectData, this.getPlatformData(projectData).projectRoot);
1000-
1001-
await this.$cocoapodsService.executePodInstall(projectRoot, xcodeProjPath);
1002-
}
1003-
}
1004-
1005-
public beforePrepareAllPlugins(): Promise<void> {
1006-
return Promise.resolve();
982+
const xcodeProjPath = this.getXcodeprojPath(projectData);
983+
await this.$cocoapodsService.executePodInstall(projectRoot, xcodeProjPath);
1007984
}
1008985

1009986
public async checkForChanges(changesInfo: IProjectChangesInfo, { provision, teamId }: IProjectChangesOptions, projectData: IProjectData): Promise<void> {
@@ -1068,6 +1045,28 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
10681045
return semver.coerce(target);
10691046
}
10701047

1048+
private async mergeProjectPodFile(projectData: IProjectData): Promise<void> {
1049+
const platformData = this.getPlatformData(projectData);
1050+
const { projectRoot, normalizedPlatformName } = platformData;
1051+
const mainPodfilePath = path.join(projectData.appResourcesDirectoryPath, normalizedPlatformName, constants.PODFILE_NAME);
1052+
const projectPodfilePath = this.$cocoapodsService.getProjectPodfilePath(projectRoot);
1053+
if (this.$fs.exists(projectPodfilePath) || this.$fs.exists(mainPodfilePath)) {
1054+
const xcodeProjPath = this.getXcodeprojPath(projectData);
1055+
const xcuserDataPath = path.join(xcodeProjPath, "xcuserdata");
1056+
const sharedDataPath = path.join(xcodeProjPath, "xcshareddata");
1057+
1058+
if (!this.$fs.exists(xcuserDataPath) && !this.$fs.exists(sharedDataPath)) {
1059+
this.$logger.info("Creating project scheme...");
1060+
await this.checkIfXcodeprojIsRequired();
1061+
1062+
const createSchemeRubyScript = `ruby -e "require 'xcodeproj'; xcproj = Xcodeproj::Project.open('${projectData.projectName}.xcodeproj'); xcproj.recreate_user_schemes; xcproj.save"`;
1063+
await this.$childProcess.exec(createSchemeRubyScript, { cwd: projectRoot });
1064+
}
1065+
1066+
await this.$cocoapodsService.applyPodfileToProject(constants.NS_BASE_PODFILE, mainPodfilePath, projectData, projectRoot);
1067+
}
1068+
}
1069+
10711070
private getAllLibsForPluginWithFileExtension(pluginData: IPluginData, fileExtension: string): string[] {
10721071
const filterCallback = (fileName: string, pluginPlatformsFolderPath: string) => path.extname(fileName) === fileExtension;
10731072
return this.getAllNativeLibrariesForPlugin(pluginData, IOSProjectService.IOS_PLATFORM_NAME, filterCallback);

lib/services/prepare-platform-native-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export class PreparePlatformNativeService extends PreparePlatformService impleme
6767

6868
if (hasModulesChange || hasConfigChange) {
6969
await config.platformData.platformProjectService.processConfigurationFilesFromAppResources(config.projectData, { release: config.appFilesUpdaterOptions.release });
70-
await config.platformData.platformProjectService.afterPrepareAllPlugins(config.projectData);
70+
await config.platformData.platformProjectService.handleNativeDependenciesChange(config.projectData);
7171
}
7272

7373
config.platformData.platformProjectService.interpolateConfigurationFile(config.projectData, config.platformSpecificData);

lib/tools/node-modules/node-modules-dest-copy.ts

-5
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,6 @@ export class NpmPluginPrepare {
107107
) {
108108
}
109109

110-
protected async beforePrepare(dependencies: IDependencyData[], platform: string, projectData: IProjectData): Promise<void> {
111-
await this.$platformsData.getPlatformData(platform, projectData).platformProjectService.beforePrepareAllPlugins(projectData, dependencies);
112-
}
113-
114110
protected async afterPrepare(dependencies: IDependencyData[], platform: string, projectData: IProjectData): Promise<void> {
115111
const prepareData: IDictionary<boolean> = {};
116112
_.each(dependencies, d => {
@@ -158,7 +154,6 @@ export class NpmPluginPrepare {
158154
return;
159155
}
160156

161-
await this.beforePrepare(dependencies, platform, projectData);
162157
for (const dependencyKey in dependencies) {
163158
const dependency = dependencies[dependencyKey];
164159
const isPlugin = !!dependency.nativescript;

test/debug.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ describe("debug command tests", () => {
350350
testInjector = createTestInjector();
351351
});
352352

353-
it("Ensures that beforePrepareAllPlugins will call gradle with clean option when *NOT* livesyncing", async () => {
353+
it("Ensures that handleNativeDependenciesChange will call gradle with clean option when *NOT* livesyncing", async () => {
354354
const platformData = testInjector.resolve<IPlatformData>("platformsData");
355355
platformData.frameworkPackageName = "tns-android";
356356

@@ -367,7 +367,7 @@ describe("debug command tests", () => {
367367
};
368368
const projectData: IProjectData = testInjector.resolve("projectData");
369369
const spawnFromEventCount = childProcess.spawnFromEventCount;
370-
await androidProjectService.beforePrepareAllPlugins(projectData);
370+
await androidProjectService.handleNativeDependenciesChange(projectData);
371371
assert.isTrue(childProcess.lastCommand.indexOf("gradle") !== -1);
372372
assert.isTrue(childProcess.lastCommandArgs[0] === "clean");
373373
assert.isTrue(spawnFromEventCount === 0);

test/npm-support.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,7 @@ async function setupProject(dependencies?: any): Promise<any> {
182182
platformProjectService: {
183183
prepareProject: (): any => null,
184184
prepareAppResources: (): any => null,
185-
afterPrepareAllPlugins: () => Promise.resolve(),
186-
beforePrepareAllPlugins: () => Promise.resolve(),
185+
handleNativeDependenciesChange: () => Promise.resolve(),
187186
getAppResourcesDestinationDirectoryPath: () => path.join(androidFolderPath, "src", "main", "res"),
188187
processConfigurationFilesFromAppResources: () => Promise.resolve(),
189188
ensureConfigurationFileInAppResources: (): any => null,

test/platform-service.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ describe('Platform Service Tests', () => {
496496
}
497497
},
498498
processConfigurationFilesFromAppResources: () => Promise.resolve(),
499-
afterPrepareAllPlugins: () => Promise.resolve(),
499+
handleNativeDependenciesChange: () => Promise.resolve(),
500500
ensureConfigurationFileInAppResources: (): any => null,
501501
interpolateConfigurationFile: (): void => undefined,
502502
isPlatformPrepared: (projectRoot: string) => false,
@@ -932,7 +932,7 @@ describe('Platform Service Tests', () => {
932932
afterCreateProject: (projectRoot: string): any => null,
933933
getAppResourcesDestinationDirectoryPath: () => testDirData.appResourcesFolderPath,
934934
processConfigurationFilesFromAppResources: () => Promise.resolve(),
935-
afterPrepareAllPlugins: () => Promise.resolve(),
935+
handleNativeDependenciesChange: () => Promise.resolve(),
936936
ensureConfigurationFileInAppResources: (): any => null,
937937
interpolateConfigurationFile: (): void => undefined,
938938
isPlatformPrepared: (projectRoot: string) => false,

test/plugin-prepare.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,11 @@ class TestNpmPluginPrepare extends NpmPluginPrepare {
1414
return this.previouslyPrepared;
1515
}
1616

17-
protected async beforePrepare(dependencies: IDependencyData[], platform: string): Promise<void> {
17+
protected async afterPrepare(dependencies: IDependencyData[], platform: string): Promise<void> {
1818
_.each(dependencies, d => {
1919
this.preparedDependencies[d.name] = true;
2020
});
2121
}
22-
23-
protected async afterPrepare(dependencies: IDependencyData[], platform: string): Promise<void> {
24-
// DO NOTHING
25-
}
2622
}
2723

2824
describe("Plugin preparation", () => {

test/stubs.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -445,10 +445,7 @@ export class PlatformProjectServiceStub extends EventEmitter implements IPlatfor
445445

446446
async removePluginNativeCode(pluginData: IPluginData): Promise<void> { }
447447

448-
async afterPrepareAllPlugins(): Promise<void> {
449-
return Promise.resolve();
450-
}
451-
async beforePrepareAllPlugins(): Promise<void> {
448+
async handleNativeDependenciesChange(): Promise<void> {
452449
return Promise.resolve();
453450
}
454451
async cleanDeviceTempFolder(deviceIdentifier: string): Promise<void> {

0 commit comments

Comments
 (0)