Code Monkey home page Code Monkey logo

chokidar's Introduction

Hi there ๐Ÿ‘‹

I make projects which help developers to build awesome things. I adore learning more about infosec & austrian economics.

Check out my blog, ping me on twitter, nostr or send me an email. My PGP is 697079DA6878B89. You could fund my work with sponsorship.

๐Ÿ”ญ Iโ€™m currently working on:

Signed backups: github / gitlab. Old projects: brunch, chaplin, es6-shim, chieftain

chokidar's People

Contributors

alan-agius4 avatar alexpusch avatar ashaffer avatar catdad avatar dbashford avatar dependabot-preview[bot] avatar ehmicky avatar erezarnon avatar es128 avatar isaacs avatar jrebmann avatar jsmonk avatar kmayer avatar majorbreakfast avatar marccelani-at avatar markablov avatar mehiel avatar nono avatar nopnop avatar paulmillr avatar phated avatar raphinesse avatar santigimeno avatar shakyshane avatar sindresorhus avatar srguiwiz avatar timneutkens avatar tym-network avatar vdiez avatar xhmikosr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

chokidar's Issues

No 'added' event on folders, error while deleting entire folder

Hello,

I'm using chokidar, and I think it is the best 'FS.Watcher' implementation I've used! ;)
very good job!

So, playing with my filesystem I see an odd behavior.
I'm watching a folder, creating a new folder no 'added' event is fired. Creating an empty file in the new folder the 'added' event is fired. That's good for me, but I wonder, is this a bug or is this the correct behavior?
In other words, will this behavior change in the future?

Another problem I experienced:
deleting new folder previously created (containing my empty file), the 'error' event is fired.
Here is the log

>>> coffee application.coffee 
starting watching: /Users/fatshotty/Desktop/pippuzzo
Error happened { [Error: ENOENT, lstat '/Users/fatshotty/work/test_hook.io/new-file']
  errno: 34,
  code: 'ENOENT',
  path: '/Users/fatshotty/work/test_hook.io/new-file' }
Error happened { [Error: ENOENT, lstat '/Users/fatshotty/work/test_hook.io/new-file-2']
  errno: 34,
  code: 'ENOENT',
  path: '/Users/fatshotty/work/test_hook.io/new-file-2' }
Error happened { [Error: ENOENT, lstat '/Users/fatshotty/work/test_hook.io/new-file-3']
  errno: 34,
  code: 'ENOENT',
  path: '/Users/fatshotty/work/test_hook.io/new-file-3' }
File /Users/fatshotty/Desktop/pippuzzo/.DS_Store has been added
File /Users/fatshotty/Desktop/pippuzzo/Deekline  Ed Solo - I Need A Dollar.mp3 has been added
File /Users/fatshotty/Desktop/pippuzzo/Deekline  Ed Solo - King of The Bongo.mp3 has been added
File /Users/fatshotty/Desktop/pippuzzo/Ed Solo  Deekline - Sensi  Ghost Town Feat. DJ Concept.mp3 has been added
File /Users/fatshotty/Desktop/pippuzzo/Ed Solo  Deekline - Top Rankin.mp3 has been added
File /Users/fatshotty/Desktop/pippuzzo/Ed Solo Deekline Ragga Tip Walk And Skank.mp3 has been added
File /Users/fatshotty/Desktop/pippuzzo/Ed Solo  DJ Deekline - Bad Bwoy.mp3 has been added
File /Users/fatshotty/Desktop/pippuzzo/Soundclash - Raggamuffin.mp3 has been added
>>> mkdir new_folder
>> no output

>>> rm -rf new_folder
File /Users/fatshotty/Desktop/pippuzzo/new_folder has been removed

>>> mkdir new_folder
>> no output
>>> touch new_folder/new_file.txt
File /Users/fatshotty/Desktop/pippuzzo/new_folder/new_file.txt has been added

>>> rm new_folder/new_file.txt
File /Users/fatshotty/Desktop/pippuzzo/new_folder/new_file.txt has been removed

>>> touch new_folder/new_file.txt
File /Users/fatshotty/Desktop/pippuzzo/new_folder/new_file.txt has been added

>>> rm -rf new_folder
Error happened { [Error: ENOENT, readdir '/Users/fatshotty/Desktop/pippuzzo/new_folder']
  errno: 34,
  code: 'ENOENT',
  path: '/Users/fatshotty/Desktop/pippuzzo/new_folder' }
File /Users/fatshotty/Desktop/pippuzzo/new_folder/new_file.txt has been removed
File /Users/fatshotty/Desktop/pippuzzo/new_folder has been removed

Hope this can help.

Thanks

There seems to be a problem installing Chokidar globally

[~/projects/mtg] sudo npm -g install chokidar                                                                                                                                                    20:11:39
npm http GET https://registry.npmjs.org/chokidar
npm http 304 https://registry.npmjs.org/chokidar

> [email protected] postinstall /usr/local/lib/node_modules/chokidar
> node setup.js postinstall


npm ERR! TypeError: options.uid should be a number
npm ERR!     at ChildProcess.spawn (child_process.js:782:24)
npm ERR!     at Object.exports.spawn (child_process.js:618:9)
npm ERR!     at spawn (/usr/local/lib/node_modules/npm/lib/utils/exec.js:103:22)
npm ERR!     at exec (/usr/local/lib/node_modules/npm/lib/utils/exec.js:40:12)
npm ERR!     at /usr/local/lib/node_modules/npm/lib/utils/lifecycle.js:146:5
npm ERR!     at process.startup.processNextTick.process._tickCallback (node.js:244:9)
npm ERR! You may report this log at:
npm ERR!     <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR!     <[email protected]>
npm ERR! 
npm ERR! System Darwin 12.2.0
npm ERR! command "node" "/usr/local/bin/npm" "-g" "install" "chokidar"
npm ERR! cwd /Users/sudhirjonathan/projects/mtg
npm ERR! node -v v0.8.12
npm ERR! npm -v 1.1.15
npm ERR! message options.uid should be a number
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /Users/sudhirjonathan/projects/mtg/npm-debug.log
npm not ok

Watching folders recursively

Is chokidar watching folders recursively by default? If so I think you should be able to disable this via options, if not this is a feature request for recursive watching.

Shouldn't there be anything about this in the readme?

new subdir does not trigger event

  1. if a new directory is created, it does not detect this
  2. if a new file is created within that new directory, an ENOENT error is thrown

IE:
I am watching
/home/local/files/
I start the watcher
I create /home/local/files/newDir/
No event occurs

This is problematic as a new event is thrown when a new file is put inside that new dir.

allow user to override options.interval

for my environment (ubuntu 12.04, core I7), interval at 100 is so fast, that while editing files in VIM, chokidar detects that the file is deleted and then added, and thus fires off events for 'delete' and 'add' and it messes with the program i have watching for file changes.

by upping the interval manually, i can get it to detect edits as 'change' events instead.

Request directory exclusion

Hello,
I would like to be able to wath a directory, but exclude on or a few of it's subdirectories.
Something like:
(Pseudocode)

watch C:\home\
don't watch C:\home\priv\
don't watch C:\home\default\

(sorry if you can already do this, I spent a few hours looking for it and couldn't find)

`usePolling: false` does not work on Mac

This is more a question - what is the state of fs.watch vs. fs.watchFile ?

My observations...
linux:

  • usePolling false (fs.watch) seems to be working pretty well
  • it fires "add" event twice, but that's easy to deal with
  • much more efficient than stat polling (huge CPU usage)

mac:

  • after initial add, first change works, but subsequent changes are ignored
  • also it hits file descriptor limit very easily

windows:

  • ???

Should it work on Windows?

Trying to watch a directory.. I'm interested in change/unlink events, but it doesn't seem to be triggering any on Windows.

Post install script failure

Hello, I am trying to get Brunch running on my system and I am running into an error installing your package on Ubuntu 12.10. I get the following error when trying to install chokidar:

npm ERR! [email protected] postinstall: node setup.js postinstall
npm ERR! sh "-c" "node setup.js postinstall" failed with 127
npm ERR!
npm ERR! Failed at the [email protected] postinstall script.
npm ERR! This is most likely a problem with the chokidar package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node setup.js postinstall
npm ERR! You can get their info via:
npm ERR! npm owner ls chokidar
npm ERR! There is likely additional logging output above.
npm ERR!
npm ERR! System Linux 3.5.0-18-generic
npm ERR! command "/usr/bin/nodejs" "/usr/bin/npm" "install" "chokidar"
npm ERR! cwd /home/brooks/Code/SimpleSeer
npm ERR! node -v v0.6.19
npm ERR! npm -v 1.1.4
npm ERR! code ELIFECYCLE
npm ERR! message [email protected] postinstall: node setup.js postinstall
npm ERR! message sh "-c" "node setup.js postinstall" failed with 127
npm ERR! errno {}
npm ERR! Error: EACCES, open 'npm-debug.log'
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR!
npm ERR! System Linux 3.5.0-18-generic
npm ERR! command "/usr/bin/nodejs" "/usr/bin/npm" "install" "chokidar"
npm ERR! cwd /home/brooks/Code/SimpleSeer
npm ERR! node -v v0.6.19
npm ERR! npm -v 1.1.4
npm ERR! path npm-debug.log
npm ERR! code EACCES
npm ERR! message EACCES, open 'npm-debug.log'
npm ERR! errno {}```

FSWatcher.prototype._remove exposed as public?

In my project I have to dynamically add or remove watched files, so I create watcher this way:
var watcher = new FSWatcher({ persistent: true });

And then I add some files (array) and it works like a charm:
watcher.add(files);

To remove files from watcher I currently use _remove method (I pass in directory and file name), which seems to be private (are there any risks of using it?) ...
for (i = 0; i < somearray.length; i += 1) {
watcher._remove(dir, filename);
}

I assume I am not the only one doing this, so it would be great if you could expose this method as public so we could call watcher.remove() (with this you would guarantee users that it is safe).

compile coffeescript before publishing

Avoid the compile step during install by running coffee in prepublish and removing the post-install script.

This will help make chokidar faster to install.

You can also keep the coffeescript out of the published code with .npmignore, but it's small enough to not matter.

ignored fn needs to know if it is file or directory

Karma allows watching glob patterns (eg. src/**/*.js), which is done through watching directories. Eg src/**/*.js will watch entire src/ directory.

In order to be efficient, we want to ignore every file we can - that is simple, ignored function can just check if it matches the pattern and ignore otherwise.

However, we need to NOT ignore directories, as there can be a matching file in there.

Quick suggestions:

  • check ignored AFTER stating the fs (which means stating even ignored files) and pass it the stat obj
  • check ignored both BEFORE (as it does now) and AFTER stating; assuming the ignored fn is cheap, this could be better

Error: EMFILE, too many open files

node v0.10.4

-> brunch w

path.js:309
      var path = (i >= 0) ? arguments[i] : process.cwd();
                                                   ^
Error: EMFILE, too many open files
    at Object.exports.resolve (path.js:309:52)
    at Object.realpath (fs.js:1309:18)
    at FSWatcher.exports.FSWatcher.FSWatcher._handle (/usr/local/share/npm/lib/node_modules/brunch/node_modules/chokidar/lib/index.js:208:17)
    at FSWatcher._handle (/usr/local/share/npm/lib/node_modules/brunch/node_modules/chokidar/lib/index.js:6:61)
    at /usr/local/share/npm/lib/node_modules/brunch/node_modules/chokidar/lib/index.js:193:26
    at Array.forEach (native)
    at /usr/local/share/npm/lib/node_modules/brunch/node_modules/chokidar/lib/index.js:192:14
    at Object.oncomplete (fs.js:107:15)

Would you consider writing this in JavaScript?

Merits of CoffeeScript aside, would you consider writing this in JavaScript? I'm considering including this in fs-extra and it'd be beneficial if all modules were written in JavaScript.

If you can't or don't want to, that's fine. I just thought it wouldn't hurt to ask :)

Nothing getting added to watched object, no unlinks emitted

Been playing around with this library because of node's BS double event emission issues. I found chokidar after digging around brunch.

Using chokidar I noticed that whenever something gets added or removed, it re-emits add events for whatever is remaining in that directory (presumably just in that directory, I've only been testing with a single directory). So if you've got 10 files in a directory, and you add an 11th, it emits 11 add events. If you then remove one, it'll emit 10 add events. That didn't seem kosher.

The intent appears to be there to not do this. There's a watched object that is meant to be a hash of fileNames per directory. There's a method, _getWatchedDir(), which returns the files being watched for a directory from that watched object. The files being watched for a directory is used to determine a diff between what is currently in the directory and what used to be in the directory. What is missing from current needs to be unlinked, and what is missing from previous needs to be added.

But it doesn't appear anything ever gets added to the watched object, so the list of previous files for a directory is always empty. As a result nothing gets unlinked and everything gets added every time something is added or deleted.

I might be missing something...am I missing something? =)

Add tests to repo

There are tests referenced in package.json and setup.js, however, there are no tests in git. Can you please add them?

watcher object 10 listener max

Hi,
In the watcher object I have a _maxlistener = 10.

My project will probably use more than 10 listeners.
Is that value really used?
If I juste change the value to 999, will it work?

Thanks

Can't install on Windows 7

If I try to install on windows (latest npm version) it throws an error because of the postinstall script.
It would be great if you would just remove lib from gitignore, so it's not nessecarry to have CoffeeScript installed if you want to install chokidar. Also one could then install from the repo if one needs the latest version.

npm http GET http://registry.npmjs.org/chokidar
npm http 304 http://registry.npmjs.org/chokidar

> [email protected] postinstall C:\Users\fziegelm\Desktop\yaas\node_modules\chokidar
> node setup.js postinstall

Executing node node_modules\coffee-script\bin\coffee -o lib/ src/

module.js:340
    throw err;
          ^
Error: Cannot find module 'C:\Users\fziegelm\Desktop\yaas\node_modules\chokidar\node_modules\coffee-script\bin\coffee'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.runMain (module.js:492:10)
    at process.startup.processNextTick.process._tickCallback (node.js:244:9)
[email protected] node_modules\chokidar

File is ignored after removing and quick adding back

Ubuntu 12.04.1 LTS
Chokidar 0.5.1
Node 0.8.14

var w = chokidar.watch('watched');
['add', 'change', 'unlink'].forEach(function(event) {
  w.on(event, function(p) {
    console.log('chokidar:', event, p);
  });
});

In command line (this basically simulates VIM's backup behavior):

cd watched
mv some.js some.js.swp && sleep .1 && mv some.js.swp some.js

Output:

chokidar: change watched/some.js
chokidar: unlink watched/some.js
chokidar: add watched/some.js.swp
chokidar: change watched/some.js.swp

Chokidar does not catch when some.js is moved back. And any subsequent changes on some.js are ignored as well.

If I increase the sleep between mv commands, it works fine. Node's fs.watchFile does not watch a file, once it's removed (eg. adding the file back after removing is ignored). Chokidar catches new files by watching the directory. So I guess there is some sort of race condition between the "directory watcher" and "file" watcher - the "directory" watcher needs to be fired after the "file remove" watcher, so that it registers a new watcher for the file - I guess this doesn't happen.

Based on https://github.com/vojtajina/testacular/issues/199

Newly created file emitting change event on removal

  1. Add file to directory chokidar is already watching
  2. Update that file with something, anything
  3. Remove that file

Chokidar emits both a change and an unlink event.

Brunch output when this happens on file named foo.coffee :

10 Oct 12:56:40 - error: Reading of 'app/foo.coffee' failed. ENOENT, open 'app/foo.coffee'

This doesn't seem to happen if you immediately remove the file without editing.

Verified on node versions 0.8.7 and 0.8.4 on OSX.

Please remove postinstall

I've got error reports coming in from all over, that postinstall isn't working (e.g. vojtajina/testacular#46). I know it should and all and I'll look into filling an issue with npm but as per the offical npm documentation here:

NOTE: INSTALL SCRIPTS ARE AN ANTIPATTERN
tl;dr Don't use install. Use a .gyp file for compilation, and prepublish for anything else.

it shouldn't be used for this anyway.

Please look into this. I'm happy to help out if neeed.

Add LICENSE

Hey @paulmillr can you please add some license to chokidar ?
There is a policy at Google, I can't import it into our scm without a license.
Thanks...

"all" event

I think it might be valuable to include an "all" event that covers "change", "unlink", and "add". I'm building an asset compiler and it's not really important which event fires, just that I know when anything happens in my watched directories.

"unlink" not fired, when watching single file (Mac)

$ touch some.file
chokidar.watch('some.file', {persistent: true})
    .on('unlink', function() {console.log('unlink', arguments)});
$ rm some.file

Won't fire the unlink event.

Watching directory works fine.

node 0.10 warning

with node 0.10 and npm 1.2.14, chokidar gives the following warning

npm WARN engine [email protected]: wanted: {"node":"~0.6.10 || 0.7 || 0.8"} (current: {"node":"v0.10.0","npm":"1.2.14"})

If it already works in 0.10 without anything, would be just a matter of changing it in the package.json file

Optimise performance

would be nice to add an option that will auto-increase polling interval to static files like images etc.

Failing to trigger events when path starts with ./

Apparently, relative paths starting with ./ or / are not triggering any error, but no events are triggered either!
I am installing it as dependency in a project.
If the path is like:
"path/"
it works, but if it is:
"./path"
nothing happens when I change the files!

watcher runs into infinite loop on circular symLinks within the file system

Test it by creating a symbolic link one or two levels up in the file system, watch any directory within the loop, see how it adds and adds directory after directory to the watched ones.

I would like to have an option whether to add directories recursively or not. My use case is to watch a specific directory, but no descendants of it.

As far as I can see, the problem lies with index.coffee form lines 165-169. An option to follow the directory recursively would be very nice.

error on install

sudo npm install -g chokidar
npm http GET https://registry.npmjs.org/chokidar
npm http 304 https://registry.npmjs.org/chokidar

> [email protected] postinstall /usr/local/lib/node_modules/chokidar
> node setup.js postinstall


npm ERR! TypeError: options.uid should be a number
npm ERR!     at ChildProcess.spawn (child_process.js:777:24)
npm ERR!     at Object.exports.spawn (child_process.js:614:9)
npm ERR!     at spawn (/usr/local/lib/node_modules/npm/lib/utils/exec.js:103:22)
npm ERR!     at exec (/usr/local/lib/node_modules/npm/lib/utils/exec.js:40:12)
npm ERR!     at /usr/local/lib/node_modules/npm/lib/utils/lifecycle.js:127:5
npm ERR!     at process.startup.processNextTick.process._tickCallback (node.js:244:9)
npm ERR! You may report this log at:
npm ERR!     <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR!     <[email protected]>
npm ERR! 
npm ERR! System Darwin 10.8.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "-g" "chokidar"
npm ERR! cwd /Users/matt/Development/clscraper
npm ERR! node -v v0.7.12
npm ERR! npm -v 1.1.0-3
npm ERR! message options.uid should be a number
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /Users/matt/Development/clscraper/npm-debug.log
npm not ok

remove event instead of change

Hello,

I'm on Mac OSx

I'm watching a folder. When I rename a file, I expect 'change' event, but only 'remove' (old file) and then 'add' (new file).

Is it right?

warn memory leak

Hi again,

I have this message :
warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.

But I am just watching one file for the moment. The problem is that I close and open The same file again and again :
setInterval(function(){
watcher = chokidar.watch(path, { persistent: true});
watcher.close();
},100);

the watcher.watched contains onyl one file.

anything I should do?

thanks

ps: I didn't put the entire code, but even if here it doesn't make sense to do the setInterval in my code it does...

fs.watchFile on Windows 7 doesn't scale

Using mimosa I was getting almost 100% CPU usage from chokidar watching the files in a large codebase - it was unusable on my Win7 64 box. See mimosa#179.

Hacking the built index.js to always do fs.watch for windows instead of fs.watchFile has improved things hugely - my CPU usage is now around 1% which has fixed the problem entirely.

I haven't noticed noticed any file events not triggering or any errors, and it's backed up by an interval so things are now fine - at least in my case, watching code files which doesn't need to be extremely responsive.

If using watch is a scary default, is there any chance this behaviour (whether to use watch vs watchFile) be made configurable in a later version of chokidar, i.e. the watch options could default to 'watchFile' unless 'watch' is provided. This would allow users to opt-in to using watch, and might also solve #50.

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.