From 1c73c8fa0f45a9ca0562d7deeeb6a468cd5b5f77 Mon Sep 17 00:00:00 2001 From: fatme Date: Wed, 3 Jul 2019 08:41:41 +0300 Subject: [PATCH 1/6] feat: validate the version of nativescript-dev-webpack on each command --- lib/common/services/commands-service.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/common/services/commands-service.ts b/lib/common/services/commands-service.ts index b4bb6566d0..294ccd6fba 100644 --- a/lib/common/services/commands-service.ts +++ b/lib/common/services/commands-service.ts @@ -28,7 +28,8 @@ export class CommandsService implements ICommandsService { private $helpService: IHelpService, private $extensibilityService: IExtensibilityService, private $optionsTracker: IOptionsTracker, - private $projectDataService: IProjectDataService) { + private $projectDataService: IProjectDataService, + private $bundleValidatorHelper: IBundleValidatorHelper) { } public allCommands(opts: { includeDevCommands: boolean }): string[] { @@ -115,6 +116,8 @@ export class CommandsService implements ICommandsService { const dashedOptions = command ? command.dashedOptions : null; this.$options.validateOptions(dashedOptions, projectData); + + this.$bundleValidatorHelper.validate(projectData, "1.0.0"); } return this.canExecuteCommand(commandName, commandArguments); From ac63ef68f0e951961fc6eb624b775d311d17aaa2 Mon Sep 17 00:00:00 2001 From: fatme Date: Wed, 3 Jul 2019 08:44:01 +0300 Subject: [PATCH 2/6] fix: remove bundle plugin validation from commands As we've already moved the logic for validation the version of nativescript-dev-webpack plugin to commandsService, there is no need to validate it again from commands. --- lib/commands/build.ts | 10 ++-------- lib/commands/debug.ts | 5 ----- lib/commands/deploy.ts | 2 -- lib/commands/preview.ts | 3 --- lib/helpers/livesync-command-helper.ts | 6 ------ 5 files changed, 2 insertions(+), 24 deletions(-) diff --git a/lib/commands/build.ts b/lib/commands/build.ts index 6acdb2c8f0..c665231967 100644 --- a/lib/commands/build.ts +++ b/lib/commands/build.ts @@ -9,7 +9,6 @@ export abstract class BuildCommandBase extends ValidatePlatformCommandBase { protected $devicePlatformsConstants: Mobile.IDevicePlatformsConstants, protected $buildController: IBuildController, $platformValidationService: IPlatformValidationService, - private $bundleValidatorHelper: IBundleValidatorHelper, private $buildDataService: IBuildDataService, protected $logger: ILogger) { super($options, $platformsDataService, $platformValidationService, $projectData); @@ -33,8 +32,6 @@ export abstract class BuildCommandBase extends ValidatePlatformCommandBase { if (!this.$platformValidationService.isPlatformSupportedForOS(platform, this.$projectData)) { this.$errors.fail(`Applications for platform ${platform} can not be built on this OS`); } - - this.$bundleValidatorHelper.validate(this.$projectData); } protected async validateArgs(args: string[], platform: string): Promise { @@ -65,10 +62,9 @@ export class BuildIosCommand extends BuildCommandBase implements ICommand { $devicePlatformsConstants: Mobile.IDevicePlatformsConstants, $buildController: IBuildController, $platformValidationService: IPlatformValidationService, - $bundleValidatorHelper: IBundleValidatorHelper, $logger: ILogger, $buildDataService: IBuildDataService) { - super($options, $errors, $projectData, $platformsDataService, $devicePlatformsConstants, $buildController, $platformValidationService, $bundleValidatorHelper, $buildDataService, $logger); + super($options, $errors, $projectData, $platformsDataService, $devicePlatformsConstants, $buildController, $platformValidationService, $buildDataService, $logger); } public async execute(args: string[]): Promise { @@ -101,11 +97,10 @@ export class BuildAndroidCommand extends BuildCommandBase implements ICommand { $devicePlatformsConstants: Mobile.IDevicePlatformsConstants, $buildController: IBuildController, $platformValidationService: IPlatformValidationService, - $bundleValidatorHelper: IBundleValidatorHelper, protected $androidBundleValidatorHelper: IAndroidBundleValidatorHelper, $buildDataService: IBuildDataService, protected $logger: ILogger) { - super($options, $errors, $projectData, platformsDataService, $devicePlatformsConstants, $buildController, $platformValidationService, $bundleValidatorHelper, $buildDataService, $logger); + super($options, $errors, $projectData, platformsDataService, $devicePlatformsConstants, $buildController, $platformValidationService, $buildDataService, $logger); } public async execute(args: string[]): Promise { @@ -122,7 +117,6 @@ export class BuildAndroidCommand extends BuildCommandBase implements ICommand { public async canExecute(args: string[]): Promise { const platform = this.$devicePlatformsConstants.Android; - super.validatePlatform(platform); this.$androidBundleValidatorHelper.validateRuntimeVersion(this.$projectData); let result = await super.canExecuteCommandBase(platform, { notConfiguredEnvOptions: { hideSyncToPreviewAppOption: true } }); if (result.canExecute) { diff --git a/lib/commands/debug.ts b/lib/commands/debug.ts index 3317b632df..f606d9b418 100644 --- a/lib/commands/debug.ts +++ b/lib/commands/debug.ts @@ -1,12 +1,10 @@ import { cache } from "../common/decorators"; import { ValidatePlatformCommandBase } from "./command-base"; -import { LiveSyncCommandHelper } from "../helpers/livesync-command-helper"; export class DebugPlatformCommand extends ValidatePlatformCommandBase implements ICommand { public allowedParameters: ICommandParameter[] = []; constructor(private platform: string, - private $bundleValidatorHelper: IBundleValidatorHelper, protected $devicesService: Mobile.IDevicesService, $platformValidationService: IPlatformValidationService, $projectData: IProjectData, @@ -64,9 +62,6 @@ export class DebugPlatformCommand extends ValidatePlatformCommandBase implements this.$errors.fail("--release flag is not applicable to this command"); } - const minSupportedWebpackVersion = this.$options.hmr ? LiveSyncCommandHelper.MIN_SUPPORTED_WEBPACK_VERSION_WITH_HMR : null; - this.$bundleValidatorHelper.validate(this.$projectData, minSupportedWebpackVersion); - const result = await super.canExecuteCommandBase(this.platform, { validateOptions: true, notConfiguredEnvOptions: { hideCloudBuildOption: true, hideSyncToPreviewAppOption: true } }); return result; } diff --git a/lib/commands/deploy.ts b/lib/commands/deploy.ts index aa7f613e95..ae414976c6 100644 --- a/lib/commands/deploy.ts +++ b/lib/commands/deploy.ts @@ -17,7 +17,6 @@ export class DeployOnDeviceCommand extends ValidatePlatformCommandBase implement private $errors: IErrors, private $mobileHelper: Mobile.IMobileHelper, $platformsDataService: IPlatformsDataService, - private $bundleValidatorHelper: IBundleValidatorHelper, private $deployCommandHelper: DeployCommandHelper, private $androidBundleValidatorHelper: IAndroidBundleValidatorHelper) { super($options, $platformsDataService, $platformValidationService, $projectData); @@ -31,7 +30,6 @@ export class DeployOnDeviceCommand extends ValidatePlatformCommandBase implement public async canExecute(args: string[]): Promise { this.$androidBundleValidatorHelper.validateNoAab(); - this.$bundleValidatorHelper.validate(this.$projectData); if (!args || !args.length || args.length > 1) { return false; } diff --git a/lib/commands/preview.ts b/lib/commands/preview.ts index a8bffb0bc4..a6a4e2bb4a 100644 --- a/lib/commands/preview.ts +++ b/lib/commands/preview.ts @@ -2,10 +2,8 @@ import { DEVICE_LOG_EVENT_NAME } from "../common/constants"; export class PreviewCommand implements ICommand { public allowedParameters: ICommandParameter[] = []; - private static MIN_SUPPORTED_WEBPACK_VERSION = "0.17.0"; constructor(private $analyticsService: IAnalyticsService, - private $bundleValidatorHelper: IBundleValidatorHelper, private $errors: IErrors, private $logger: ILogger, private $previewAppController: IPreviewAppController, @@ -43,7 +41,6 @@ export class PreviewCommand implements ICommand { } await this.$networkConnectivityValidator.validate(); - this.$bundleValidatorHelper.validate(this.$projectData, PreviewCommand.MIN_SUPPORTED_WEBPACK_VERSION); return true; } } diff --git a/lib/helpers/livesync-command-helper.ts b/lib/helpers/livesync-command-helper.ts index ac58ac0976..ea2fbc1e5d 100644 --- a/lib/helpers/livesync-command-helper.ts +++ b/lib/helpers/livesync-command-helper.ts @@ -2,8 +2,6 @@ import { RunOnDeviceEvents } from "../constants"; import { DeployController } from "../controllers/deploy-controller"; export class LiveSyncCommandHelper implements ILiveSyncCommandHelper { - public static MIN_SUPPORTED_WEBPACK_VERSION_WITH_HMR = "0.17.0"; - constructor( private $buildDataService: IBuildDataService, private $projectData: IProjectData, @@ -15,7 +13,6 @@ export class LiveSyncCommandHelper implements ILiveSyncCommandHelper { private $injector: IInjector, private $buildController: IBuildController, private $analyticsService: IAnalyticsService, - private $bundleValidatorHelper: IBundleValidatorHelper, private $errors: IErrors, private $iOSSimulatorLogProvider: Mobile.IiOSSimulatorLogProvider, private $cleanupService: ICleanupService, @@ -133,9 +130,6 @@ export class LiveSyncCommandHelper implements ILiveSyncCommandHelper { result[availablePlatform.toLowerCase()] = validateOutput; } - const minSupportedWebpackVersion = this.$options.hmr ? LiveSyncCommandHelper.MIN_SUPPORTED_WEBPACK_VERSION_WITH_HMR : null; - this.$bundleValidatorHelper.validate(this.$projectData, minSupportedWebpackVersion); - return result; } From 5dc21badf26d3e1afe060dae0dd931c1442760bb Mon Sep 17 00:00:00 2001 From: fatme Date: Wed, 3 Jul 2019 09:13:30 +0300 Subject: [PATCH 3/6] chore: fix unit tests --- test/platform-commands.ts | 3 +++ test/plugins-service.ts | 3 +++ 2 files changed, 6 insertions(+) diff --git a/test/platform-commands.ts b/test/platform-commands.ts index 0a3808baa5..8c65ae494f 100644 --- a/test/platform-commands.ts +++ b/test/platform-commands.ts @@ -187,6 +187,9 @@ function createTestInjector() { testInjector.register("addPlatformService", {}); testInjector.register("platformController", {}); testInjector.register("platformCommandHelper", PlatformCommandHelper); + testInjector.register("bundleValidatorHelper", { + validate: () => ({}) + }); return testInjector; } diff --git a/test/plugins-service.ts b/test/plugins-service.ts index cb44b1436f..d299ce44f8 100644 --- a/test/plugins-service.ts +++ b/test/plugins-service.ts @@ -150,6 +150,9 @@ function createTestInjector() { testInjector.register("cleanupService", { setShouldDispose: (shouldDispose: boolean): void => undefined }); + testInjector.register("bundleValidatorHelper", { + validate: () => ({}) + }); return testInjector; } From da1870e196f15ebcc510b9eb4b548b5c8263077a Mon Sep 17 00:00:00 2001 From: fatme Date: Wed, 3 Jul 2019 17:17:25 +0300 Subject: [PATCH 4/6] fix: validate the version of nativescript-dev-webpack plugin from prepare-controller --- lib/commands/preview.ts | 2 ++ lib/common/services/commands-service.ts | 5 +---- lib/controllers/prepare-controller.ts | 5 ++++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/commands/preview.ts b/lib/commands/preview.ts index a6a4e2bb4a..f891b5fca9 100644 --- a/lib/commands/preview.ts +++ b/lib/commands/preview.ts @@ -4,6 +4,7 @@ export class PreviewCommand implements ICommand { public allowedParameters: ICommandParameter[] = []; constructor(private $analyticsService: IAnalyticsService, + private $bundleValidatorHelper: IBundleValidatorHelper, private $errors: IErrors, private $logger: ILogger, private $previewAppController: IPreviewAppController, @@ -41,6 +42,7 @@ export class PreviewCommand implements ICommand { } await this.$networkConnectivityValidator.validate(); + this.$bundleValidatorHelper.validate(this.$projectData, "1.0.0"); return true; } } diff --git a/lib/common/services/commands-service.ts b/lib/common/services/commands-service.ts index 294ccd6fba..b4bb6566d0 100644 --- a/lib/common/services/commands-service.ts +++ b/lib/common/services/commands-service.ts @@ -28,8 +28,7 @@ export class CommandsService implements ICommandsService { private $helpService: IHelpService, private $extensibilityService: IExtensibilityService, private $optionsTracker: IOptionsTracker, - private $projectDataService: IProjectDataService, - private $bundleValidatorHelper: IBundleValidatorHelper) { + private $projectDataService: IProjectDataService) { } public allCommands(opts: { includeDevCommands: boolean }): string[] { @@ -116,8 +115,6 @@ export class CommandsService implements ICommandsService { const dashedOptions = command ? command.dashedOptions : null; this.$options.validateOptions(dashedOptions, projectData); - - this.$bundleValidatorHelper.validate(projectData, "1.0.0"); } return this.canExecuteCommand(commandName, commandArguments); diff --git a/lib/controllers/prepare-controller.ts b/lib/controllers/prepare-controller.ts index 29b9be2b2a..402538101c 100644 --- a/lib/controllers/prepare-controller.ts +++ b/lib/controllers/prepare-controller.ts @@ -17,6 +17,7 @@ export class PrepareController extends EventEmitter { private persistedData: IFilesChangeEventData[] = []; constructor( + private $bundleValidatorHelper: IBundleValidatorHelper, private $platformController: IPlatformController, public $hooksService: IHooksService, private $logger: ILogger, @@ -32,12 +33,14 @@ export class PrepareController extends EventEmitter { @performanceLog() @hook("prepare") public async prepare(prepareData: IPrepareData): Promise { + const projectData = this.$projectDataService.getProjectData(prepareData.projectDir); + this.$bundleValidatorHelper.validate(projectData, "1.0.0"); + await this.$platformController.addPlatformIfNeeded(prepareData); this.$logger.info("Preparing project..."); let result = null; - const projectData = this.$projectDataService.getProjectData(prepareData.projectDir); const platformData = this.$platformsDataService.getPlatformData(prepareData.platform, projectData); if (prepareData.watch) { From 6aeac225f5263f8cd3c9f1cc73e8f7c6330b271e Mon Sep 17 00:00:00 2001 From: fatme Date: Wed, 3 Jul 2019 17:20:01 +0300 Subject: [PATCH 5/6] fix: don't show the help on run command when the version of nativescript-dev-webpack is lower than 1.0.0 --- lib/common/mobile/mobile-core/devices-service.ts | 7 ++++--- lib/services/project-changes-service.ts | 5 ++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/common/mobile/mobile-core/devices-service.ts b/lib/common/mobile/mobile-core/devices-service.ts index 4a139363a6..347f5d5c52 100644 --- a/lib/common/mobile/mobile-core/devices-service.ts +++ b/lib/common/mobile/mobile-core/devices-service.ts @@ -444,6 +444,7 @@ export class DevicesService extends EventEmitter implements Mobile.IDevicesServi } } catch (err) { err.deviceIdentifier = device.deviceInfo.identifier; + this.$logger.trace(`Error while executing action on device ${device.deviceInfo.identifier}. The error is ${err}`); errors.push(err); } } @@ -454,9 +455,9 @@ export class DevicesService extends EventEmitter implements Mobile.IDevicesServi preErrorMsg = "Multiple errors were thrown:" + EOL; } - const singleError = (new Error(`${preErrorMsg}${errors.map(e => e.message || e).join(EOL)}`)); - singleError.allErrors = errors; - throw singleError; + const errorMessage = `${preErrorMsg}${errors.map(e => e.message || e).join(EOL)}`; + const suppressCommandHelp = _.some(errors, (e: any) => e.suppressCommandHelp); + this.$errors.fail({ formatStr: errorMessage, suppressCommandHelp }); } return result; diff --git a/lib/services/project-changes-service.ts b/lib/services/project-changes-service.ts index c539525cc7..a82a9a009c 100644 --- a/lib/services/project-changes-service.ts +++ b/lib/services/project-changes-service.ts @@ -1,7 +1,6 @@ import * as path from "path"; import { NativePlatformStatus, PACKAGE_JSON_FILE_NAME, APP_GRADLE_FILE_NAME, BUILD_XCCONFIG_FILE_NAME, PLATFORMS_DIR_NAME } from "../constants"; import { getHash, hook } from "../common/helpers"; -import { PrepareData } from "../data/prepare-data"; const prepareInfoFileName = ".nsprepareinfo"; @@ -51,7 +50,7 @@ export class ProjectChangesService implements IProjectChangesService { } @hook("checkForChanges") - public async checkForChanges(platformData: IPlatformData, projectData: IProjectData, prepareData: PrepareData): Promise { + public async checkForChanges(platformData: IPlatformData, projectData: IProjectData, prepareData: IPrepareData): Promise { this._changesInfo = new ProjectChangesInfo(); const isNewPrepareInfo = await this.ensurePrepareInfo(platformData, projectData, prepareData); if (!isNewPrepareInfo) { @@ -158,7 +157,7 @@ export class ProjectChangesService implements IProjectChangesService { await this.savePrepareInfo(platformData, projectData, null); } - private async ensurePrepareInfo(platformData: IPlatformData, projectData: IProjectData, prepareData: PrepareData): Promise { + private async ensurePrepareInfo(platformData: IPlatformData, projectData: IProjectData, prepareData: IPrepareData): Promise { this._prepareInfo = this.getPrepareInfo(platformData); if (this._prepareInfo) { const prepareInfoFile = path.join(platformData.projectRoot, prepareInfoFileName); From 5c2e869524a4713e9968cf15202aad73969fe2f4 Mon Sep 17 00:00:00 2001 From: fatme Date: Thu, 4 Jul 2019 08:29:00 +0300 Subject: [PATCH 6/6] chore: fix unit tests --- test/controllers/prepare-controller.ts | 4 ++++ test/platform-commands.ts | 3 --- test/plugins-service.ts | 3 --- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/test/controllers/prepare-controller.ts b/test/controllers/prepare-controller.ts index ef0b4a0fd0..78b4af2d43 100644 --- a/test/controllers/prepare-controller.ts +++ b/test/controllers/prepare-controller.ts @@ -54,6 +54,10 @@ function createTestInjector(data: { hasNativeChanges: boolean }): IInjector { isFileInIgnoreList: () => false }); + injector.register("bundleValidatorHelper", { + validate: () => ({}) + }); + const prepareController: PrepareController = injector.resolve("prepareController"); prepareController.emit = (eventName: string, eventData: any) => { emittedEventNames.push(eventName); diff --git a/test/platform-commands.ts b/test/platform-commands.ts index 8c65ae494f..0a3808baa5 100644 --- a/test/platform-commands.ts +++ b/test/platform-commands.ts @@ -187,9 +187,6 @@ function createTestInjector() { testInjector.register("addPlatformService", {}); testInjector.register("platformController", {}); testInjector.register("platformCommandHelper", PlatformCommandHelper); - testInjector.register("bundleValidatorHelper", { - validate: () => ({}) - }); return testInjector; } diff --git a/test/plugins-service.ts b/test/plugins-service.ts index d299ce44f8..cb44b1436f 100644 --- a/test/plugins-service.ts +++ b/test/plugins-service.ts @@ -150,9 +150,6 @@ function createTestInjector() { testInjector.register("cleanupService", { setShouldDispose: (shouldDispose: boolean): void => undefined }); - testInjector.register("bundleValidatorHelper", { - validate: () => ({}) - }); return testInjector; }