Skip to content

Commit 4798951

Browse files
committed
fix: pods not detected in nested plugins
1 parent 0c79359 commit 4798951

File tree

4 files changed

+36
-17
lines changed

4 files changed

+36
-17
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 travers 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
}

0 commit comments

Comments
 (0)