Skip to content

Commit 3f01716

Browse files
Mitko-KerezovDimitar Kerezov
authored and
Dimitar Kerezov
committed
Fix multiple typescript/sass watchers
Whenever using CLI as a library, calling livesync multiple times leads to multiple typescript/sass watchers. This happens due to the fact that `currentWatcherInfo.pattern` is an array and checking two arrays for equality with `!==` is bound to return `true` at all times. `toString()` both arrays and check the string literals instead.
1 parent f0d4908 commit 3f01716

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

lib/definitions/livesync.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ interface ILiveSyncProcessInfo {
6060
timer: NodeJS.Timer;
6161
watcherInfo: {
6262
watcher: IFSWatcher,
63-
pattern: string | string[]
63+
pattern: string[]
6464
};
6565
actionsChain: Promise<any>;
6666
isStopped: boolean;

lib/services/livesync/livesync-service.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -526,8 +526,8 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
526526
}
527527

528528
const currentWatcherInfo = this.liveSyncProcessesInfo[liveSyncData.projectDir].watcherInfo;
529-
530-
if (!currentWatcherInfo || currentWatcherInfo.pattern !== pattern) {
529+
const areWatcherPatternsDifferent = () => _.difference(currentWatcherInfo.pattern, pattern).length || _.difference(pattern, currentWatcherInfo.pattern).length;
530+
if (!currentWatcherInfo || areWatcherPatternsDifferent()) {
531531
if (currentWatcherInfo) {
532532
currentWatcherInfo.watcher.close();
533533
}

test/services/livesync-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ describe("liveSyncService", () => {
9494
watcher: <any>{
9595
close: (): any => undefined
9696
},
97-
pattern: "pattern"
97+
pattern: ["pattern"]
9898
},
9999
deviceDescriptors: []
100100
});

0 commit comments

Comments
 (0)