@@ -4,7 +4,7 @@ import { EOL } from "os";
4
4
import { EventEmitter } from "events" ;
5
5
import { hook } from "../../common/helpers" ;
6
6
import { 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" ;
8
8
import { cache } from "../../common/decorators" ;
9
9
10
10
const deviceDescriptorPrimaryKey = "identifier" ;
@@ -38,6 +38,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
38
38
private $analyticsService : IAnalyticsService ,
39
39
private $usbLiveSyncService : DeprecatedUsbLiveSyncService ,
40
40
private $previewAppLiveSyncService : IPreviewAppLiveSyncService ,
41
+ private $hmrStatusService : IHmrStatusService ,
41
42
private $injector : IInjector ) {
42
43
super ( ) ;
43
44
}
@@ -147,8 +148,6 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
147
148
deviceIdentifier : liveSyncResultInfo . deviceAppData . device . deviceInfo . identifier ,
148
149
isFullSync : liveSyncResultInfo . isFullSync
149
150
} ) ;
150
-
151
- this . $logger . info ( `Successfully synced application ${ liveSyncResultInfo . deviceAppData . appIdentifier } on device ${ liveSyncResultInfo . deviceAppData . device . deviceInfo . identifier } .` ) ;
152
151
}
153
152
154
153
private async refreshApplicationWithDebug ( projectData : IProjectData , liveSyncResultInfo : ILiveSyncResultInfo , debugOptions : IDebugOptions , outputPath ?: string ) : Promise < IDebugInformation > {
@@ -518,6 +517,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
518
517
519
518
await this . $platformService . trackActionForPlatform ( { action : "LiveSync" , platform : device . deviceInfo . platform , isForDevice : ! device . isEmulator , deviceOsVersion : device . deviceInfo . version } ) ;
520
519
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 } .` ) ;
521
521
522
522
this . emitLivesyncEvent ( LiveSyncEvents . liveSyncStarted , {
523
523
projectDir : projectData . projectDir ,
@@ -564,6 +564,10 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
564
564
const platforms = _ ( devices ) . map ( device => device . deviceInfo . platform ) . uniq ( ) . value ( ) ;
565
565
const patterns = await this . getWatcherPatterns ( liveSyncData , projectData , platforms ) ;
566
566
567
+ if ( liveSyncData . useHotModuleReload ) {
568
+ this . $hmrStatusService . attachToHrmStatusEvent ( ) ;
569
+ }
570
+
567
571
if ( liveSyncData . watchAllFiles ) {
568
572
const productionDependencies = this . $nodeModulesDependenciesBuilder . getProductionDependencies ( projectData . projectDir ) ;
569
573
patterns . push ( PACKAGE_JSON_FILE_NAME ) ;
@@ -582,6 +586,10 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
582
586
}
583
587
584
588
let filesToSync : string [ ] = [ ] ;
589
+ const hmrData : { hash : string ; fallbackFiles : IDictionary < string [ ] > } = {
590
+ hash : "" ,
591
+ fallbackFiles : { }
592
+ } ;
585
593
const filesToSyncMap : IDictionary < string [ ] > = { } ;
586
594
let filesToRemove : string [ ] = [ ] ;
587
595
let timeoutTimer : NodeJS . Timer ;
@@ -610,6 +618,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
610
618
if ( filesToSync . length || filesToRemove . length ) {
611
619
try {
612
620
const currentFilesToSync = _ . cloneDeep ( filesToSync ) ;
621
+ const currentHmrData = _ . cloneDeep ( hmrData ) ;
613
622
filesToSync . splice ( 0 , filesToSync . length ) ;
614
623
615
624
const currentFilesToRemove = _ . cloneDeep ( filesToRemove ) ;
@@ -655,8 +664,21 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
655
664
force : liveSyncData . force
656
665
} ;
657
666
658
- const liveSyncResultInfo = await service . liveSyncWatchAction ( device , settings ) ;
667
+ let liveSyncResultInfo = await service . liveSyncWatchAction ( device , settings ) ;
668
+
659
669
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 } .` ) ;
660
682
} ,
661
683
( device : Mobile . IDevice ) => {
662
684
const liveSyncProcessInfo = this . liveSyncProcessesInfo [ projectData . projectDir ] ;
@@ -704,6 +726,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
704
726
} ,
705
727
filesToSync,
706
728
filesToSyncMap,
729
+ hmrData,
707
730
filesToRemove,
708
731
startSyncFilesTimeout : async ( platform : string ) => {
709
732
if ( platform ) {
0 commit comments