@@ -2,6 +2,7 @@ import { HmrConstants, DeviceDiscoveryEventNames } from "../common/constants";
2
2
import { PREPARE_READY_EVENT_NAME , TrackActionNames , DEBUGGER_DETACHED_EVENT_NAME , RunOnDeviceEvents , USER_INTERACTION_NEEDED_EVENT_NAME } from "../constants" ;
3
3
import { cache , performanceLog } from "../common/decorators" ;
4
4
import { EventEmitter } from "events" ;
5
+ import * as util from "util" ;
5
6
6
7
export class RunController extends EventEmitter implements IRunController {
7
8
private prepareReadyEventHandler : any = null ;
@@ -270,7 +271,7 @@ export class RunController extends EventEmitter implements IRunController {
270
271
}
271
272
272
273
private async syncInitialDataOnDevices ( projectData : IProjectData , liveSyncInfo : ILiveSyncInfo , deviceDescriptors : ILiveSyncDeviceDescriptor [ ] ) : Promise < void > {
273
- const rebuiltInformation : IDictionary < { packageFilePath : string , platform : string , isEmulator : boolean } > = { } ;
274
+ const rebuiltInformation : IDictionary < { packageFilePath : string , platform : string , isEmulator : boolean } > = { } ;
274
275
275
276
const deviceAction = async ( device : Mobile . IDevice ) => {
276
277
const deviceDescriptor = _ . find ( deviceDescriptors , dd => dd . identifier === device . deviceInfo . identifier ) ;
@@ -333,15 +334,16 @@ export class RunController extends EventEmitter implements IRunController {
333
334
error : err ,
334
335
} ) ;
335
336
336
- await this . stop ( { projectDir : projectData . projectDir , deviceIdentifiers : [ device . deviceInfo . identifier ] , stopOptions : { shouldAwaitAllActions : false } } ) ;
337
+ await this . stop ( { projectDir : projectData . projectDir , deviceIdentifiers : [ device . deviceInfo . identifier ] , stopOptions : { shouldAwaitAllActions : false } } ) ;
337
338
}
338
339
} ;
339
340
340
341
await this . addActionToChain ( projectData . projectDir , ( ) => this . $devicesService . execute ( deviceAction , ( device : Mobile . IDevice ) => _ . some ( deviceDescriptors , deviceDescriptor => deviceDescriptor . identifier === device . deviceInfo . identifier ) ) ) ;
341
342
}
342
343
343
344
private async syncChangedDataOnDevices ( data : IFilesChangeEventData , projectData : IProjectData , liveSyncInfo : ILiveSyncInfo ) : Promise < void > {
344
- const rebuiltInformation : IDictionary < { packageFilePath : string , platform : string , isEmulator : boolean } > = { } ;
345
+ const successfullySyncedMessageFormat = `Successfully synced application %s on device %s.` ;
346
+ const rebuiltInformation : IDictionary < { packageFilePath : string , platform : string , isEmulator : boolean } > = { } ;
345
347
346
348
const deviceAction = async ( device : Mobile . IDevice ) => {
347
349
const deviceDescriptors = this . $liveSyncProcessDataService . getDeviceDescriptors ( projectData . projectDir ) ;
@@ -380,28 +382,47 @@ export class RunController extends EventEmitter implements IRunController {
380
382
await this . $deviceInstallAppService . installOnDevice ( device , deviceDescriptor . buildData , rebuiltInformation [ platformData . platformNameLowerCase ] . packageFilePath ) ;
381
383
await platformLiveSyncService . syncAfterInstall ( device , watchInfo ) ;
382
384
await this . refreshApplication ( projectData , { deviceAppData, modifiedFilesData : [ ] , isFullSync : false , useHotModuleReload : liveSyncInfo . useHotModuleReload } , data , deviceDescriptor ) ;
385
+ this . $logger . info ( util . format ( successfullySyncedMessageFormat , deviceAppData . appIdentifier , device . deviceInfo . identifier ) ) ;
383
386
} else {
384
387
const isInHMRMode = liveSyncInfo . useHotModuleReload && data . hmrData && data . hmrData . hash ;
385
388
if ( isInHMRMode ) {
386
389
this . $hmrStatusService . watchHmrStatus ( device . deviceInfo . identifier , data . hmrData . hash ) ;
387
390
}
388
391
389
- let liveSyncResultInfo = await platformLiveSyncService . liveSyncWatchAction ( device , watchInfo ) ;
390
- await this . refreshApplication ( projectData , liveSyncResultInfo , data , deviceDescriptor ) ;
391
-
392
- if ( ! liveSyncResultInfo . didRecover && isInHMRMode ) {
393
- const status = await this . $hmrStatusService . getHmrStatus ( device . deviceInfo . identifier , data . hmrData . hash ) ;
394
- if ( status === HmrConstants . HMR_ERROR_STATUS ) {
395
- watchInfo . filesToSync = data . hmrData . fallbackFiles ;
396
- liveSyncResultInfo = await platformLiveSyncService . liveSyncWatchAction ( device , watchInfo ) ;
397
- // We want to force a restart of the application.
398
- liveSyncResultInfo . isFullSync = true ;
399
- await this . refreshApplication ( projectData , liveSyncResultInfo , data , deviceDescriptor ) ;
392
+ const watchAction = async ( ) : Promise < void > => {
393
+ let liveSyncResultInfo = await platformLiveSyncService . liveSyncWatchAction ( device , watchInfo ) ;
394
+ await this . refreshApplication ( projectData , liveSyncResultInfo , data , deviceDescriptor ) ;
395
+
396
+ if ( ! liveSyncResultInfo . didRecover && isInHMRMode ) {
397
+ const status = await this . $hmrStatusService . getHmrStatus ( device . deviceInfo . identifier , data . hmrData . hash ) ;
398
+ if ( status === HmrConstants . HMR_ERROR_STATUS ) {
399
+ watchInfo . filesToSync = data . hmrData . fallbackFiles ;
400
+ liveSyncResultInfo = await platformLiveSyncService . liveSyncWatchAction ( device , watchInfo ) ;
401
+ // We want to force a restart of the application.
402
+ liveSyncResultInfo . isFullSync = true ;
403
+ await this . refreshApplication ( projectData , liveSyncResultInfo , data , deviceDescriptor ) ;
404
+ }
405
+ }
406
+
407
+ this . $logger . info ( util . format ( successfullySyncedMessageFormat , deviceAppData . appIdentifier , device . deviceInfo . identifier ) ) ;
408
+ } ;
409
+
410
+ if ( liveSyncInfo . useHotModuleReload ) {
411
+ try {
412
+ this . $logger . trace ( "Try executing watch action without any preparation of files." ) ;
413
+ await watchAction ( ) ;
414
+ this . $logger . trace ( "Successfully executed watch action without any preparation of files." ) ;
415
+ return ;
416
+ } catch ( err ) {
417
+ 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 } ` ) ;
400
418
}
401
419
}
420
+
421
+ await this . $deviceInstallAppService . installOnDeviceIfNeeded ( device , deviceDescriptor . buildData ) ;
422
+ watchInfo . connectTimeout = null ;
423
+ await watchAction ( ) ;
402
424
}
403
425
404
- this . $logger . info ( `Successfully synced application ${ deviceAppData . appIdentifier } on device ${ device . deviceInfo . identifier } .` ) ;
405
426
} catch ( err ) {
406
427
this . $logger . warn ( `Unable to apply changes for device: ${ device . deviceInfo . identifier } . Error is: ${ err && err . message } .` ) ;
407
428
0 commit comments