Skip to content

Commit

Permalink
fix(Windows): Add converting from windows to unix path for all ignore…
Browse files Browse the repository at this point in the history
…d paths. (#824)
  • Loading branch information
JSMonk authored and paulmillr committed Apr 22, 2019
1 parent 41f8782 commit db99076
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
10 changes: 6 additions & 4 deletions index.js
Expand Up @@ -65,7 +65,7 @@ const toUnix = (string) => {
// TODO: this is not equal to path-normalize module - investigate why
const normalizePathToUnix = (path) => toUnix(sysPath.normalize(toUnix(path)));

const normalizeIgnored = (cwd) => (path) => {
const normalizeIgnored = (cwd = '') => (path) => {
if (typeof path !== 'string') return path;
return normalizePathToUnix(sysPath.isAbsolute(path) ? path : sysPath.join(cwd, path));
};
Expand Down Expand Up @@ -608,13 +608,15 @@ _isIgnored(path, stats) {
const cwd = this.options.cwd;
const ign = this.options.ignored;

let ignored = ign;
if (cwd && ign) ignored = ign.map(normalizeIgnored(cwd));
const ignored = ign && ign.map(normalizeIgnored(cwd));
const paths = arrify(ignored)
.filter((path) => typeof path === 'string' && !isGlob(path))
.map((path) => path + '/**');
this._userIgnored = anymatch(
this._getGlobIgnored().concat(ignored).concat(paths)
this._getGlobIgnored()
.map(normalizeIgnored(cwd))
.concat(ignored)
.concat(paths)
);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/nodefs-handler.js
Expand Up @@ -325,7 +325,7 @@ _handleFile(file, stats, initialAdd, callback) {
});

// emit an add event if we're supposed to
if (!(initialAdd && this.fsw.options.ignoreInitial)) {
if (!(initialAdd && this.fsw.options.ignoreInitial) && this.fsw._isntIgnored(file)) {
if (!this.fsw._throttle('add', file, 0)) return;
this.fsw._emit('add', file, stats);
}
Expand Down
18 changes: 10 additions & 8 deletions test.js
Expand Up @@ -1818,24 +1818,26 @@ const runTests = function(baseopts) {
if (!macosFswatch) spy.should.have.been.calledOnce;
});
it('should ignore unwatched paths that are a subset of watched paths', async () => {
const subdirRel = upath.relative(process.cwd(), getFixturePath('subdir'));
const unlinkFile = getFixturePath('unlink.txt');
const addFile = getFixturePath('subdir/add.txt');
const changedFile = getFixturePath('change.txt');
let watcher = chokidar_watch(currentDir, options);
const spy = await aspy(watcher, 'all');

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

await delay();
await fs_unlink(getFixturePath('unlink.txt'));
await write(getFixturePath('subdir/add.txt'), Date.now());
await write(getFixturePath('change.txt'), Date.now());
await fs_unlink(unlinkFile);
await write(addFile, Date.now());
await write(changedFile, Date.now());
await waitFor([spy.withArgs('change')]);

await delay(300);
spy.should.have.been.calledWith('change', getFixturePath('change.txt'));
spy.should.not.have.been.calledWith('add', getFixturePath('subdir/add.txt'));
spy.should.not.have.been.calledWith('unlink');
spy.should.have.been.calledWith('change', changedFile);
spy.should.not.have.been.calledWith('add', addFile);
spy.should.not.have.been.calledWith('unlink', unlinkFile);
if (!macosFswatch) spy.should.have.been.calledOnce;
});
it('should unwatch relative paths', async () => {
Expand Down

0 comments on commit db99076

Please sign in to comment.