Skip to content
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

fix(Windows): Add converting from windows to unix path for all ignore… #824

Merged
merged 1 commit into from
Apr 22, 2019
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
10 changes: 6 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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