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

New files watching in subfolders doesn't work #29

Closed
artch opened this issue Apr 17, 2014 · 10 comments
Closed

New files watching in subfolders doesn't work #29

artch opened this issue Apr 17, 2014 · 10 comments

Comments

@artch
Copy link

artch commented Apr 17, 2014

Steps to reproduce:

  1. npm install gulp gulp-watch

  2. Create local subfolder and subfolder/subsubfolder

  3. Put gulpfile.js to the root folder:

    var gulp = require('gulp'),
       watch = require('gulp-watch');
    
    gulp.task('default', function () {   
    watch({glob: 'subfolder/**/*.txt', silent: false, verbose: true})               
    })
  4. Run gulp from the root folder.

  5. Put new file 1.txt to subfolder/subsubfolder. It does not invoke a watcher, while it should.

@floatdrop
Copy link
Owner

This is strange. If you already have this folder with files and add file to subfolder, gaze seems to catch created event. Otherwise - not.

@artch
Copy link
Author

artch commented Apr 18, 2014

Your workaround works, but it is not really useful when we have a folder structure with big (and unknown) number of nested levels. You might need to forward this issue to gaze folks I think.

@tim-smart
Copy link

I would like to confirm this as well. This task does not pick up newly created files in a subfolder:

var gulp = require('gulp');
var watch = require('gulp-watch');

gulp.task('watch', function() {
    watch({ glob: 'app/views/less/**/*.less' }, function() {
        console.error('something changed');
    });
});

@floatdrop
Copy link
Owner

This will be fixed in referenced issue in gaze.

@tim-smart
Copy link

This is what I settled on until this works properly:

var gulp = require('gulp');
var watch = require('gulp-watch');
var through2 = require('through2');
var livereload = require('gulp-livereload');
var mpath = require('path');

gulp.task('watch', function() {
    var lrServer = livereload();

    watch({
        glob: [
            'app/views/less/**',
            'app/views/js/**',
            'app/views/jade/**',
            '!app/views/js/node_modules'
        ],
        read: false
    }).pipe(through2.obj(function(file, enc, done) {
        var ext = mpath.extname(file.path);

        switch (ext) {
            case '.less':
                gulp.task('css');
                break;
            case '.js':
                gulp.task('javascript');
                break;
            case '.jade':
                lrServer.changed(file.path);
                break;
        }

        this.push(file);
        done();
    }));
});

@floatdrop
Copy link
Owner

Is there a reason, that you don't use different watches for file?

var gulp = require('gulp');
var watch = require('gulp-watch');
var livereload = require('gulp-livereload');

gulp.task('watch', function() {
    var lrServer = livereload();

    watch({ glob: [ 'app/views/less/**' ] }, ['css']);
    watch({ glob: [ 'app/views/js/**', '!app/views/js/node_modules' ] }, ['javascript']);
    watch({ glob: [ 'app/views/jade/**' ] }).on('data', function (file) { 
        lrServer.changed(file.path);
    });
});

@AustinMontoya
Copy link

For anyone who is still waiting for this to get fixed in gaze, I built a small module called glob-expander that acts as a partial workaround. It will pick up new files in any existing directories. Unfortunately, it doesn't pick up directories that have been added after watch runs, but it's better than explicitly listing out all of your existing folders.

@artch's original example can be re-written as such with this new package:

var gulp = require('gulp'),
      watch = require('gulp-watch'),
      expandGlob = require('glob-expander');

gulp.task('default', function () {   
  watch({glob: expandGlob('subfolder/**/*.txt'), silent: false, verbose: true})               
})

Note that I'm only advocating this as a temporary workaround until gaze fixes their issue. YMMV

@floatdrop
Copy link
Owner

Did you check gaze@0.6.x (gulp-watch uses 0.5.x)? Would it fix it for you?

@ianmstew
Copy link

I just substituted gaze@0.6.4 for 0.5.x underneath glob-watching, and gulp.watch fails silently (no effect).

@artch
Copy link
Author

artch commented Oct 6, 2014

So this isn't still handled in gaze 0.6.x as well?

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

5 participants