Skip to content

Commit a6165ec

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 a6165ec

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

lib/definitions/livesync.d.ts

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,8 +526,7 @@ 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+
if (!currentWatcherInfo || _.difference(currentWatcherInfo.pattern, pattern).length || _.difference(pattern, currentWatcherInfo.pattern).length) {
531530
if (currentWatcherInfo) {
532531
currentWatcherInfo.watcher.close();
533532
}

0 commit comments

Comments
 (0)