FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Kddimitrov/fix podfile detection in nested plugins by KristianDD · Pull Request #5075 · NativeScript/nativescript-cli · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .ts  (6) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
1 change: 1 addition & 0 deletions lib/definitions/plugins.d.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ interface IPluginsService {
addToPackageJson(plugin: string, version: string, isDev: boolean, projectDir: string): void;
removeFromPackageJson(plugin: string, projectDir: string): void;
getAllInstalledPlugins(projectData: IProjectData): Promise<IPluginData[]>;
getAllProductionPlugins(projectData: IProjectData, dependencies?: IDependencyData[]): IPluginData[];
ensureAllDependenciesAreInstalled(projectData: IProjectData): Promise<void>;

/**
Expand Down
11 changes: 5 additions & 6 deletions lib/services/ios-project-service.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
});
};

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

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

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

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

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

const pluginsService = <IPluginsService>this.$injector.resolve("pluginsService");
const allPlugins: IPluginData[] = await pluginsService.getAllInstalledPlugins(projectData);
const allPlugins: IPluginData[] = this.getAllProductionPlugins(projectData);
for (const plugin of allPlugins) {
const pluginPlatformsFolderPath = plugin.pluginPlatformsFolderPath(IOSProjectService.IOS_PLATFORM_NAME);
const pluginXcconfigFilePath = path.join(pluginPlatformsFolderPath, BUILD_XCCONFIG_FILE_NAME);
Expand Down
23 changes: 22 additions & 1 deletion lib/services/plugins-service.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ export class PluginsService implements IPluginsService {
private $errors: IErrors,
private $filesHashService: IFilesHashService,
private $injector: IInjector,
private $mobileHelper: Mobile.IMobileHelper) { }
private $mobileHelper: Mobile.IMobileHelper,
private $nodeModulesDependenciesBuilder: INodeModulesDependenciesBuilder) { }

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

//This method will traverse all non dev dependencies (not only the root/installed ones) and filter the plugins.
public getAllProductionPlugins(projectData: IProjectData, dependencies?: IDependencyData[]): IPluginData[] {
const allProductionPlugins: IPluginData[] = [];
dependencies = dependencies || this.$nodeModulesDependenciesBuilder.getProductionDependencies(projectData.projectDir);

if (_.isEmpty(dependencies)) {
return allProductionPlugins;
}

_.forEach(dependencies, dependency => {
const isPlugin = !!dependency.nativescript;
if (isPlugin) {
const pluginData = this.convertToPluginData(dependency, projectData.projectDir);
allProductionPlugins.push(pluginData);
}
});

return allProductionPlugins;
}

public getDependenciesFromPackageJson(projectDir: string): IPackageJsonDepedenciesResult {
const packageJson = this.$fs.readJson(this.getPackageJsonFilePath(projectDir));
const dependencies: IBasePluginData[] = this.getBasicPluginInformation(packageJson.dependencies);
Expand Down
18 changes: 8 additions & 10 deletions lib/tools/node-modules/node-modules-builder.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,18 @@ export class NodeModulesBuilder implements INodeModulesBuilder {

public async prepareNodeModules({platformData , projectData}: IPrepareNodeModulesData): Promise<void> {
const dependencies = this.$nodeModulesDependenciesBuilder.getProductionDependencies(projectData.projectDir);
if (_.isEmpty(dependencies)) {
await platformData.platformProjectService.beforePrepareAllPlugins(projectData, dependencies);

const pluginsData = this.$pluginsService.getAllProductionPlugins(projectData, dependencies);
if (_.isEmpty(pluginsData)) {
return;
}

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

for (const dependencyKey in dependencies) {
const dependency = dependencies[dependencyKey];
const isPlugin = !!dependency.nativescript;
if (isPlugin) {
this.$logger.debug(`Successfully prepared plugin ${dependency.name} for ${platformData.normalizedPlatformName.toLowerCase()}.`);
const pluginData = this.$pluginsService.convertToPluginData(dependency, projectData.projectDir);
await this.$pluginsService.preparePluginNativeCode({pluginData, platform: platformData.normalizedPlatformName.toLowerCase(), projectData});
}
await this.$pluginsService.preparePluginNativeCode({pluginData, platform: platformData.normalizedPlatformName.toLowerCase(), projectData});
this.$logger.debug(`Successfully prepared plugin ${pluginData.name} for ${platformData.normalizedPlatformName.toLowerCase()}.`);
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions test/ios-project-service.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ function createTestInjector(projectPath: string, projectName: string, xCode?: IX
});
testInjector.register("iosDeviceOperations", {});
testInjector.register("pluginsService", {
getAllInstalledPlugins: (): string[] => []
getAllInstalledPlugins: (): string[] => [],
getAllProductionPlugins: (): string[] => [],
});
testInjector.register("androidProcessService", {});
testInjector.register("sysInfo", {
Expand Down Expand Up @@ -323,7 +324,7 @@ describe("Cocoapods support", () => {
};
const projectData: IProjectData = testInjector.resolve("projectData");
const pluginsService = testInjector.resolve("pluginsService");
pluginsService.getAllInstalledPlugins = () => {
pluginsService.getAllProductionPlugins = () => {
return [samplePluginData];
};
const cocoapodsService = testInjector.resolve("cocoapodsService");
Expand Down Expand Up @@ -411,7 +412,7 @@ describe("Cocoapods support", () => {
};
const projectData: IProjectData = testInjector.resolve("projectData");
const pluginsService = testInjector.resolve("pluginsService");
pluginsService.getAllInstalledPlugins = () => {
pluginsService.getAllProductionPlugins = () => {
return [samplePluginData];
};
const cocoapodsService = testInjector.resolve("cocoapodsService");
Expand Down
2 changes: 2 additions & 0 deletions test/plugins-service.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ function createTestInjector() {
testInjector.register("cleanupService", {
setShouldDispose: (shouldDispose: boolean): void => undefined
});
testInjector.register("nodeModulesDependenciesBuilder", {});

return testInjector;
}
Expand Down Expand Up @@ -632,6 +633,7 @@ describe("Plugins service", () => {
unitTestsInjector.register("injector", unitTestsInjector);
unitTestsInjector.register("mobileHelper", MobileHelper);
unitTestsInjector.register("devicePlatformsConstants", DevicePlatformsConstants);
unitTestsInjector.register("nodeModulesDependenciesBuilder", {});

const pluginsService: PluginsService = unitTestsInjector.resolve(PluginsService);
testData.pluginsService = pluginsService;
Expand Down

Back | FazBrowse Home | New Git URL