Skip to content

Fix multiple typescript/sass watchers #3332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/definitions/livesync.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ interface ILiveSyncProcessInfo {
timer: NodeJS.Timer;
watcherInfo: {
watcher: IFSWatcher,
pattern: string | string[]
patterns: string[]
};
actionsChain: Promise<any>;
isStopped: boolean;
Expand Down
14 changes: 7 additions & 7 deletions lib/services/livesync/livesync-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -513,21 +513,21 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
}

private async startWatcher(projectData: IProjectData, liveSyncData: ILiveSyncInfo): Promise<void> {
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();
}
Expand Down Expand Up @@ -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);

Expand All @@ -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, () => {
Expand Down
2 changes: 1 addition & 1 deletion test/services/livesync-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ describe("liveSyncService", () => {
watcher: <any>{
close: (): any => undefined
},
pattern: "pattern"
patterns: ["pattern"]
},
deviceDescriptors: []
});
Expand Down