From db5a1a88863c6544349a3c9f4ef3b645f05a90ff Mon Sep 17 00:00:00 2001 From: Panayot Cankov Date: Tue, 27 Jun 2017 15:20:52 +0300 Subject: [PATCH 1/2] fix android with webpack (#2925) --- lib/definitions/plugins.d.ts | 2 ++ lib/services/platform-service.ts | 19 +++++++++++++++++-- lib/services/plugins-service.ts | 4 ++-- test/platform-commands.ts | 1 + test/platform-service.ts | 1 + 5 files changed, 23 insertions(+), 4 deletions(-) diff --git a/lib/definitions/plugins.d.ts b/lib/definitions/plugins.d.ts index 99c50b7893..24926cd12a 100644 --- a/lib/definitions/plugins.d.ts +++ b/lib/definitions/plugins.d.ts @@ -12,6 +12,8 @@ interface IPluginsService { */ getDependenciesFromPackageJson(projectDir: string): IPackageJsonDepedenciesResult; validate(platformData: IPlatformData, projectData: IProjectData): Promise; + preparePluginNativeCode(pluginData: IPluginData, platform: string, projectData: IProjectData): Promise; + convertToPluginData(cacheData: any, projectDir: string): IPluginData; } interface IPackageJsonDepedenciesResult { diff --git a/lib/services/platform-service.ts b/lib/services/platform-service.ts index 8b92bc5a19..f1a3bd5b94 100644 --- a/lib/services/platform-service.ts +++ b/lib/services/platform-service.ts @@ -39,7 +39,8 @@ export class PlatformService extends EventEmitter implements IPlatformService { private $npm: INodePackageManager, private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants, private $projectChangesService: IProjectChangesService, - private $analyticsService: IAnalyticsService) { + private $analyticsService: IAnalyticsService, + private $nodeModulesDependenciesBuilder: INodeModulesDependenciesBuilder) { super(); } @@ -223,13 +224,17 @@ export class PlatformService extends EventEmitter implements IPlatformService { let platformData = this.$platformsData.getPlatformData(platform, projectData); await this.$pluginsService.validate(platformData, projectData); + const bundle = appFilesUpdaterOptions.bundle; + await this.ensurePlatformInstalled(platform, platformTemplate, projectData, config); - let changesInfo = this.$projectChangesService.checkForChanges(platform, projectData, { bundle: appFilesUpdaterOptions.bundle, release: appFilesUpdaterOptions.release, provision: config.provision }); + let changesInfo = this.$projectChangesService.checkForChanges(platform, projectData, { bundle, release: appFilesUpdaterOptions.release, provision: config.provision }); this.$logger.trace("Changes info in prepare platform:", changesInfo); if (changesInfo.hasChanges) { await this.cleanProject(platform, appFilesUpdaterOptions, platformData, projectData); + } + if (changesInfo.hasChanges || bundle) { await this.preparePlatformCore(platform, appFilesUpdaterOptions, projectData, config, changesInfo, filesToSync); this.$projectChangesService.savePrepareInfo(platform, projectData); } else { @@ -302,6 +307,16 @@ export class PlatformService extends EventEmitter implements IPlatformService { if (!changesInfo || changesInfo.modulesChanged) { await this.copyTnsModules(platform, projectData); + } else if (appFilesUpdaterOptions.bundle) { + let dependencies = this.$nodeModulesDependenciesBuilder.getProductionDependencies(projectData.projectDir); + for (let dependencyKey in dependencies) { + const dependency = dependencies[dependencyKey]; + let isPlugin = !!dependency.nativescript; + if (isPlugin) { + let pluginData = this.$pluginsService.convertToPluginData(dependency, projectData.projectDir); + await this.$pluginsService.preparePluginNativeCode(pluginData, platform, projectData); + } + } } let directoryPath = path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME); diff --git a/lib/services/plugins-service.ts b/lib/services/plugins-service.ts index c1fae529f9..df436d5e9d 100644 --- a/lib/services/plugins-service.ts +++ b/lib/services/plugins-service.ts @@ -139,7 +139,7 @@ export class PluginsService implements IPluginsService { this.$projectFilesManager.processPlatformSpecificFiles(pluginScriptsDestinationPath, platform); } - private async preparePluginNativeCode(pluginData: IPluginData, platform: string, projectData: IProjectData): Promise { + public async preparePluginNativeCode(pluginData: IPluginData, platform: string, projectData: IProjectData): Promise { let platformData = this.$platformsData.getPlatformData(platform, projectData); pluginData.pluginPlatformsFolderPath = (_platform: string) => path.join(pluginData.fullPath, "platforms", _platform); @@ -228,7 +228,7 @@ export class PluginsService implements IPluginsService { }; } - private convertToPluginData(cacheData: any, projectDir: string): IPluginData { + public convertToPluginData(cacheData: any, projectDir: string): IPluginData { let pluginData: any = {}; pluginData.name = cacheData.name; pluginData.version = cacheData.version; diff --git a/test/platform-commands.ts b/test/platform-commands.ts index 9c5b8ee2d9..63288c0261 100644 --- a/test/platform-commands.ts +++ b/test/platform-commands.ts @@ -96,6 +96,7 @@ function createTestInjector() { testInjector.register("injector", testInjector); testInjector.register("hooksService", stubs.HooksServiceStub); testInjector.register("staticConfig", StaticConfigLib.StaticConfig); + testInjector.register("nodeModulesDependenciesBuilder", {}); testInjector.register('platformService', PlatformServiceLib.PlatformService); testInjector.register('errors', ErrorsNoFailStub); testInjector.register('logger', stubs.LoggerStub); diff --git a/test/platform-service.ts b/test/platform-service.ts index d8898f0b26..e4ce0e5352 100644 --- a/test/platform-service.ts +++ b/test/platform-service.ts @@ -30,6 +30,7 @@ function createTestInjector() { testInjector.register('platformService', PlatformServiceLib.PlatformService); testInjector.register('errors', stubs.ErrorsStub); testInjector.register('logger', stubs.LoggerStub); + testInjector.register("nodeModulesDependenciesBuilder", {}); testInjector.register('npmInstallationManager', stubs.NpmInstallationManagerStub); testInjector.register('projectData', stubs.ProjectDataStub); testInjector.register('platformsData', stubs.PlatformsDataStub); From 94a3307172669bbde3eb1b60e323918c39a4870b Mon Sep 17 00:00:00 2001 From: rosen-vladimirov Date: Wed, 28 Jun 2017 00:09:07 +0300 Subject: [PATCH 2/2] Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a994e9ea7..2d88b73194 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ NativeScript CLI Changelog * [Fixed #2892](https://github.com/NativeScript/nativescript-cli/issues/2892): Not copying the CFBundleURLTypes from the plist file to the project * [Fixed #2916](https://github.com/NativeScript/nativescript-cli/issues/2916): If no device or emulator is attached `tns debug android` kills the commandline process and doesn't start an emulator * [Fixed #2923](https://github.com/NativeScript/nativescript-cli/issues/2923): Fix asking for user email on postinstall +* [Fixed #2929](https://github.com/NativeScript/nativescript-cli/issues/2929): Android release builds with webpack disregards plugin's gradle dependencies. 3.1.0 (2017, June 22)