Coder Social home page Coder Social logo

watch-fs's People

Contributors

gabesoft avatar gurdiga avatar jarofghosts avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

jarofghosts

watch-fs's Issues

Doesn't works if the file doesn't exists yet on startup

Hi,

Thanks you for your module, it's really usefull :-)

But currently, I have an error and the nodejs server break if the file doesn't exists on startup :

% node test.js
Could not access path "/www/test/test.txt" { [Error: ENOENT, stat '/www/test/test.txt']
  errno: 34,
  code: 'ENOENT',
  path: '/www/test/test.txt' }
watcher started

The code is your example :

var Watcher = require('watch-fs').Watcher;

var watcher = new Watcher({
    paths: [ 'test.txt' ]
});

watcher.on('create', function(name) {
        console.log('file ' + name + ' created');
        });

watcher.on('change', function(name) {
        console.log('file ' + name + ' changed');
        });

watcher.on('delete', function(name) {
        console.log('file ' + name + ' deleted');
        });

watcher.start(function(err) {
        console.log('watcher started');
});

There is a solution to ignore it at startup please ?

Regards,

Symlink path normalization issue

Scenario (yes, this is copy/paste-able into a console):

# preparation
mkdir scenario
cd scenario
npm install watch-fs

# setup
touch file.js
mkdir dir
cd dir
ln -s ../file.js .
cd ..

# now we’re back to the “scenario” root directory

then I put this in quickstart.js:

var Watcher = require('watch-fs').Watcher;

var watcher = new Watcher({
    paths: [ 'dir' ],
    filters: {
        includeFile: function(name) {
            return /\.js/.test(name);
        }
    }
});

watcher.start(function(err) {
    console.log('watcher started');
});

and run it:

    ~/tmp/scenario ⌘  node quickstart.js 

fs.js:1051
    throw errnoException(process._errno, 'watch');
          ^
Error: watch ENOENT
    at errnoException (fs.js:1019:11)
    at FSWatcher.start (fs.js:1051:11)
    at Object.fs.watch (fs.js:1076:11)
    at initWatcher (/Users/vlad/tmp/scenario/node_modules/watch-fs/lib/watcher.js:99:32)
    at /Users/vlad/tmp/scenario/node_modules/watch-fs/lib/watcher.js:92:9
    at Array.forEach (native)
    at initWatchers (/Users/vlad/tmp/scenario/node_modules/watch-fs/lib/watcher.js:91:22)
    at /Users/vlad/tmp/scenario/node_modules/watch-fs/lib/watcher.js:238:13
    at /Users/vlad/tmp/scenario/node_modules/watch-fs/lib/watcher.js:72:9
    at /Users/vlad/tmp/scenario/node_modules/watch-fs/node_modules/async/lib/async.js:116:25
    ~/tmp/scenario ⌘  

Now, if I insert a console.log(realPath, fullPath); at node_modules/watch-fs/lib/watcher.js:99 and run that again, then it shows me this this:

/Users/vlad/tmp/scenario/dir /Users/vlad/tmp/scenario/dir
../file.js /Users/vlad/tmp/scenario/dir/file.js

which basically explains why that line fails:

map[fullPath].watcher = fs.watch(realPath, function (event, name) {

that is, it’s trying to fs.watch() ../file.js which is not exactly there… ;) I didn’t look too deep into this, but I think that using fs.realpathSync() instead of fs.readlinkSync() in the buildMap function would fix that, but I’m afraid that there might be more to the picture, and this is why I’m not creating a pull request. :->

So, what do you think? :)

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.