Chokidar: "ignored"-pattern, that works with anymatch, but not with chokidar

Created on 8 Aug 2017  路  6Comments  路  Source: paulmillr/chokidar

I want to watch only for files with a specific extension (in my case .json), so ignored has to ignore everything that is NOT .json.

Result: chokidar ignored all my test files, including ".json".

My guess: chokidar uses another regex-engine than default javascript, so I made a MWE with pure anymatch, which worked like expected:

var anymatch = require('anymatch');
var matchers = [/^(?!.*\.json$).*$/];
console.log(anymatch(matchers, 'foo.json')); // results in false
console.log(anymatch(matchers, 'foo.js'));   // results in true

Non-successfull MWE with chokidar:

var chokidar = require('chokidar');
chokidar.watch('testdir', {
    ignored: /^(?!.*\.json$).*$/,
}).on('add', function (filename) {
    console.log(filename + ' added');
});

Edit: This MWE actually gets executed and finished immediately without feedback. Maybe that is a hint? That behaviour was not visible in my original application (probably no script end because of my client/server-loops etc.).

Specs:

Most helpful comment

Oh, and the reason your original method is not working is

> /^(?!.*\.json$).*$/.test('testdir')
true

testdir is ignored right off the bat, so chokidar does not traverse into its contents

All 6 comments

How about chokidar.watch('testdir/**/*.json', ?

Oh, and the reason your original method is not working is

> /^(?!.*\.json$).*$/.test('testdir')
true

testdir is ignored right off the bat, so chokidar does not traverse into its contents

How do you ignore everything except specific file types that may or may not be in a subdirectory?

What @Jakobud said.

How do you ignore everything except specific file types that may or may not be in a subdirectory?

Does anyone have the answer to @Jakobud question?

@AbdulMuqtadeer @Jakobud @vincenzo

An answer was given here: https://github.com/paulmillr/chokidar/issues/951

But I couldn't get it to work. :(

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nikoladev picture nikoladev  路  6Comments

paulmillr picture paulmillr  路  9Comments

kevcodez picture kevcodez  路  3Comments

yebrahim picture yebrahim  路  4Comments

ORESoftware picture ORESoftware  路  3Comments