Skip to content

Commit 65d524e

Browse files
authored
Merge pull request #5075 from NativeScript/kddimitrov/fix-podfile-detection-in-nested-plugins
Kddimitrov/fix podfile detection in nested plugins
2 parents 049cc2d + fbe2a15 commit 65d524e

File tree

6 files changed

+42
-20
lines changed

6 files changed

+42
-20
lines changed

lib/definitions/plugins.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ interface IPluginsService {
44
addToPackageJson(plugin: string, version: string, isDev: boolean, projectDir: string): void;
55
removeFromPackageJson(plugin: string, projectDir: string): void;
66
getAllInstalledPlugins(projectData: IProjectData): Promise<IPluginData[]>;
7+
getAllProductionPlugins(projectData: IProjectData, dependencies?: IDependencyData[]): IPluginData[];
78
ensureAllDependenciesAreInstalled(projectData: IProjectData): Promise<void>;
89

910
/**

lib/services/ios-project-service.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
399399
});
400400
};
401401

402-
const allPlugins = await this.getAllInstalledPlugins(projectData);
402+
const allPlugins = this.getAllProductionPlugins(projectData);
403403
for (const plugin of allPlugins) {
404404
const pluginInfoPlistPath = path.join(plugin.pluginPlatformsFolderPath(IOSProjectService.IOS_PLATFORM_NAME), this.getPlatformData(projectData).configurationFileName);
405405
makePatch(pluginInfoPlistPath);
@@ -452,8 +452,8 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
452452
this.$fs.writeFile(this.getPlatformData(projectData).configurationFilePath, plistContent);
453453
}
454454

455-
private getAllInstalledPlugins(projectData: IProjectData): Promise<IPluginData[]> {
456-
return (<IPluginsService>this.$injector.resolve("pluginsService")).getAllInstalledPlugins(projectData);
455+
private getAllProductionPlugins(projectData: IProjectData): IPluginData[] {
456+
return (<IPluginsService>this.$injector.resolve("pluginsService")).getAllProductionPlugins(projectData);
457457
}
458458

459459
private replace(name: string): string {
@@ -510,7 +510,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
510510

511511
public async handleNativeDependenciesChange(projectData: IProjectData, opts: IRelease): Promise<void> {
512512
const platformData = this.getPlatformData(projectData);
513-
const pluginsData = await this.getAllInstalledPlugins(projectData);
513+
const pluginsData = this.getAllProductionPlugins(projectData);
514514
this.setProductBundleIdentifier(projectData);
515515

516516
await this.applyPluginsCocoaPods(pluginsData, projectData, platformData);
@@ -763,8 +763,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
763763
this.$fs.deleteFile(pluginsXcconfigFilePath);
764764
}
765765

766-
const pluginsService = <IPluginsService>this.$injector.resolve("pluginsService");
767-
const allPlugins: IPluginData[] = await pluginsService.getAllInstalledPlugins(projectData);
766+
const allPlugins: IPluginData[] = this.getAllProductionPlugins(projectData);
768767
for (const plugin of allPlugins) {
769768
const pluginPlatformsFolderPath = plugin.pluginPlatformsFolderPath(IOSProjectService.IOS_PLATFORM_NAME);
770769
const pluginXcconfigFilePath = path.join(pluginPlatformsFolderPath, BUILD_XCCONFIG_FILE_NAME);

lib/services/plugins-service.ts

+22-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ export class PluginsService implements IPluginsService {
3232
private $errors: IErrors,
3333
private $filesHashService: IFilesHashService,
3434
private $injector: IInjector,
35-
private $mobileHelper: Mobile.IMobileHelper) { }
35+
private $mobileHelper: Mobile.IMobileHelper,
36+
private $nodeModulesDependenciesBuilder: INodeModulesDependenciesBuilder) { }
3637

3738
public async add(plugin: string, projectData: IProjectData): Promise<void> {
3839
await this.ensure(projectData);
@@ -169,6 +170,26 @@ export class PluginsService implements IPluginsService {
169170
return _.filter(nodeModules, nodeModuleData => nodeModuleData && nodeModuleData.isPlugin);
170171
}
171172

173+
//This method will traverse all non dev dependencies (not only the root/installed ones) and filter the plugins.
174+
public getAllProductionPlugins(projectData: IProjectData, dependencies?: IDependencyData[]): IPluginData[] {
175+
const allProductionPlugins: IPluginData[] = [];
176+
dependencies = dependencies || this.$nodeModulesDependenciesBuilder.getProductionDependencies(projectData.projectDir);
177+
178+
if (_.isEmpty(dependencies)) {
179+
return allProductionPlugins;
180+
}
181+
182+
_.forEach(dependencies, dependency => {
183+
const isPlugin = !!dependency.nativescript;
184+
if (isPlugin) {
185+
const pluginData = this.convertToPluginData(dependency, projectData.projectDir);
186+
allProductionPlugins.push(pluginData);
187+
}
188+
});
189+
190+
return allProductionPlugins;
191+
}
192+
172193
public getDependenciesFromPackageJson(projectDir: string): IPackageJsonDepedenciesResult {
173194
const packageJson = this.$fs.readJson(this.getPackageJsonFilePath(projectDir));
174195
const dependencies: IBasePluginData[] = this.getBasicPluginInformation(packageJson.dependencies);

lib/tools/node-modules/node-modules-builder.ts

+8-10
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,18 @@ export class NodeModulesBuilder implements INodeModulesBuilder {
77

88
public async prepareNodeModules({platformData , projectData}: IPrepareNodeModulesData): Promise<void> {
99
const dependencies = this.$nodeModulesDependenciesBuilder.getProductionDependencies(projectData.projectDir);
10-
if (_.isEmpty(dependencies)) {
10+
await platformData.platformProjectService.beforePrepareAllPlugins(projectData, dependencies);
11+
12+
const pluginsData = this.$pluginsService.getAllProductionPlugins(projectData, dependencies);
13+
if (_.isEmpty(pluginsData)) {
1114
return;
1215
}
1316

14-
await platformData.platformProjectService.beforePrepareAllPlugins(projectData, dependencies);
17+
for (let i = 0; i < pluginsData.length; i++) {
18+
const pluginData = pluginsData[i];
1519

16-
for (const dependencyKey in dependencies) {
17-
const dependency = dependencies[dependencyKey];
18-
const isPlugin = !!dependency.nativescript;
19-
if (isPlugin) {
20-
this.$logger.debug(`Successfully prepared plugin ${dependency.name} for ${platformData.normalizedPlatformName.toLowerCase()}.`);
21-
const pluginData = this.$pluginsService.convertToPluginData(dependency, projectData.projectDir);
22-
await this.$pluginsService.preparePluginNativeCode({pluginData, platform: platformData.normalizedPlatformName.toLowerCase(), projectData});
23-
}
20+
await this.$pluginsService.preparePluginNativeCode({pluginData, platform: platformData.normalizedPlatformName.toLowerCase(), projectData});
21+
this.$logger.debug(`Successfully prepared plugin ${pluginData.name} for ${platformData.normalizedPlatformName.toLowerCase()}.`);
2422
}
2523
}
2624
}

test/ios-project-service.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ function createTestInjector(projectPath: string, projectName: string, xCode?: IX
119119
});
120120
testInjector.register("iosDeviceOperations", {});
121121
testInjector.register("pluginsService", {
122-
getAllInstalledPlugins: (): string[] => []
122+
getAllInstalledPlugins: (): string[] => [],
123+
getAllProductionPlugins: (): string[] => [],
123124
});
124125
testInjector.register("androidProcessService", {});
125126
testInjector.register("sysInfo", {
@@ -323,7 +324,7 @@ describe("Cocoapods support", () => {
323324
};
324325
const projectData: IProjectData = testInjector.resolve("projectData");
325326
const pluginsService = testInjector.resolve("pluginsService");
326-
pluginsService.getAllInstalledPlugins = () => {
327+
pluginsService.getAllProductionPlugins = () => {
327328
return [samplePluginData];
328329
};
329330
const cocoapodsService = testInjector.resolve("cocoapodsService");
@@ -411,7 +412,7 @@ describe("Cocoapods support", () => {
411412
};
412413
const projectData: IProjectData = testInjector.resolve("projectData");
413414
const pluginsService = testInjector.resolve("pluginsService");
414-
pluginsService.getAllInstalledPlugins = () => {
415+
pluginsService.getAllProductionPlugins = () => {
415416
return [samplePluginData];
416417
};
417418
const cocoapodsService = testInjector.resolve("cocoapodsService");

test/plugins-service.ts

+2
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ function createTestInjector() {
150150
testInjector.register("cleanupService", {
151151
setShouldDispose: (shouldDispose: boolean): void => undefined
152152
});
153+
testInjector.register("nodeModulesDependenciesBuilder", {});
153154

154155
return testInjector;
155156
}
@@ -632,6 +633,7 @@ describe("Plugins service", () => {
632633
unitTestsInjector.register("injector", unitTestsInjector);
633634
unitTestsInjector.register("mobileHelper", MobileHelper);
634635
unitTestsInjector.register("devicePlatformsConstants", DevicePlatformsConstants);
636+
unitTestsInjector.register("nodeModulesDependenciesBuilder", {});
635637

636638
const pluginsService: PluginsService = unitTestsInjector.resolve(PluginsService);
637639
testData.pluginsService = pluginsService;

0 commit comments

Comments
 (0)