Skip to content

Commit db99076

Browse files
JSMonkpaulmillr
authored andcommitted
fix(Windows): Add converting from windows to unix path for all ignored paths. (#824)
1 parent 41f8782 commit db99076

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const toUnix = (string) => {
6565
// TODO: this is not equal to path-normalize module - investigate why
6666
const normalizePathToUnix = (path) => toUnix(sysPath.normalize(toUnix(path)));
6767

68-
const normalizeIgnored = (cwd) => (path) => {
68+
const normalizeIgnored = (cwd = '') => (path) => {
6969
if (typeof path !== 'string') return path;
7070
return normalizePathToUnix(sysPath.isAbsolute(path) ? path : sysPath.join(cwd, path));
7171
};
@@ -608,13 +608,15 @@ _isIgnored(path, stats) {
608608
const cwd = this.options.cwd;
609609
const ign = this.options.ignored;
610610

611-
let ignored = ign;
612-
if (cwd && ign) ignored = ign.map(normalizeIgnored(cwd));
611+
const ignored = ign && ign.map(normalizeIgnored(cwd));
613612
const paths = arrify(ignored)
614613
.filter((path) => typeof path === 'string' && !isGlob(path))
615614
.map((path) => path + '/**');
616615
this._userIgnored = anymatch(
617-
this._getGlobIgnored().concat(ignored).concat(paths)
616+
this._getGlobIgnored()
617+
.map(normalizeIgnored(cwd))
618+
.concat(ignored)
619+
.concat(paths)
618620
);
619621
}
620622

lib/nodefs-handler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ _handleFile(file, stats, initialAdd, callback) {
325325
});
326326

327327
// emit an add event if we're supposed to
328-
if (!(initialAdd && this.fsw.options.ignoreInitial)) {
328+
if (!(initialAdd && this.fsw.options.ignoreInitial) && this.fsw._isntIgnored(file)) {
329329
if (!this.fsw._throttle('add', file, 0)) return;
330330
this.fsw._emit('add', file, stats);
331331
}

test.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1818,24 +1818,26 @@ const runTests = function(baseopts) {
18181818
if (!macosFswatch) spy.should.have.been.calledOnce;
18191819
});
18201820
it('should ignore unwatched paths that are a subset of watched paths', async () => {
1821+
const subdirRel = upath.relative(process.cwd(), getFixturePath('subdir'));
1822+
const unlinkFile = getFixturePath('unlink.txt');
1823+
const addFile = getFixturePath('subdir/add.txt');
1824+
const changedFile = getFixturePath('change.txt');
18211825
let watcher = chokidar_watch(currentDir, options);
18221826
const spy = await aspy(watcher, 'all');
18231827

1824-
await delay();
18251828
// test with both relative and absolute paths
1826-
const subdirRel = upath.relative(process.cwd(), getFixturePath('subdir'));
18271829
watcher.unwatch([subdirRel, getGlobPath('unl*')]);
18281830

18291831
await delay();
1830-
await fs_unlink(getFixturePath('unlink.txt'));
1831-
await write(getFixturePath('subdir/add.txt'), Date.now());
1832-
await write(getFixturePath('change.txt'), Date.now());
1832+
await fs_unlink(unlinkFile);
1833+
await write(addFile, Date.now());
1834+
await write(changedFile, Date.now());
18331835
await waitFor([spy.withArgs('change')]);
18341836

18351837
await delay(300);
1836-
spy.should.have.been.calledWith('change', getFixturePath('change.txt'));
1837-
spy.should.not.have.been.calledWith('add', getFixturePath('subdir/add.txt'));
1838-
spy.should.not.have.been.calledWith('unlink');
1838+
spy.should.have.been.calledWith('change', changedFile);
1839+
spy.should.not.have.been.calledWith('add', addFile);
1840+
spy.should.not.have.been.calledWith('unlink', unlinkFile);
18391841
if (!macosFswatch) spy.should.have.been.calledOnce;
18401842
});
18411843
it('should unwatch relative paths', async () => {

0 commit comments

Comments
 (0)