@@ -3,8 +3,8 @@ import * as choki from "chokidar";
33import { EOL } from "os" ;
44import { EventEmitter } from "events" ;
55import { 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" ;
88import { cache } from "../../common/decorators" ;
99
1010const deviceDescriptorPrimaryKey = "identifier" ;
@@ -289,6 +289,12 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
289289 return _ . map ( deviceOptions , d => this . disableDebuggingCore ( d , debuggingAdditionalOptions ) ) ;
290290 }
291291
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+
292298 public async disableDebuggingCore ( deviceOption : IDisableDebuggingDeviceOptions , debuggingAdditionalOptions : IDebuggingAdditionalOptions ) : Promise < void > {
293299 const liveSyncProcessInfo = this . liveSyncProcessesInfo [ debuggingAdditionalOptions . projectDir ] ;
294300 if ( liveSyncProcessInfo . currentSyncAction ) {
@@ -328,7 +334,10 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
328334 // Should be set after prepare
329335 this . $usbLiveSyncService . isInitialized = true ;
330336
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 ) ;
332341 }
333342 }
334343
@@ -515,8 +524,8 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
515524 } ;
516525 }
517526
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 ) ;
520529
521530 if ( liveSyncData . watchAllFiles ) {
522531 const productionDependencies = this . $nodeModulesDependenciesBuilder . getProductionDependencies ( projectData . projectDir ) ;
@@ -535,18 +544,18 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
535544 currentWatcherInfo . watcher . close ( ) ;
536545 }
537546
538- let filesToSync : string [ ] = [ ] ;
547+ const filesToSync : string [ ] = [ ] ;
539548 let filesToRemove : string [ ] = [ ] ;
540549 let timeoutTimer : NodeJS . Timer ;
541550
542- const startTimeout = ( ) => {
551+ const startSyncFilesTimeout = ( ) => {
543552 timeoutTimer = setTimeout ( async ( ) => {
544553 // Push actions to the queue, do not start them simultaneously
545554 await this . addActionToChain ( projectData . projectDir , async ( ) => {
546555 if ( filesToSync . length || filesToRemove . length ) {
547556 try {
548557 const currentFilesToSync = _ . cloneDeep ( filesToSync ) ;
549- filesToSync = [ ] ;
558+ filesToSync . splice ( 0 , filesToSync . length ) ;
550559
551560 const currentFilesToRemove = _ . cloneDeep ( filesToRemove ) ;
552561 filesToRemove = [ ] ;
@@ -622,7 +631,18 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
622631
623632 await this . $hooksService . executeBeforeHooks ( 'watch' , {
624633 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 )
626646 }
627647 } ) ;
628648
@@ -650,10 +670,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
650670 filesToRemove . push ( filePath ) ;
651671 }
652672
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 ( ) ;
657674 } ) ;
658675
659676 this . liveSyncProcessesInfo [ liveSyncData . projectDir ] . watcherInfo = { watcher, patterns } ;
0 commit comments