Skip to content

Commit

Permalink
Only unwatch and watch on Linux systems
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Jan 19, 2020
1 parent 8f9a66f commit 818de7c
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions src/watch/fileWatcher.ts
@@ -1,4 +1,5 @@
import chokidar, { FSWatcher } from 'chokidar';
import { platform } from 'os';
import { ChokidarOptions } from '../rollup/types';
import { Task } from './watch';

Expand Down Expand Up @@ -41,20 +42,20 @@ export class FileWatcher {
}

private createWatcher(transformWatcherId: string | null): FSWatcher {
const handleChange = transformWatcherId
? () => {
// unwatching and watching fixes an issue with chokidar where on certain systems,
// a file that was unlinked and immediately recreated would create a change event
// but then no longer any further events
watcher.unwatch(transformWatcherId);
watcher.add(transformWatcherId);
this.task.invalidate(transformWatcherId, true);
}
: (id: string) => {
watcher.unwatch(id);
watcher.add(id);
this.task.invalidate(id, false);
};
const task = this.task;
const isLinux = platform() === 'linux';
const isTransformDependency = transformWatcherId !== null;
const handleChange = (id: string) => {
const changedId = transformWatcherId || id;
if (isLinux) {
// unwatching and watching fixes an issue with chokidar where on certain systems,
// a file that was unlinked and immediately recreated would create a change event
// but then no longer any further events
watcher.unwatch(changedId);
watcher.add(changedId);
}
task.invalidate(changedId, isTransformDependency);
};
const watcher = chokidar
.watch([], this.chokidarOptions)
.on('change', handleChange)
Expand Down

0 comments on commit 818de7c

Please sign in to comment.