Giter Site home page Giter Site logo

paulmillr / chokidar Goto Github PK

View Code? Open in Web Editor NEW
10.7K 92.0 574.0 1.81 MB

Minimal and efficient cross-platform file watching library

Home Page: https://paulmillr.com

License: MIT License

JavaScript 61.77% TypeScript 38.23%
watch-files fsevents watcher filesystem

chokidar's Introduction

Chokidar Weekly downloads Yearly downloads

Minimal and efficient cross-platform file watching library

NPM

Why?

Node.js fs.watch:

  • Doesn't report filenames on MacOS.
  • Doesn't report events at all when using editors like Sublime on MacOS.
  • Often reports events twice.
  • Emits most changes as rename.
  • Does not provide an easy way to recursively watch file trees.
  • Does not support recursive watching on Linux.

Node.js fs.watchFile:

  • Almost as bad at event handling.
  • Also does not provide any recursive watching.
  • Results in high CPU utilization.

Chokidar resolves these problems.

Initially made for Brunch (an ultra-swift web app build tool), it is now used in Microsoft's Visual Studio Code, gulp, karma, PM2, browserify, webpack, BrowserSync, and many others. It has proven itself in production environments.

Version 3 is out! Check out our blog post about it: Chokidar 3: How to save 32TB of traffic every week

How?

Chokidar does still rely on the Node.js core fs module, but when using fs.watch and fs.watchFile for watching, it normalizes the events it receives, often checking for truth by getting file stats and/or dir contents.

On MacOS, chokidar by default uses a native extension exposing the Darwin FSEvents API. This provides very efficient recursive watching compared with implementations like kqueue available on most *nix platforms. Chokidar still does have to do some work to normalize the events received that way as well.

On most other platforms, the fs.watch-based implementation is the default, which avoids polling and keeps CPU usage down. Be advised that chokidar will initiate watchers recursively for everything within scope of the paths that have been specified, so be judicious about not wasting system resources by watching much more than needed.

Getting started

Install with npm:

npm install chokidar

Then require and use it in your code:

const chokidar = require('chokidar');

// One-liner for current directory
chokidar.watch('.').on('all', (event, path) => {
  console.log(event, path);
});

API

// Example of a more typical implementation structure

// Initialize watcher.
const watcher = chokidar.watch('file, dir, or array', {
  ignored: /(^|[\/\\])\../, // ignore dotfiles
  persistent: true
});

// Something to use when events are received.
const log = console.log.bind(console);
// Add event listeners.
watcher
  .on('add', path => log(`File ${path} has been added`))
  .on('change', path => log(`File ${path} has been changed`))
  .on('unlink', path => log(`File ${path} has been removed`));

// More possible events.
watcher
  .on('addDir', path => log(`Directory ${path} has been added`))
  .on('unlinkDir', path => log(`Directory ${path} has been removed`))
  .on('error', error => log(`Watcher error: ${error}`))
  .on('ready', () => log('Initial scan complete. Ready for changes'))
  .on('raw', (event, path, details) => { // internal
    log('Raw event info:', event, path, details);
  });

// 'add', 'addDir' and 'change' events also receive stat() results as second
// argument when available: https://nodejs.org/api/fs.html#fs_class_fs_stats
watcher.on('change', (path, stats) => {
  if (stats) console.log(`File ${path} changed size to ${stats.size}`);
});

// Watch new files.
watcher.add('new-file');
watcher.add(['new-file-2', 'new-file-3', '**/other-file*']);

// Get list of actual paths being watched on the filesystem
var watchedPaths = watcher.getWatched();

// Un-watch some files.
await watcher.unwatch('new-file*');

// Stop watching.
// The method is async!
watcher.close().then(() => console.log('closed'));

// Full list of options. See below for descriptions.
// Do not use this example!
chokidar.watch('file', {
  persistent: true,

  ignored: '*.txt',
  ignoreInitial: false,
  followSymlinks: true,
  cwd: '.',

  usePolling: false,
  interval: 100,
  binaryInterval: 300,
  alwaysStat: false,
  depth: 99,
  awaitWriteFinish: {
    stabilityThreshold: 2000,
    pollInterval: 100
  },

  ignorePermissionErrors: false,
  atomic: true // or a custom 'atomicity delay', in milliseconds (default 100)
});

chokidar.watch(paths, [options])

  • paths (string or array of strings). Paths to files, dirs to be watched recursively.
  • options (object) Options object as defined below:

Persistence

  • persistent (default: true). Indicates whether the process should continue to run as long as files are being watched. If set to false when using fsevents to watch, no more events will be emitted after ready, even if the process continues to run.

Path filtering

  • ignored (anymatch-compatible definition) Defines files/paths to be ignored. The whole relative or absolute path is tested, not just filename. If a function with two arguments is provided, it gets called twice per path - once with a single argument (the path), second time with two arguments (the path and the fs.Stats object of that path).
  • ignoreInitial (default: false). If set to false then add/addDir events are also emitted for matching paths while instantiating the watching as chokidar discovers these file paths (before the ready event).
  • followSymlinks (default: true). When false, only the symlinks themselves will be watched for changes instead of following the link references and bubbling events through the link's path.
  • cwd (no default). The base directory from which watch paths are to be derived. Paths emitted with events will be relative to this.

Performance

  • usePolling (default: false). Whether to use fs.watchFile (backed by polling), or fs.watch. If polling leads to high CPU utilization, consider setting this to false. It is typically necessary to set this to true to successfully watch files over a network, and it may be necessary to successfully watch files in other non-standard situations. Setting to true explicitly on MacOS overrides the useFsEvents default. You may also set the CHOKIDAR_USEPOLLING env variable to true (1) or false (0) in order to override this option.
  • Polling-specific settings (effective when usePolling: true)
    • interval (default: 100). Interval of file system polling, in milliseconds. You may also set the CHOKIDAR_INTERVAL env variable to override this option.
    • binaryInterval (default: 300). Interval of file system polling for binary files. (see list of binary extensions)
  • useFsEvents (default: true on MacOS). Whether to use the fsevents watching interface if available. When set to true explicitly and fsevents is available this supercedes the usePolling setting. When set to false on MacOS, usePolling: true becomes the default.
  • alwaysStat (default: false). If relying upon the fs.Stats object that may get passed with add, addDir, and change events, set this to true to ensure it is provided even in cases where it wasn't already available from the underlying watch events.
  • depth (default: undefined). If set, limits how many levels of subdirectories will be traversed.
  • awaitWriteFinish (default: false). By default, the add event will fire when a file first appears on disk, before the entire file has been written. Furthermore, in some cases some change events will be emitted while the file is being written. In some cases, especially when watching for large files there will be a need to wait for the write operation to finish before responding to a file creation or modification. Setting awaitWriteFinish to true (or a truthy value) will poll file size, holding its add and change events until the size does not change for a configurable amount of time. The appropriate duration setting is heavily dependent on the OS and hardware. For accurate detection this parameter should be relatively high, making file watching much less responsive. Use with caution.
    • options.awaitWriteFinish can be set to an object in order to adjust timing params:
    • awaitWriteFinish.stabilityThreshold (default: 2000). Amount of time in milliseconds for a file size to remain constant before emitting its event.
    • awaitWriteFinish.pollInterval (default: 100). File size polling interval, in milliseconds.

Errors

  • ignorePermissionErrors (default: false). Indicates whether to watch files that don't have read permissions if possible. If watching fails due to EPERM or EACCES with this set to true, the errors will be suppressed silently.
  • atomic (default: true if useFsEvents and usePolling are false). Automatically filters out artifacts that occur when using editors that use "atomic writes" instead of writing directly to the source file. If a file is re-added within 100 ms of being deleted, Chokidar emits a change event rather than unlink then add. If the default of 100 ms does not work well for you, you can override it by setting atomic to a custom value, in milliseconds.

Methods & Events

chokidar.watch() produces an instance of FSWatcher. Methods of FSWatcher:

  • .add(path / paths): Add files, directories for tracking. Takes an array of strings or just one string.
  • .on(event, callback): Listen for an FS event. Available events: add, addDir, change, unlink, unlinkDir, ready, raw, error. Additionally all is available which gets emitted with the underlying event name and path for every event other than ready, raw, and error. raw is internal, use it carefully.
  • .unwatch(path / paths): Stop watching files or directories. Takes an array of strings or just one string.
  • .close(): async Removes all listeners from watched files. Asynchronous, returns Promise. Use with await to ensure bugs don't happen.
  • .getWatched(): Returns an object representing all the paths on the file system being watched by this FSWatcher instance. The object's keys are all the directories (using absolute paths unless the cwd option was used), and the values are arrays of the names of the items contained in each directory.

CLI

If you need a CLI interface for your file watching, check out chokidar-cli, allowing you to execute a command on each change, or get a stdio stream of change events.

Install Troubleshooting

  • npm WARN optional dep failed, continuing [email protected]

    • This message is normal part of how npm handles optional dependencies and is not indicative of a problem. Even if accompanied by other related error messages, Chokidar should function properly.
  • TypeError: fsevents is not a constructor

    • Update chokidar by doing rm -rf node_modules package-lock.json yarn.lock && npm install, or update your dependency that uses chokidar.
  • Chokidar is producing ENOSP error on Linux, like this:

    • bash: cannot set terminal process group (-1): Inappropriate ioctl for device bash: no job control in this shell Error: watch /home/ ENOSPC
    • This means Chokidar ran out of file handles and you'll need to increase their count by executing the following command in Terminal: echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

Changelog

For more detailed changelog, see full_changelog.md.

  • v3.5 (Jan 6, 2021): Support for ARM Macs with Apple Silicon. Fixes for deleted symlinks.
  • v3.4 (Apr 26, 2020): Support for directory-based symlinks. Fixes for macos file replacement.
  • v3.3 (Nov 2, 2019): FSWatcher#close() method became async. That fixes IO race conditions related to close method.
  • v3.2 (Oct 1, 2019): Improve Linux RAM usage by 50%. Race condition fixes. Windows glob fixes. Improve stability by using tight range of dependency versions.
  • v3.1 (Sep 16, 2019): dotfiles are no longer filtered out by default. Use ignored option if needed. Improve initial Linux scan time by 50%.
  • v3 (Apr 30, 2019): massive CPU & RAM consumption improvements; reduces deps / package size by a factor of 17x and bumps Node.js requirement to v8.16 and higher.
  • v2 (Dec 29, 2017): Globs are now posix-style-only; without windows support. Tons of bugfixes.
  • v1 (Apr 7, 2015): Glob support, symlink support, tons of bugfixes. Node 0.8+ is supported
  • v0.1 (Apr 20, 2012): Initial release, extracted from Brunch

Also

Why was chokidar named this way? What's the meaning behind it?

Chowkidar is a transliteration of a Hindi word meaning 'watchman, gatekeeper', चौकीदार. This ultimately comes from Sanskrit _ चतुष्क_ (crossway, quadrangle, consisting-of-four). This word is also used in other languages like Urdu as (چوکیدار) which is widely used in Pakistan and India.

License

MIT (c) Paul Miller (https://paulmillr.com), see LICENSE file.

chokidar's People

Contributors

43081j avatar alan-agius4 avatar alexpusch avatar ashaffer avatar dbashford avatar dependabot-preview[bot] avatar ehmicky avatar ehsankhfr avatar erezarnon avatar es128 avatar isaacs avatar jrebmann avatar jsmonk avatar majorbreakfast avatar markablov avatar mehiel avatar nono avatar nopnop avatar paulmillr avatar phated avatar raphinesse avatar santigimeno avatar scamden 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

chokidar's Issues

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.

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.

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)

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?

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.

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? =)

`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:

  • ???

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 {}```

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.

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

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 :)

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?

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).

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)

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.

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

"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.

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!

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.

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?

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.

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...

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

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.

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

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.

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

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

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

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.