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

File watcher with usePolling: true not completing task? #282

Closed
noahgrant opened this issue Apr 16, 2015 · 8 comments
Closed

File watcher with usePolling: true not completing task? #282

noahgrant opened this issue Apr 16, 2015 · 8 comments

Comments

@noahgrant
Copy link

Hi, I have a strange issue--I've resorted to setting useFsEvents = false because of #219 , except when I do that, my other watched callbacks only execute once. Here's an example:

  gulp.task('watchify', function() {
    var bundler = browserify({
          entries: [
            './path/to/entry.js
          ],
          cache: {},
          debug: true,
          fullPaths: true,
          insertGlobals: true,
          packageCache: {}
        }
      ),
      rebundle = function(ids) {
        return bundler.bundle()
          .on('error', errorHandler)
          .pipe(source('mybundle.js'))
          .pipe(buffer())
          .pipe(gulp.dest('./build/js/'));
      };

    if (env.dev()) {
      bundler = watchify(bundler, {
        poll: 750 // sets useFsEvents to false and usePolling to true in chokidar
      });
      bundler.on('update', rebundle);
    }

    return rebundle();
  });

  gulp.task('jshint', function() {
    return gulp.src(sources.scripts)
        .pipe(watch(sources.scripts))
        .pipe(plumber())
        .pipe(jshint())
        .pipe(jshint.reporter(stylish));
  });

If I run gulp watchify jshint and then save myGreatModule.js, watchify will pick up on the change, and jshint will run. If I save myGreatModule.js again, only watchify will run--jshint will not. If I remove the poll: 750 line, both watchify and jshint run on every save. Can you explain why and what I can do to fix it? Does watchify need to emit an 'end' event or something to let gulp know that the rebundle method has completed?

@noahgrant
Copy link
Author

here is the watchify line that sets the relevant options for chokidar based on that poll

@es128
Copy link
Contributor

es128 commented Apr 16, 2015

So it looks like you're using two separate components that use chokidar (watchify and gulp-watch) with different watch-mode settings for each chokidar instance. This is not well-explored territory, and it's not very easy to reason about what's going on because of the layers between your implementation and chokidar.

Can you share a repo I can use to try to reproduce the issue locally?

@noahgrant
Copy link
Author

@es128 For what it's worth, the gulp-watch that I'm using is an old version that is still using Gaze@0.5.x, which is just an fs.watch/fs.watchFile wrapper, so both of my watchers should be effectively in the same mode. This seems like a pretty common use case--how else would you recommend doing things like linting in addition to incrementally building your browserify bundles?

I can put together an example repo shortly. Thanks!

@es128
Copy link
Contributor

es128 commented Apr 16, 2015

Your whole problem is with the jshint task not running, and it is using a gaze-based watcher. The way you described it, your watchify task is stable and consistently runs with either setting. So I am now confused about why you think chokidar is the culprit.

how else would you recommend

I am not in the business of advising on gulp configurations. All I can say is that nobody has yet presented an issue involving one polling and one non-polling chokidar watcher within the same process - although as it turns out that was not the case here.

Have you tried/considered updating your gulp-watch?

@noahgrant
Copy link
Author

I was just about to post an update to say that the same thing happens with gulp-watch 4.2.4 (set to use polling, as well, but with chokidar).

The reason I believe it's chokidar (or watchify, actually) is the culprit, is because the linter (or any other task for js-files) run as expected without running watchify or while running watchify with chokidar using fsevents. That is to say, I can repeatedly save a file and it gets linted every time. However, as soon as watchify rebuilds once (with useFsEvents = false), the other tasks stop running--they'll usually run once successfully, but then they'll stop responding after watchify runs. It seems like watchify isn't completing or something (even though it does continue to rebuild on successive saves), but the only thing I've added is a poll option to set useFsEvents to false in chokidar.

@es128
Copy link
Contributor

es128 commented Apr 16, 2015

I understand your point about how you've narrowed down the difference that causes the issue, but I don't see how there's anything chokidar could be doing to disrupt the rest of your tasks. Perhaps file an issue with watchify if you haven't already.

Closing for now, but will reopen if an issue with chokidar can be demonstrated or at least described more directly.

@es128 es128 closed this as completed Apr 16, 2015
@noahgrant
Copy link
Author

Okay, thanks @es128. For posterity, I should add that if I update gulp-watch and do not force useFsEvents to false (so two chokidars running in separate modes), jshint will run on repeated saves as expected.

@es128
Copy link
Contributor

es128 commented Apr 16, 2015

Yeah everything that you've described that's directly chokidar related seems to work. The only thing that breaks is the handoff from watchify back into the rest of your gulp pipeline when using a watchify-specific option.

I understand the intent of the option is just to manipulate chokidar's options, but nonetheless it is not a simple pass-through, and I have no idea how else watchify's behavior is changed because of it.

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

2 participants