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

Browser sync is not paying attention to watchEvents. #1367

Open
3 of 10 tasks
Riobe opened this issue Apr 27, 2017 · 2 comments
Open
3 of 10 tasks

Browser sync is not paying attention to watchEvents. #1367

Riobe opened this issue Apr 27, 2017 · 2 comments

Comments

@Riobe
Copy link

Riobe commented Apr 27, 2017

Issue details

browser-sync's watchEvents documentation says that it is an array that can be used to specify "which file events to respond to." and these correspond to chokidar events. It appears that these are being ignored. The default of ['change'], or an explicit setting, will respond on all events (including the unlink events which is why I noticed).

Steps to reproduce/test case

I have an example of this issue available in this repository with only browser-sync as a dependency, and as minimal as a setup as I think possible.

Using this the following configuration will still result in browser-sync reloading on deletions (unlink):

'use strict';

const browserSync = require('browser-sync');

let config = { 
  server: true,
  files: [
    './index.html',
    'js/**/*.js'
  ],  
  watchEvents: ['add', 'change']
};

let instance = browserSync.create();
instance.init(config);

Please specify which version of Browsersync, node and npm you're running

  • Browsersync [ 2.18.8 ]
  • Node [ 6.10.2 ]
  • Npm [ 3.10.10 ]

Affected platforms

  • linux (CentOS)
  • windows
  • OS X
  • freebsd
  • solaris
  • other (please specify which)

Browsersync use-case

  • API
  • Gulp
  • Grunt
  • CLI
@Riobe
Copy link
Author

Riobe commented Apr 27, 2017

From what I can see the default callback from lib/file-watcher.js is getting called with the correct event each time. It looks like the subscribe function from lib/internal-events.js is then getting called with a value that has a type === 'reload' and a files array that has the correct event: 'unlink' in it.

The problem, I think, that I can't figure out is why lib/file-utils.js.changedFile is never getting called as far as I can tell. From commit de2e2fa it looks like that should be where the filtering is done. I found that commit by finding issue #1291.

I don't know why changedFile never gets called, or why the handler gets called with a type: 'reload' every time, but I'm starting to hit a wall with figuring that out.

@Riobe
Copy link
Author

Riobe commented Apr 27, 2017

My current work around for this issue is:

browserSyncConfig.files = browserSyncConfig.files.map(pattern => { 
  return { 
    match: pattern,
    fn: event => { 
      if (!['add', 'change'].includes(event)) { 
        return;
      } 

      browserSync.reload();
    } 
  };
});

This will ignore the unlink event which stops browser-sync from reloading when a file is deleted as part of a clean task that happens before a build, and holds off reloading till the new file is added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant