tschaub / gulp-newer

Pass through newer source files only
https://npmjs.org/package/gulp-newer
226 stars 24 forks source link

'extra' not working as expected, always includes all source-files #41

Closed ClemensSchneider closed 7 years ago

ClemensSchneider commented 8 years ago

I tried to add gulp-newer to my SCSS task, to only process changed files but to process all files in case one of the settings-files (e.g. _settings.scss) has changed. The extra-parameter looked promising for this but didn't work out as expected. My task is defined as follows:

return gulp.src(['app/styles/**/*.scss', '!app/styles/**/_*.scss'])
    .pipe($.plumber({errorHandler: $.notify.onError("Error: <%= error.message %>")}))
    .pipe($.newer({ dest : '.tmp/styles', ext: '.css', extra: 'app/styles/**/_*.scss' }))
    .pipe($.sourcemaps.init())
    .pipe($.sass.sync({
      outputStyle: 'expanded',
      precision: 10,
      includePaths: ['.']
    }).on('error', $.sass.logError))
    .pipe($.autoprefixer({browsers: ['> 1%', 'last 2 versions', 'ie >= 9', 'Firefox > 30', 'and_chr >= 2.3']}))
    .pipe($.sourcemaps.write())
    .pipe(gulp.dest('.tmp/styles'))
    .pipe(reload({stream: true}));
});

Before adding the extra-parameter, only the newer files were processed as expected. When changing the settings-files (e.g. _settings.scss), nothing happened. Now, by adding the settings-files as glob via extra-parameter, all files were processed all the time, no matter which file was changed.

Looks like the issue is with the check if bufferedFiles are available:

if (self._bufferedFiles) {
          // flush buffer
          self._bufferedFiles.forEach(function(file) {
            self.push(file);
          });
          self._bufferedFiles.length = 0;
          // pass through all remaining files as well
          self._all = true;
        }

When using the extra-parameter, bufferedFiles are initialized no matter what and then, if one of the source-files has changed (even if none of the extra-files is newer), all files are passed through...

CydGoblin commented 8 years ago

same problem, here is my task

gulp.task('pug', function buildHTML() {
  return watch('./src/pug/**/*.pug', function () {
    gulp.src('./src/pug/*.pug')
      .pipe(newer({ dest: './src/', ext: '.html', extra: './src/pug/includes/page-layout.pug'}))
      .pipe(pug({
        pretty: true
      }))
      .pipe(gulp.dest('./src'))
      .pipe(browserSync.stream());
  });
});
ClemensSchneider commented 8 years ago

Is there a fix to be expected any time soon?