carlitoplatanito / gulp-nunjucks-render

[Gulp](https://github.com/wearefractal/gulp) plugin to render [Nunjucks](http://mozilla.github.io/nunjucks/) templates
149 stars 33 forks source link

Small Changes to Parent Template Not Detected #47

Open 58bits opened 8 years ago

58bits commented 8 years ago

Sorry - re-opening this, as it's not the IDE. I just tried editing and compiling the parent template in Vim and the same problem occurs.


Have a weird problem with nunjucks. When I make small changes to a comment section in a parent template, the 'page' template that extends the parent, does not get compiled (although the file to be compiled is being passed to nunjucks). If I type an extra word or two in the source parent template, all works as expected. I suspect this is a nunjucks problem, and not gulp-nunjucks-render - but thought I'd post here as well just in case I'm missing something obvious.

Here's the issue I've posted with nunjucks... https://github.com/mozilla/nunjucks/issues/811

58bits commented 8 years ago

It appears to be a problem with Gulp (Gulp 4 in this case). The timestamp of the output file is not being updated - in fact, the timestamp is being set 'back' in time 0_0.

kamlekar commented 8 years ago

As I had already commented: https://github.com/carlosl/gulp-nunjucks-render/issues/46#issuecomment-240906591

Same issue happened with me as well which I fixed by commenting source maps code in gulp file. Though, I am not sure whether you are using sourcemaps or not.

58bits commented 8 years ago

Okay I think I've found the problem. The timestamp is not being updated, because the page template has not been changed, only the parent template - and the source file object is being reused here file.contents = new Buffer(result); in https://github.com/carlosl/gulp-nunjucks-render/blob/master/index.js

Thinking about this a bit more, in most cases this is the desired behavior, however, in a cases where parent template files are updated, all of the child templates will need to be 'touched', or alternatively, perhaps there could be a 'force-update' option. Not sure.

58bits commented 8 years ago

Here's the complete task, showing how in Gulp 4 - we can use the 'since' option to ignore pages that have not been updated. This takes care of any templates that should be ignored, because there have been no changes, however, it doesn't solve the parent template problem, which should force a complete re-compile and re-render, with new timestamps for all child templates.

Of course Git and the IDE will detect larger changes based on file size, but smaller changes in a parent template (less than a block size for the file on disk) will go undetected.

gulp.task('compile', function () {
  return gulp.src('./app/views/pages/**/*.+(html|njk)', {since: gulp.lastRun('compile') })
    .pipe(data(function () {
      return {
        bust: loadRevisionManifest('./app/data/rev-manifest.json'),
        timestamp: `Infonomic.io compiled at ${new Date().toISOString()} ${uuid.v4()}`
      }
    }))
    .pipe(nunjucks({
      path: ['./app/views/templates'],
      manageEnv: nunjucksEnvironment
    }))
    .pipe(gulp.dest('./public'))
});
58bits commented 8 years ago

Here's the related Gulp issues, although not sure what the outcome is here... https://github.com/gulpjs/gulp/issues/1461

58bits commented 8 years ago

Here's my interim solution.... using gulp-shell.

var nunjucks = require('gulp-nunjucks-render');
var shell = require('gulp-shell');

gulp.task('compile', function () {
  return gulp.src('./app/views/pages/**/*.+(html|njk)')
    .pipe(nunjucks({
      path: ['./app/views/templates'],
    }))
    .pipe(gulp.dest('./public'))
    .pipe(shell([
      'touch <%= file.path %>',
    ]))
});
lf87 commented 6 years ago

Are there any updates on this? I'm having a very similar, if not the exact same issue.

Detailed here: https://stackoverflow.com/questions/49233603/detect-changes-between-multiple-source-files-using-gulp