From ea6eccc4ba05a83672555af3f7b9a371a0828fd0 Mon Sep 17 00:00:00 2001 From: fatme Date: Thu, 4 Jul 2019 15:00:02 +0300 Subject: [PATCH 1/5] fix: remove prepareReadyHandler on run command and don't provide deviceDescriptors as param to sync method --- lib/controllers/run-controller.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/controllers/run-controller.ts b/lib/controllers/run-controller.ts index 1237555a06..8a83b81849 100644 --- a/lib/controllers/run-controller.ts +++ b/lib/controllers/run-controller.ts @@ -4,6 +4,8 @@ import { cache, performanceLog } from "../common/decorators"; import { EventEmitter } from "events"; export class RunController extends EventEmitter implements IRunController { + private prepareReadyEventHandler: any = null; + constructor( protected $analyticsService: IAnalyticsService, private $buildController: IBuildController, @@ -45,9 +47,10 @@ export class RunController extends EventEmitter implements IRunController { this.$hmrStatusService.attachToHmrStatusEvent(); } - this.$prepareController.on(PREPARE_READY_EVENT_NAME, async data => { - await this.syncChangedDataOnDevices(data, projectData, liveSyncInfo, deviceDescriptors); - }); + if (!this.prepareReadyEventHandler) { + this.prepareReadyEventHandler = async (data: any) => await this.syncChangedDataOnDevices(data, projectData, liveSyncInfo); + this.$prepareController.on(PREPARE_READY_EVENT_NAME, this.prepareReadyEventHandler.bind(this)); + } await this.syncInitialDataOnDevices(projectData, liveSyncInfo, deviceDescriptorsForInitialSync); @@ -58,6 +61,11 @@ export class RunController extends EventEmitter implements IRunController { const { projectDir, deviceIdentifiers, stopOptions } = data; const liveSyncProcessInfo = this.$liveSyncProcessDataService.getPersistedData(projectDir); if (liveSyncProcessInfo && !liveSyncProcessInfo.isStopped) { + if (this.prepareReadyEventHandler) { + this.removeListener(PREPARE_READY_EVENT_NAME, this.prepareReadyEventHandler); + this.prepareReadyEventHandler = null; + } + // In case we are coming from error during livesync, the current action is the one that erred (but we are still executing it), // so we cannot await it as this will cause infinite loop. const shouldAwaitPendingOperation = !stopOptions || stopOptions.shouldAwaitAllActions; @@ -313,10 +321,11 @@ export class RunController extends EventEmitter implements IRunController { await this.addActionToChain(projectData.projectDir, () => this.$devicesService.execute(deviceAction, (device: Mobile.IDevice) => _.some(deviceDescriptors, deviceDescriptor => deviceDescriptor.identifier === device.deviceInfo.identifier))); } - private async syncChangedDataOnDevices(data: IFilesChangeEventData, projectData: IProjectData, liveSyncInfo: ILiveSyncInfo, deviceDescriptors: ILiveSyncDeviceDescriptor[]): Promise { + private async syncChangedDataOnDevices(data: IFilesChangeEventData, projectData: IProjectData, liveSyncInfo: ILiveSyncInfo): Promise { const rebuiltInformation: IDictionary<{ packageFilePath: string, platform: string, isEmulator: boolean }> = { }; const deviceAction = async (device: Mobile.IDevice) => { + const deviceDescriptors = this.$liveSyncProcessDataService.getDeviceDescriptors(projectData.projectDir); const deviceDescriptor = _.find(deviceDescriptors, dd => dd.identifier === device.deviceInfo.identifier); const platformData = this.$platformsDataService.getPlatformData(data.platform, projectData); const prepareData = this.$prepareDataService.getPrepareData(liveSyncInfo.projectDir, device.deviceInfo.platform, From 317f10b2e446e54c79e910aceba7e0464602590f Mon Sep 17 00:00:00 2001 From: fatme Date: Fri, 5 Jul 2019 10:39:56 +0300 Subject: [PATCH 2/5] fix: fix shouldBuild method when release cloud build is executed --- lib/controllers/build-controller.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/controllers/build-controller.ts b/lib/controllers/build-controller.ts index a5e0bbf2f2..ae421bd8d7 100644 --- a/lib/controllers/build-controller.ts +++ b/lib/controllers/build-controller.ts @@ -87,12 +87,12 @@ export class BuildController extends EventEmitter implements IBuildController { const projectData = this.$projectDataService.getProjectData(buildData.projectDir); const platformData = this.$platformsDataService.getPlatformData(buildData.platform, projectData); const outputPath = buildData.outputPath || platformData.getBuildOutputPath(buildData); + const changesInfo = this.$projectChangesService.currentChanges || await this.$projectChangesService.checkForChanges(platformData, projectData, buildData); - if (buildData.release && this.$projectChangesService.currentChanges.hasChanges) { + if (buildData.release && changesInfo.hasChanges) { return true; } - const changesInfo = this.$projectChangesService.currentChanges || await this.$projectChangesService.checkForChanges(platformData, projectData, buildData); if (changesInfo.changesRequireBuild) { return true; } From 2160190aba9b1bf5d0c486d016b871a6555fbb5e Mon Sep 17 00:00:00 2001 From: fatme Date: Fri, 5 Jul 2019 10:42:57 +0300 Subject: [PATCH 3/5] fix: execute checkForChanges before syncing changed files --- lib/controllers/run-controller.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/controllers/run-controller.ts b/lib/controllers/run-controller.ts index 8a83b81849..e2f1100685 100644 --- a/lib/controllers/run-controller.ts +++ b/lib/controllers/run-controller.ts @@ -25,6 +25,7 @@ export class RunController extends EventEmitter implements IRunController { private $prepareController: IPrepareController, private $prepareDataService: IPrepareDataService, private $prepareNativePlatformService: IPrepareNativePlatformService, + private $projectChangesService: IProjectChangesService, protected $projectDataService: IProjectDataService ) { super(); @@ -48,7 +49,18 @@ export class RunController extends EventEmitter implements IRunController { } if (!this.prepareReadyEventHandler) { - this.prepareReadyEventHandler = async (data: any) => await this.syncChangedDataOnDevices(data, projectData, liveSyncInfo); + this.prepareReadyEventHandler = async (data: IFilesChangeEventData) => { + if (data.hasNativeChanges) { + const platformData = this.$platformsDataService.getPlatformData(data.platform, projectData); + const prepareData = this.$prepareDataService.getPrepareData(liveSyncInfo.projectDir, data.platform, { ...liveSyncInfo, watch: !liveSyncInfo.skipWatcher }); + const changesInfo = await this.$projectChangesService.checkForChanges(platformData, projectData, prepareData); + if (changesInfo.hasChanges) { + await this.syncChangedDataOnDevices(data, projectData, liveSyncInfo); + } + } else { + await this.syncChangedDataOnDevices(data, projectData, liveSyncInfo); + } + }; this.$prepareController.on(PREPARE_READY_EVENT_NAME, this.prepareReadyEventHandler.bind(this)); } From 943b3bd4b2b379e2d71728faadfb865c9e06125a Mon Sep 17 00:00:00 2001 From: fatme Date: Fri, 5 Jul 2019 13:21:05 +0300 Subject: [PATCH 4/5] fix: fix call projectChangesService.checkForChanges regardless if skipNativePlatform is provided --- lib/controllers/build-controller.ts | 4 ---- lib/services/platform/prepare-native-platform-service.ts | 5 ++--- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/lib/controllers/build-controller.ts b/lib/controllers/build-controller.ts index ae421bd8d7..fc94dab0fa 100644 --- a/lib/controllers/build-controller.ts +++ b/lib/controllers/build-controller.ts @@ -89,10 +89,6 @@ export class BuildController extends EventEmitter implements IBuildController { const outputPath = buildData.outputPath || platformData.getBuildOutputPath(buildData); const changesInfo = this.$projectChangesService.currentChanges || await this.$projectChangesService.checkForChanges(platformData, projectData, buildData); - if (buildData.release && changesInfo.hasChanges) { - return true; - } - if (changesInfo.changesRequireBuild) { return true; } diff --git a/lib/services/platform/prepare-native-platform-service.ts b/lib/services/platform/prepare-native-platform-service.ts index 6b3549cb3f..1a9276beee 100644 --- a/lib/services/platform/prepare-native-platform-service.ts +++ b/lib/services/platform/prepare-native-platform-service.ts @@ -15,12 +15,11 @@ export class PrepareNativePlatformService implements IPrepareNativePlatformServi @hook('prepareNativeApp') public async prepareNativePlatform(platformData: IPlatformData, projectData: IProjectData, prepareData: IPrepareData): Promise { const { nativePrepare, release } = prepareData; + const changesInfo = await this.$projectChangesService.checkForChanges(platformData, projectData, prepareData); if (nativePrepare && nativePrepare.skipNativePrepare) { - return false; + return changesInfo.hasChanges; } - const changesInfo = await this.$projectChangesService.checkForChanges(platformData, projectData, prepareData); - const hasNativeModulesChange = !changesInfo || changesInfo.nativeChanged; const hasConfigChange = !changesInfo || changesInfo.configChanged; const hasChangesRequirePrepare = !changesInfo || changesInfo.changesRequirePrepare; From 342307fcee30b3cc372349ba741a85914f44e32c Mon Sep 17 00:00:00 2001 From: fatme Date: Fri, 5 Jul 2019 13:46:21 +0300 Subject: [PATCH 5/5] fix: remove from prepareReady event when we really stop the livesync process --- lib/controllers/run-controller.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/controllers/run-controller.ts b/lib/controllers/run-controller.ts index e2f1100685..bb46da92e5 100644 --- a/lib/controllers/run-controller.ts +++ b/lib/controllers/run-controller.ts @@ -73,10 +73,6 @@ export class RunController extends EventEmitter implements IRunController { const { projectDir, deviceIdentifiers, stopOptions } = data; const liveSyncProcessInfo = this.$liveSyncProcessDataService.getPersistedData(projectDir); if (liveSyncProcessInfo && !liveSyncProcessInfo.isStopped) { - if (this.prepareReadyEventHandler) { - this.removeListener(PREPARE_READY_EVENT_NAME, this.prepareReadyEventHandler); - this.prepareReadyEventHandler = null; - } // In case we are coming from error during livesync, the current action is the one that erred (but we are still executing it), // so we cannot await it as this will cause infinite loop. @@ -114,6 +110,11 @@ export class RunController extends EventEmitter implements IRunController { liveSyncProcessInfo.deviceDescriptors = []; + if (this.prepareReadyEventHandler) { + this.removeListener(PREPARE_READY_EVENT_NAME, this.prepareReadyEventHandler); + this.prepareReadyEventHandler = null; + } + const projectData = this.$projectDataService.getProjectData(projectDir); await this.$hooksService.executeAfterHooks('watch', { hookArgs: {