From 530fbf6d5fe5266f07056b83a53f587eb82305b0 Mon Sep 17 00:00:00 2001 From: fatme Date: Fri, 12 Oct 2018 13:13:25 +0300 Subject: [PATCH] fix: get correct hmr hash when more than one webpack processes are started --- lib/definitions/hmr-status-service.d.ts | 2 +- lib/definitions/livesync.d.ts | 7 ++++++- lib/services/hmr-status-service.ts | 4 ++-- .../livesync/android-livesync-service.ts | 2 +- lib/services/livesync/livesync-service.ts | 19 ++++++++----------- .../preview-app-livesync-service.ts | 12 +++++------- lib/services/log-parser-service.ts | 2 +- 7 files changed, 24 insertions(+), 24 deletions(-) diff --git a/lib/definitions/hmr-status-service.d.ts b/lib/definitions/hmr-status-service.d.ts index a652971440..2af5f4c3d7 100644 --- a/lib/definitions/hmr-status-service.d.ts +++ b/lib/definitions/hmr-status-service.d.ts @@ -1,4 +1,4 @@ interface IHmrStatusService { getHmrStatus(deviceId: string, operationHash: string): Promise; - attachToHrmStatusEvent(): void; + attachToHmrStatusEvent(): void; } \ No newline at end of file diff --git a/lib/definitions/livesync.d.ts b/lib/definitions/livesync.d.ts index d6619dadda..5904ec2430 100644 --- a/lib/definitions/livesync.d.ts +++ b/lib/definitions/livesync.d.ts @@ -356,7 +356,7 @@ interface ILiveSyncWatchInfo extends IProjectDataComposition, IHasUseHotModuleRe isReinstalled: boolean; syncAllFiles: boolean; liveSyncDeviceInfo: ILiveSyncDeviceInfo; - hmrData: { hash: string; fallbackFiles: IDictionary }; + hmrData: IPlatformHmrData; force?: boolean; } @@ -377,6 +377,11 @@ interface IFullSyncInfo extends IProjectDataComposition, IHasUseHotModuleReloadO force?: boolean; } +interface IPlatformHmrData { + hash: string; + fallbackFiles: string[]; +} + interface ITransferFilesOptions { isFullSync: boolean; force?: boolean; diff --git a/lib/services/hmr-status-service.ts b/lib/services/hmr-status-service.ts index 5c8cefeed4..2c3241c2c1 100644 --- a/lib/services/hmr-status-service.ts +++ b/lib/services/hmr-status-service.ts @@ -34,7 +34,7 @@ export class HmrStatusService implements IHmrStatusService { } @cache() - public attachToHrmStatusEvent(): void { + public attachToHmrStatusEvent(): void { this.$logParserService.addParseRule({ regex: HmrStatusService.HMR_STATUS_LOG_REGEX, handler: this.handleHmrStatusFound.bind(this), @@ -62,7 +62,7 @@ export class HmrStatusService implements IHmrStatusService { } } - this.$logger.trace("Found hmr status.", {status, hash}); + this.$logger.trace("Found hmr status.", { status, hash }); if (status) { this.setData(status, hash, deviceId); diff --git a/lib/services/livesync/android-livesync-service.ts b/lib/services/livesync/android-livesync-service.ts index e5bbb166e1..ddcdc75c7c 100644 --- a/lib/services/livesync/android-livesync-service.ts +++ b/lib/services/livesync/android-livesync-service.ts @@ -30,7 +30,7 @@ export class AndroidLiveSyncService extends PlatformLiveSyncServiceBase implemen // This is the case when the app has crashed and is in ErrorActivity. // As the app might not have time to apply the patches, we will send the whole bundle.js(fallbackFiles) if (liveSyncInfo.useHotModuleReload && !result.didRefresh && liveSyncInfo.hmrData && liveSyncInfo.hmrData.hash) { - liveSyncInfo.filesToSync = liveSyncInfo.hmrData.fallbackFiles[device.deviceInfo.platform]; + liveSyncInfo.filesToSync = liveSyncInfo.hmrData.fallbackFiles; result = await this.liveSyncWatchActionCore(device, liveSyncInfo); result.didRecover = true; } diff --git a/lib/services/livesync/livesync-service.ts b/lib/services/livesync/livesync-service.ts index 4ad472d760..ce73c52f33 100644 --- a/lib/services/livesync/livesync-service.ts +++ b/lib/services/livesync/livesync-service.ts @@ -565,7 +565,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi const patterns = await this.getWatcherPatterns(liveSyncData, projectData, platforms); if (liveSyncData.useHotModuleReload) { - this.$hmrStatusService.attachToHrmStatusEvent(); + this.$hmrStatusService.attachToHmrStatusEvent(); } if (liveSyncData.watchAllFiles) { @@ -586,10 +586,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi } let filesToSync: string[] = []; - const hmrData: { hash: string; fallbackFiles: IDictionary } = { - hash: "", - fallbackFiles: {} - }; + const hmrData: IDictionary = {}; const filesToSyncMap: IDictionary = {}; let filesToRemove: string[] = []; let timeoutTimer: NodeJS.Timer; @@ -635,6 +632,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi await this.$devicesService.execute(async (device: Mobile.IDevice) => { const liveSyncProcessInfo = this.liveSyncProcessesInfo[projectData.projectDir]; const deviceBuildInfoDescriptor = _.find(liveSyncProcessInfo.deviceDescriptors, dd => dd.identifier === device.deviceInfo.identifier); + const platformHmrData = (currentHmrData && currentHmrData[device.deviceInfo.platform]) || {}; const settings: ILiveSyncWatchInfo = { liveSyncDeviceInfo: deviceBuildInfoDescriptor, @@ -643,7 +641,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi filesToSync: currentFilesToSync, isReinstalled: false, syncAllFiles: liveSyncData.watchAllFiles, - hmrData: currentHmrData, + hmrData: platformHmrData, useHotModuleReload: liveSyncData.useHotModuleReload, force: liveSyncData.force, connectTimeout: 1000 @@ -657,10 +655,10 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi await this.refreshApplication(projectData, liveSyncResultInfo, deviceBuildInfoDescriptor.debugOptions, deviceBuildInfoDescriptor.outputPath); // If didRecover is true, this means we were in ErrorActivity and fallback files were already transfered and app will be restarted. - if (!liveSyncResultInfo.didRecover && liveSyncData.useHotModuleReload && currentHmrData.hash) { - const status = await this.$hmrStatusService.getHmrStatus(device.deviceInfo.identifier, currentHmrData.hash); + if (!liveSyncResultInfo.didRecover && liveSyncData.useHotModuleReload && platformHmrData.hash) { + const status = await this.$hmrStatusService.getHmrStatus(device.deviceInfo.identifier, platformHmrData.hash); if (status === HmrConstants.HMR_ERROR_STATUS) { - watchInfo.filesToSync = currentHmrData.fallbackFiles[device.deviceInfo.platform]; + watchInfo.filesToSync = platformHmrData.fallbackFiles; liveSyncResultInfo = await service.liveSyncWatchAction(device, watchInfo); // We want to force a restart of the application. liveSyncResultInfo.isFullSync = true; @@ -703,8 +701,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi settings.connectTimeout = null; if (liveSyncData.useHotModuleReload && appInstalledOnDeviceResult.appInstalled) { - const additionalFilesToSync = currentHmrData && currentHmrData.fallbackFiles && currentHmrData.fallbackFiles[device.deviceInfo.platform]; - _.each(additionalFilesToSync, fileToSync => currentFilesToSync.push(fileToSync)); + _.each(platformHmrData.fallbackFiles, fileToSync => currentFilesToSync.push(fileToSync)); } await watchAction(settings); diff --git a/lib/services/livesync/playground/preview-app-livesync-service.ts b/lib/services/livesync/playground/preview-app-livesync-service.ts index 9a23e12da1..8ea4af7c54 100644 --- a/lib/services/livesync/playground/preview-app-livesync-service.ts +++ b/lib/services/livesync/playground/preview-app-livesync-service.ts @@ -54,27 +54,25 @@ export class PreviewAppLiveSyncService implements IPreviewAppLiveSyncService { private async initializePreviewForDevice(data: IPreviewAppLiveSyncData, device: Device): Promise { const filesToSyncMap: IDictionary = {}; - const hmrData: { hash: string; fallbackFiles: IDictionary } = { - hash: "", - fallbackFiles: {} - }; + const hmrData: IDictionary = {}; let promise = Promise.resolve(null); const startSyncFilesTimeout = async (platform: string) => { await promise .then(async () => { const currentHmrData = _.cloneDeep(hmrData); + const platformHmrData = currentHmrData[platform] || {}; const filesToSync = _.cloneDeep(filesToSyncMap[platform]); // We don't need to prepare when webpack emits changed files. We just need to send a message to pubnub. promise = this.syncFilesForPlatformSafe(data, platform, { filesToSync, skipPrepare: true, useHotModuleReload: data.appFilesUpdaterOptions.useHotModuleReload }); await promise; - if (data.appFilesUpdaterOptions.useHotModuleReload && currentHmrData.hash) { + if (data.appFilesUpdaterOptions.useHotModuleReload && platformHmrData.hash) { const devices = _.filter(this.$previewSdkService.connectedDevices, { platform: platform.toLowerCase() }); await Promise.all(_.map(devices, async (previewDevice: Device) => { - const status = await this.$hmrStatusService.getHmrStatus(previewDevice.id, currentHmrData.hash); + const status = await this.$hmrStatusService.getHmrStatus(previewDevice.id, platformHmrData.hash); if (status === HmrConstants.HMR_ERROR_STATUS) { - await this.syncFilesForPlatformSafe(data, platform, { filesToSync: currentHmrData.fallbackFiles[platform], useHotModuleReload: false, deviceId: previewDevice.id }); + await this.syncFilesForPlatformSafe(data, platform, { filesToSync: platformHmrData.fallbackFiles, useHotModuleReload: false, deviceId: previewDevice.id }); } })); } diff --git a/lib/services/log-parser-service.ts b/lib/services/log-parser-service.ts index 1f06bc151f..77616a9c99 100644 --- a/lib/services/log-parser-service.ts +++ b/lib/services/log-parser-service.ts @@ -29,7 +29,7 @@ export class LogParserService extends EventEmitter implements ILogParserService private processDeviceLogResponse(message: string, deviceIdentifier: string, devicePlatform: string) { const lines = message.split("\n"); _.forEach(lines, line => { - _.forEach(this.parseRules, (parseRule) => { + _.forEach(this.parseRules, parseRule => { if (!devicePlatform || !parseRule.platform || parseRule.platform.toLowerCase() === devicePlatform.toLowerCase()) { const matches = parseRule.regex.exec(line);