diff --git a/lib/definitions/livesync.d.ts b/lib/definitions/livesync.d.ts index 6d5db2d7f7..4f2d9b0d63 100644 --- a/lib/definitions/livesync.d.ts +++ b/lib/definitions/livesync.d.ts @@ -60,7 +60,7 @@ interface ILiveSyncProcessInfo { timer: NodeJS.Timer; watcherInfo: { watcher: IFSWatcher, - pattern: string | string[] + patterns: string[] }; actionsChain: Promise; isStopped: boolean; diff --git a/lib/services/livesync/livesync-service.ts b/lib/services/livesync/livesync-service.ts index 8b4c53d104..8c9a97b47a 100644 --- a/lib/services/livesync/livesync-service.ts +++ b/lib/services/livesync/livesync-service.ts @@ -513,21 +513,21 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi } private async startWatcher(projectData: IProjectData, liveSyncData: ILiveSyncInfo): Promise { - const pattern = [APP_FOLDER_NAME]; + const patterns = [APP_FOLDER_NAME]; if (liveSyncData.watchAllFiles) { const productionDependencies = this.$nodeModulesDependenciesBuilder.getProductionDependencies(projectData.projectDir); - pattern.push(PACKAGE_JSON_FILE_NAME); + patterns.push(PACKAGE_JSON_FILE_NAME); // watch only production node_module/packages same one prepare uses for (const index in productionDependencies) { - pattern.push(productionDependencies[index].directory); + patterns.push(productionDependencies[index].directory); } } const currentWatcherInfo = this.liveSyncProcessesInfo[liveSyncData.projectDir].watcherInfo; - - if (!currentWatcherInfo || currentWatcherInfo.pattern !== pattern) { + const areWatcherPatternsDifferent = () => _.xor(currentWatcherInfo.patterns, patterns).length; + if (!currentWatcherInfo || areWatcherPatternsDifferent()) { if (currentWatcherInfo) { currentWatcherInfo.watcher.close(); } @@ -630,7 +630,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi ignored: ["**/.*", ".*"] // hidden files }; - const watcher = choki.watch(pattern, watcherOptions) + const watcher = choki.watch(patterns, watcherOptions) .on("all", async (event: string, filePath: string) => { clearTimeout(timeoutTimer); @@ -650,7 +650,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi } }); - this.liveSyncProcessesInfo[liveSyncData.projectDir].watcherInfo = { watcher, pattern }; + this.liveSyncProcessesInfo[liveSyncData.projectDir].watcherInfo = { watcher, patterns }; this.liveSyncProcessesInfo[liveSyncData.projectDir].timer = timeoutTimer; this.$processService.attachToProcessExitSignals(this, () => { diff --git a/test/services/livesync-service.ts b/test/services/livesync-service.ts index f32e088313..a3d15d0378 100644 --- a/test/services/livesync-service.ts +++ b/test/services/livesync-service.ts @@ -94,7 +94,7 @@ describe("liveSyncService", () => { watcher: { close: (): any => undefined }, - pattern: "pattern" + patterns: ["pattern"] }, deviceDescriptors: [] });