@@ -3,8 +3,8 @@ import * as choki from "chokidar";
3
3
import { EOL } from "os" ;
4
4
import { EventEmitter } from "events" ;
5
5
import { hook } from "../../common/helpers" ;
6
- import { APP_FOLDER_NAME , PACKAGE_JSON_FILE_NAME , LiveSyncTrackActionNames , USER_INTERACTION_NEEDED_EVENT_NAME , DEBUGGER_ATTACHED_EVENT_NAME , DEBUGGER_DETACHED_EVENT_NAME , TrackActionNames } from "../../constants" ;
7
- import { FileExtensions , DeviceTypes , DeviceDiscoveryEventNames } from "../../common/constants" ;
6
+ import { APP_FOLDER_NAME , APP_RESOURCES_FOLDER_NAME , 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" ;
8
8
import { cache } from "../../common/decorators" ;
9
9
10
10
const deviceDescriptorPrimaryKey = "identifier" ;
@@ -289,6 +289,12 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
289
289
return _ . map ( deviceOptions , d => this . disableDebuggingCore ( d , debuggingAdditionalOptions ) ) ;
290
290
}
291
291
292
+ @hook ( 'watchPatterns' )
293
+ public async getWatcherPatterns ( liveSyncData : ILiveSyncInfo ) : Promise < string [ ] > {
294
+ // liveSyncData is used by plugins that make use of the watchPatterns hook
295
+ return [ APP_FOLDER_NAME , path . join ( APP_FOLDER_NAME , APP_RESOURCES_FOLDER_NAME ) ] ;
296
+ }
297
+
292
298
public async disableDebuggingCore ( deviceOption : IDisableDebuggingDeviceOptions , debuggingAdditionalOptions : IDebuggingAdditionalOptions ) : Promise < void > {
293
299
const liveSyncProcessInfo = this . liveSyncProcessesInfo [ debuggingAdditionalOptions . projectDir ] ;
294
300
if ( liveSyncProcessInfo . currentSyncAction ) {
@@ -328,7 +334,10 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
328
334
// Should be set after prepare
329
335
this . $usbLiveSyncService . isInitialized = true ;
330
336
331
- await this . startWatcher ( projectData , liveSyncData ) ;
337
+ const devicesIds = deviceDescriptors . map ( dd => dd . identifier ) ;
338
+ const devices = _ . filter ( this . $devicesService . getDeviceInstances ( ) , device => _ . includes ( devicesIds , device . deviceInfo . identifier ) ) ;
339
+ const platforms = _ ( devices ) . map ( device => device . deviceInfo . platform ) . uniq ( ) . value ( ) ;
340
+ await this . startWatcher ( projectData , liveSyncData , platforms ) ;
332
341
}
333
342
}
334
343
@@ -515,8 +524,8 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
515
524
} ;
516
525
}
517
526
518
- private async startWatcher ( projectData : IProjectData , liveSyncData : ILiveSyncInfo ) : Promise < void > {
519
- const patterns = [ APP_FOLDER_NAME ] ;
527
+ private async startWatcher ( projectData : IProjectData , liveSyncData : ILiveSyncInfo , platforms : string [ ] ) : Promise < void > {
528
+ const patterns = await this . getWatcherPatterns ( liveSyncData ) ;
520
529
521
530
if ( liveSyncData . watchAllFiles ) {
522
531
const productionDependencies = this . $nodeModulesDependenciesBuilder . getProductionDependencies ( projectData . projectDir ) ;
@@ -535,18 +544,18 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
535
544
currentWatcherInfo . watcher . close ( ) ;
536
545
}
537
546
538
- let filesToSync : string [ ] = [ ] ;
547
+ const filesToSync : string [ ] = [ ] ;
539
548
let filesToRemove : string [ ] = [ ] ;
540
549
let timeoutTimer : NodeJS . Timer ;
541
550
542
- const startTimeout = ( ) => {
551
+ const startSyncFilesTimeout = ( ) => {
543
552
timeoutTimer = setTimeout ( async ( ) => {
544
553
// Push actions to the queue, do not start them simultaneously
545
554
await this . addActionToChain ( projectData . projectDir , async ( ) => {
546
555
if ( filesToSync . length || filesToRemove . length ) {
547
556
try {
548
557
const currentFilesToSync = _ . cloneDeep ( filesToSync ) ;
549
- filesToSync = [ ] ;
558
+ filesToSync . splice ( 0 , filesToSync . length ) ;
550
559
551
560
const currentFilesToRemove = _ . cloneDeep ( filesToRemove ) ;
552
561
filesToRemove = [ ] ;
@@ -622,7 +631,18 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
622
631
623
632
await this . $hooksService . executeBeforeHooks ( 'watch' , {
624
633
hookArgs : {
625
- projectData
634
+ projectData,
635
+ config : {
636
+ env : liveSyncData . env ,
637
+ appFilesUpdaterOptions : {
638
+ bundle : liveSyncData . bundle ,
639
+ release : liveSyncData . release
640
+ } ,
641
+ platforms
642
+ } ,
643
+ filesToSync,
644
+ filesToRemove,
645
+ startSyncFilesTimeout : startSyncFilesTimeout . bind ( this )
626
646
}
627
647
} ) ;
628
648
@@ -650,10 +670,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
650
670
filesToRemove . push ( filePath ) ;
651
671
}
652
672
653
- // Do not sync typescript files directly - wait for javascript changes to occur in order to restart the app only once
654
- if ( path . extname ( filePath ) !== FileExtensions . TYPESCRIPT_FILE ) {
655
- startTimeout ( ) ;
656
- }
673
+ startSyncFilesTimeout ( ) ;
657
674
} ) ;
658
675
659
676
this . liveSyncProcessesInfo [ liveSyncData . projectDir ] . watcherInfo = { watcher, patterns } ;
0 commit comments