@@ -594,7 +594,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
594
594
let filesToRemove : string [ ] = [ ] ;
595
595
let timeoutTimer : NodeJS . Timer ;
596
596
597
- const startSyncFilesTimeout = ( platform ?: string ) => {
597
+ const startSyncFilesTimeout = ( platform ?: string , opts ?: { calledFromHook : boolean } ) => {
598
598
timeoutTimer = setTimeout ( async ( ) => {
599
599
if ( platform && liveSyncData . bundle ) {
600
600
filesToSync = filesToSyncMap [ platform ] ;
@@ -636,6 +636,52 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
636
636
const liveSyncProcessInfo = this . liveSyncProcessesInfo [ projectData . projectDir ] ;
637
637
const deviceBuildInfoDescriptor = _ . find ( liveSyncProcessInfo . deviceDescriptors , dd => dd . identifier === device . deviceInfo . identifier ) ;
638
638
639
+ const settings : ILiveSyncWatchInfo = {
640
+ liveSyncDeviceInfo : deviceBuildInfoDescriptor ,
641
+ projectData,
642
+ filesToRemove : currentFilesToRemove ,
643
+ filesToSync : currentFilesToSync ,
644
+ isReinstalled : false ,
645
+ syncAllFiles : liveSyncData . watchAllFiles ,
646
+ hmrData : currentHmrData ,
647
+ useHotModuleReload : liveSyncData . useHotModuleReload ,
648
+ force : liveSyncData . force ,
649
+ connectTimeout : 1000
650
+ } ;
651
+
652
+ const service = this . getLiveSyncService ( device . deviceInfo . platform ) ;
653
+
654
+ const watchAction = async ( watchInfo : ILiveSyncWatchInfo ) : Promise < void > => {
655
+ let liveSyncResultInfo = await service . liveSyncWatchAction ( device , watchInfo ) ;
656
+
657
+ await this . refreshApplication ( projectData , liveSyncResultInfo , deviceBuildInfoDescriptor . debugOptions , deviceBuildInfoDescriptor . outputPath ) ;
658
+
659
+ // If didRecover is true, this means we were in ErrorActivity and fallback files were already transfered and app will be restarted.
660
+ if ( ! liveSyncResultInfo . didRecover && liveSyncData . useHotModuleReload && currentHmrData . hash ) {
661
+ const status = await this . $hmrStatusService . getHmrStatus ( device . deviceInfo . identifier , currentHmrData . hash ) ;
662
+ if ( status === HmrConstants . HMR_ERROR_STATUS ) {
663
+ watchInfo . filesToSync = currentHmrData . fallbackFiles [ device . deviceInfo . platform ] ;
664
+ liveSyncResultInfo = await service . liveSyncWatchAction ( device , watchInfo ) ;
665
+ // We want to force a restart of the application.
666
+ liveSyncResultInfo . isFullSync = true ;
667
+ await this . refreshApplication ( projectData , liveSyncResultInfo , deviceBuildInfoDescriptor . debugOptions , deviceBuildInfoDescriptor . outputPath ) ;
668
+ }
669
+ }
670
+
671
+ this . $logger . info ( `Successfully synced application ${ liveSyncResultInfo . deviceAppData . appIdentifier } on device ${ liveSyncResultInfo . deviceAppData . device . deviceInfo . identifier } .` ) ;
672
+ } ;
673
+
674
+ if ( liveSyncData . useHotModuleReload && opts && opts . calledFromHook ) {
675
+ try {
676
+ this . $logger . trace ( "Try executing watch action without any preparation of files." ) ;
677
+ await watchAction ( settings ) ;
678
+ this . $logger . trace ( "Successfully executed watch action without any preparation of files." ) ;
679
+ return ;
680
+ } catch ( err ) {
681
+ this . $logger . trace ( `Error while trying to execute fast sync. Now we'll check the state of the app and we'll try to resurrect from the error. The error is: ${ err } ` ) ;
682
+ }
683
+ }
684
+
639
685
const appInstalledOnDeviceResult = await this . ensureLatestAppPackageIsInstalledOnDevice ( {
640
686
device,
641
687
preparedPlatforms,
@@ -653,41 +699,15 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
653
699
skipModulesNativeCheck : ! liveSyncData . watchAllFiles
654
700
} , { skipNativePrepare : deviceBuildInfoDescriptor . skipNativePrepare } ) ;
655
701
702
+ settings . isReinstalled = appInstalledOnDeviceResult . appInstalled ;
703
+ settings . connectTimeout = null ;
704
+
656
705
if ( liveSyncData . useHotModuleReload && appInstalledOnDeviceResult . appInstalled ) {
657
706
const additionalFilesToSync = currentHmrData && currentHmrData . fallbackFiles && currentHmrData . fallbackFiles [ device . deviceInfo . platform ] ;
658
707
_ . each ( additionalFilesToSync , fileToSync => currentFilesToSync . push ( fileToSync ) ) ;
659
708
}
660
709
661
- const service = this . getLiveSyncService ( device . deviceInfo . platform ) ;
662
- const settings : ILiveSyncWatchInfo = {
663
- liveSyncDeviceInfo : deviceBuildInfoDescriptor ,
664
- projectData,
665
- filesToRemove : currentFilesToRemove ,
666
- filesToSync : currentFilesToSync ,
667
- isReinstalled : appInstalledOnDeviceResult . appInstalled ,
668
- syncAllFiles : liveSyncData . watchAllFiles ,
669
- hmrData : currentHmrData ,
670
- useHotModuleReload : liveSyncData . useHotModuleReload ,
671
- force : liveSyncData . force
672
- } ;
673
-
674
- let liveSyncResultInfo = await service . liveSyncWatchAction ( device , settings ) ;
675
-
676
- await this . refreshApplication ( projectData , liveSyncResultInfo , deviceBuildInfoDescriptor . debugOptions , deviceBuildInfoDescriptor . outputPath ) ;
677
-
678
- //If didRecover is true, this means we were in ErrorActivity and fallback files were already transfered and app will be restarted.
679
- if ( ! liveSyncResultInfo . didRecover && liveSyncData . useHotModuleReload && currentHmrData . hash ) {
680
- const status = await this . $hmrStatusService . getHmrStatus ( device . deviceInfo . identifier , currentHmrData . hash ) ;
681
- if ( status === HmrConstants . HMR_ERROR_STATUS ) {
682
- settings . filesToSync = currentHmrData . fallbackFiles [ device . deviceInfo . platform ] ;
683
- liveSyncResultInfo = await service . liveSyncWatchAction ( device , settings ) ;
684
- //We want to force a restart of the application.
685
- liveSyncResultInfo . isFullSync = true ;
686
- await this . refreshApplication ( projectData , liveSyncResultInfo , deviceBuildInfoDescriptor . debugOptions , deviceBuildInfoDescriptor . outputPath ) ;
687
- }
688
- }
689
-
690
- this . $logger . info ( `Successfully synced application ${ liveSyncResultInfo . deviceAppData . appIdentifier } on device ${ liveSyncResultInfo . deviceAppData . device . deviceInfo . identifier } .` ) ;
710
+ await watchAction ( settings ) ;
691
711
} ,
692
712
( device : Mobile . IDevice ) => {
693
713
const liveSyncProcessInfo = this . liveSyncProcessesInfo [ projectData . projectDir ] ;
@@ -715,7 +735,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
715
735
} ) ;
716
736
}
717
737
}
718
- } , 250 ) ;
738
+ } , liveSyncData . useHotModuleReload ? 0 : 250 ) ;
719
739
720
740
this . liveSyncProcessesInfo [ liveSyncData . projectDir ] . timer = timeoutTimer ;
721
741
} ;
@@ -738,11 +758,12 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
738
758
hmrData,
739
759
filesToRemove,
740
760
startSyncFilesTimeout : async ( platform : string ) => {
761
+ const opts = { calledFromHook : true } ;
741
762
if ( platform ) {
742
- await startSyncFilesTimeout ( platform ) ;
763
+ await startSyncFilesTimeout ( platform , opts ) ;
743
764
} else {
744
765
// This code is added for backwards compatibility with old versions of nativescript-dev-webpack plugin.
745
- await startSyncFilesTimeout ( ) ;
766
+ await startSyncFilesTimeout ( null , opts ) ;
746
767
}
747
768
}
748
769
}
@@ -823,7 +844,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
823
844
}
824
845
}
825
846
826
- public emitLivesyncEvent ( event : string , livesyncData : ILiveSyncEventData ) : boolean {
847
+ public emitLivesyncEvent ( event : string , livesyncData : ILiveSyncEventData ) : boolean {
827
848
this . $logger . trace ( `Will emit event ${ event } with data` , livesyncData ) ;
828
849
return this . emit ( event , livesyncData ) ;
829
850
}
0 commit comments