@@ -4,7 +4,7 @@ import { EOL } from "os";
44import { EventEmitter } from "events" ;
55import { hook } from "../../common/helpers" ;
66import { PACKAGE_JSON_FILE_NAME , LiveSyncTrackActionNames , USER_INTERACTION_NEEDED_EVENT_NAME , DEBUGGER_ATTACHED_EVENT_NAME , DEBUGGER_DETACHED_EVENT_NAME , TrackActionNames } from "../../constants" ;
7- import { DeviceTypes , DeviceDiscoveryEventNames } from "../../common/constants" ;
7+ import { DeviceTypes , DeviceDiscoveryEventNames , HmrConstants } from "../../common/constants" ;
88import { cache } from "../../common/decorators" ;
99
1010const deviceDescriptorPrimaryKey = "identifier" ;
@@ -38,6 +38,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
3838 private $analyticsService : IAnalyticsService ,
3939 private $usbLiveSyncService : DeprecatedUsbLiveSyncService ,
4040 private $previewAppLiveSyncService : IPreviewAppLiveSyncService ,
41+ private $hmrStatusService : IHmrStatusService ,
4142 private $injector : IInjector ) {
4243 super ( ) ;
4344 }
@@ -147,8 +148,6 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
147148 deviceIdentifier : liveSyncResultInfo . deviceAppData . device . deviceInfo . identifier ,
148149 isFullSync : liveSyncResultInfo . isFullSync
149150 } ) ;
150-
151- this . $logger . info ( `Successfully synced application ${ liveSyncResultInfo . deviceAppData . appIdentifier } on device ${ liveSyncResultInfo . deviceAppData . device . deviceInfo . identifier } .` ) ;
152151 }
153152
154153 private async refreshApplicationWithDebug ( projectData : IProjectData , liveSyncResultInfo : ILiveSyncResultInfo , debugOptions : IDebugOptions , outputPath ?: string ) : Promise < IDebugInformation > {
@@ -518,6 +517,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
518517
519518 await this . $platformService . trackActionForPlatform ( { action : "LiveSync" , platform : device . deviceInfo . platform , isForDevice : ! device . isEmulator , deviceOsVersion : device . deviceInfo . version } ) ;
520519 await this . refreshApplication ( projectData , liveSyncResultInfo , deviceBuildInfoDescriptor . debugOptions , deviceBuildInfoDescriptor . outputPath ) ;
520+ this . $logger . info ( `Successfully synced application ${ liveSyncResultInfo . deviceAppData . appIdentifier } on device ${ liveSyncResultInfo . deviceAppData . device . deviceInfo . identifier } .` ) ;
521521
522522 this . emitLivesyncEvent ( LiveSyncEvents . liveSyncStarted , {
523523 projectDir : projectData . projectDir ,
@@ -564,6 +564,10 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
564564 const platforms = _ ( devices ) . map ( device => device . deviceInfo . platform ) . uniq ( ) . value ( ) ;
565565 const patterns = await this . getWatcherPatterns ( liveSyncData , projectData , platforms ) ;
566566
567+ if ( liveSyncData . useHotModuleReload ) {
568+ this . $hmrStatusService . attachToHrmStatusEvent ( ) ;
569+ }
570+
567571 if ( liveSyncData . watchAllFiles ) {
568572 const productionDependencies = this . $nodeModulesDependenciesBuilder . getProductionDependencies ( projectData . projectDir ) ;
569573 patterns . push ( PACKAGE_JSON_FILE_NAME ) ;
@@ -582,6 +586,10 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
582586 }
583587
584588 let filesToSync : string [ ] = [ ] ;
589+ const hmrData : { hash : string ; fallbackFiles : IDictionary < string [ ] > } = {
590+ hash : "" ,
591+ fallbackFiles : { }
592+ } ;
585593 const filesToSyncMap : IDictionary < string [ ] > = { } ;
586594 let filesToRemove : string [ ] = [ ] ;
587595 let timeoutTimer : NodeJS . Timer ;
@@ -610,6 +618,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
610618 if ( filesToSync . length || filesToRemove . length ) {
611619 try {
612620 const currentFilesToSync = _ . cloneDeep ( filesToSync ) ;
621+ const currentHmrData = _ . cloneDeep ( hmrData ) ;
613622 filesToSync . splice ( 0 , filesToSync . length ) ;
614623
615624 const currentFilesToRemove = _ . cloneDeep ( filesToRemove ) ;
@@ -655,8 +664,21 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
655664 force : liveSyncData . force
656665 } ;
657666
658- const liveSyncResultInfo = await service . liveSyncWatchAction ( device , settings ) ;
667+ let liveSyncResultInfo = await service . liveSyncWatchAction ( device , settings ) ;
668+
659669 await this . refreshApplication ( projectData , liveSyncResultInfo , deviceBuildInfoDescriptor . debugOptions , deviceBuildInfoDescriptor . outputPath ) ;
670+
671+ if ( liveSyncData . useHotModuleReload && currentHmrData . hash ) {
672+ const status = await this . $hmrStatusService . awaitHmrStatus ( device . deviceInfo . identifier , currentHmrData . hash ) ;
673+ if ( status === HmrConstants . HMR_ERROR_STATUS ) {
674+ settings . filesToSync = currentHmrData . fallbackFiles [ device . deviceInfo . platform ] ;
675+ liveSyncResultInfo = await service . liveSyncWatchAction ( device , settings ) ;
676+ liveSyncResultInfo . isFullSync = true ;
677+ await this . refreshApplication ( projectData , liveSyncResultInfo , deviceBuildInfoDescriptor . debugOptions , deviceBuildInfoDescriptor . outputPath ) ;
678+ }
679+ }
680+
681+ this . $logger . info ( `Successfully synced application ${ liveSyncResultInfo . deviceAppData . appIdentifier } on device ${ liveSyncResultInfo . deviceAppData . device . deviceInfo . identifier } .` ) ;
660682 } ,
661683 ( device : Mobile . IDevice ) => {
662684 const liveSyncProcessInfo = this . liveSyncProcessesInfo [ projectData . projectDir ] ;
@@ -704,6 +726,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
704726 } ,
705727 filesToSync,
706728 filesToSyncMap,
729+ hmrData,
707730 filesToRemove,
708731 startSyncFilesTimeout : async ( platform : string ) => {
709732 if ( platform ) {
0 commit comments