From 488791585787dfcabee1209623e87f674f537982 Mon Sep 17 00:00:00 2001 From: DimitarTachev Date: Mon, 15 Jul 2019 08:46:32 +0300 Subject: [PATCH 1/2] fix: do not validate invalid platforms versions --- lib/controllers/migrate-controller.ts | 4 ++++ lib/declarations.d.ts | 5 +++++ .../platform/platform-validation-service.ts | 17 ++++++++++++++--- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/controllers/migrate-controller.ts b/lib/controllers/migrate-controller.ts index 67b7cddcad..49c00bcd52 100644 --- a/lib/controllers/migrate-controller.ts +++ b/lib/controllers/migrate-controller.ts @@ -26,6 +26,7 @@ Running this command will ${MigrateController.COMMON_MIGRATE_MESSAGE}`; private $addPlatformService: IAddPlatformService, private $pluginsService: IPluginsService, private $projectDataService: IProjectDataService, + private $platformValidationService: IPlatformValidationService, private $resources: IResourceLoader) { super($fs, $platformCommandHelper, $platformsDataService, $packageInstallationManager, $packageManager, $pacoteService); } @@ -159,6 +160,9 @@ Running this command will ${MigrateController.COMMON_MIGRATE_MESSAGE}`; for (let platform of platforms) { platform = platform && platform.toLowerCase(); + if (!this.$platformValidationService.isValidPlatform(platform, projectData)) { + continue; + } const hasRuntimeDependency = this.hasRuntimeDependency({ platform, projectData }); if (hasRuntimeDependency && await this.shouldUpdateRuntimeVersion(this.verifiedPlatformVersions[platform.toLowerCase()], platform, projectData, allowInvalidVersions)) { diff --git a/lib/declarations.d.ts b/lib/declarations.d.ts index b1b2c43a64..389e2c17b7 100644 --- a/lib/declarations.d.ts +++ b/lib/declarations.d.ts @@ -1021,6 +1021,11 @@ interface IPlatformValidationService { */ validatePlatform(platform: string, projectData: IProjectData): void; + /** + * Returns whether the passed platform is a valid one (from the supported ones) + */ + isValidPlatform(platform: string, projectData: IProjectData): boolean; + /** * Gets first chance to validate the options provided as command line arguments. * If no platform is provided or a falsy (null, undefined, "", false...) platform is provided, diff --git a/lib/services/platform/platform-validation-service.ts b/lib/services/platform/platform-validation-service.ts index 6648803b51..2ac7981c9d 100644 --- a/lib/services/platform/platform-validation-service.ts +++ b/lib/services/platform/platform-validation-service.ts @@ -11,14 +11,25 @@ export class PlatformValidationService implements IPlatformValidationService { private $platformsDataService: IPlatformsDataService ) { } - public validatePlatform(platform: string, projectData: IProjectData): void { + public isValidPlatform(platform: string, projectData: IProjectData): boolean { if (!platform) { - this.$errors.fail("No platform specified."); + return false; } platform = platform.split("@")[0].toLowerCase(); - if (!this.$platformsDataService.getPlatformData(platform, projectData)) { + return false; + } + + return true; + } + + public validatePlatform(platform: string, projectData: IProjectData): void { + if (!platform) { + this.$errors.fail("No platform specified."); + } + + if (!this.isValidPlatform(platform, projectData)) { const platformNames = helpers.formatListOfNames(this.$mobileHelper.platformNames); this.$errors.fail(`Invalid platform ${platform}. Valid platforms are ${platformNames}.`); } From fd1ed04c8d8608c5350fad4eaf393931fa20d6fe Mon Sep 17 00:00:00 2001 From: DimitarTachev Date: Mon, 15 Jul 2019 09:15:25 +0300 Subject: [PATCH 2/2] fix: skip migration check based on the --force flag --- lib/commands/build.ts | 8 ++++++-- lib/commands/debug.ts | 4 +++- lib/commands/prepare.ts | 6 +++++- lib/commands/preview.ts | 4 +++- lib/commands/run.ts | 7 ++++++- lib/commands/test.ts | 4 +++- 6 files changed, 26 insertions(+), 7 deletions(-) diff --git a/lib/commands/build.ts b/lib/commands/build.ts index 912753e508..86686e4688 100644 --- a/lib/commands/build.ts +++ b/lib/commands/build.ts @@ -74,7 +74,9 @@ export class BuildIosCommand extends BuildCommandBase implements ICommand { public async canExecute(args: string[]): Promise { const platform = this.$devicePlatformsConstants.iOS; - await this.$migrateController.validate({ projectDir: this.$projectData.projectDir, platforms: [platform] }); + if (!this.$options.force) { + await this.$migrateController.validate({ projectDir: this.$projectData.projectDir, platforms: [platform] }); + } super.validatePlatform(platform); @@ -120,7 +122,9 @@ export class BuildAndroidCommand extends BuildCommandBase implements ICommand { public async canExecute(args: string[]): Promise { const platform = this.$devicePlatformsConstants.Android; - await this.$migrateController.validate({ projectDir: this.$projectData.projectDir, platforms: [platform] }); + if (!this.$options.force) { + await this.$migrateController.validate({ projectDir: this.$projectData.projectDir, platforms: [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 a9ca28acb0..1bdc9c50b3 100644 --- a/lib/commands/debug.ts +++ b/lib/commands/debug.ts @@ -53,7 +53,9 @@ export class DebugPlatformCommand extends ValidatePlatformCommandBase implements } public async canExecute(args: string[]): Promise { - await this.$migrateController.validate({ projectDir: this.$projectData.projectDir, platforms: [this.platform] }); + if (!this.$options.force) { + await this.$migrateController.validate({ projectDir: this.$projectData.projectDir, platforms: [this.platform] }); + } this.$androidBundleValidatorHelper.validateNoAab(); diff --git a/lib/commands/prepare.ts b/lib/commands/prepare.ts index 5faef3e149..0e42bdd1aa 100644 --- a/lib/commands/prepare.ts +++ b/lib/commands/prepare.ts @@ -33,7 +33,11 @@ export class PrepareCommand extends ValidatePlatformCommandBase implements IComm const platform = args[0]; const result = await this.$platformCommandParameter.validate(platform) && await this.$platformValidationService.validateOptions(this.$options.provision, this.$options.teamId, this.$projectData, platform); - await this.$migrateController.validate({ projectDir: this.$projectData.projectDir, platforms: [platform] }); + + if (!this.$options.force) { + await this.$migrateController.validate({ projectDir: this.$projectData.projectDir, platforms: [platform] }); + } + if (!result) { return false; } diff --git a/lib/commands/preview.ts b/lib/commands/preview.ts index 8f847fe5eb..21249fec62 100644 --- a/lib/commands/preview.ts +++ b/lib/commands/preview.ts @@ -41,7 +41,9 @@ export class PreviewCommand implements ICommand { this.$errors.fail(`The arguments '${args.join(" ")}' are not valid for the preview command.`); } - await this.$migrateController.validate({ projectDir: this.$projectData.projectDir, platforms: [] }); + if (!this.$options.force) { + await this.$migrateController.validate({ projectDir: this.$projectData.projectDir, platforms: [] }); + } await this.$networkConnectivityValidator.validate(); return true; diff --git a/lib/commands/run.ts b/lib/commands/run.ts index f5e3ef9861..7348c63c58 100644 --- a/lib/commands/run.ts +++ b/lib/commands/run.ts @@ -14,6 +14,7 @@ export class RunCommandBase implements ICommand { private $hostInfo: IHostInfo, private $liveSyncCommandHelper: ILiveSyncCommandHelper, private $migrateController: IMigrateController, + private $options: IOptions, private $projectData: IProjectData ) { } @@ -36,7 +37,11 @@ export class RunCommandBase implements ICommand { this.$androidBundleValidatorHelper.validateNoAab(); this.$projectData.initializeProjectData(); const platforms = this.platform ? [this.platform] : [this.$devicePlatformsConstants.Android, this.$devicePlatformsConstants.iOS]; - await this.$migrateController.validate({ projectDir: this.$projectData.projectDir, platforms }); + + if (!this.$options.force) { + await this.$migrateController.validate({ projectDir: this.$projectData.projectDir, platforms }); + } + await this.$liveSyncCommandHelper.validatePlatform(this.platform); return true; diff --git a/lib/commands/test.ts b/lib/commands/test.ts index 8f12bea759..e412e72ab0 100644 --- a/lib/commands/test.ts +++ b/lib/commands/test.ts @@ -49,7 +49,9 @@ abstract class TestCommandBase { } async canExecute(args: string[]): Promise { - await this.$migrateController.validate({ projectDir: this.$projectData.projectDir, platforms: [this.platform] }); + if (!this.$options.force) { + await this.$migrateController.validate({ projectDir: this.$projectData.projectDir, platforms: [this.platform] }); + } this.$projectData.initializeProjectData(); this.$analyticsService.setShouldDispose(this.$options.justlaunch || !this.$options.watch);