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

Small Changes to Parent Template Not Detected #47

Open
58bits opened this issue Aug 19, 2016 · 7 comments
Open

Small Changes to Parent Template Not Detected #47

58bits opened this issue Aug 19, 2016 · 7 comments

Comments

@58bits
Copy link

58bits commented Aug 19, 2016

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... mozilla/nunjucks#811

@58bits
Copy link
Author

58bits commented Aug 19, 2016

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
Copy link
Contributor

As I had already commented: #46 (comment)

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
Copy link
Author

58bits commented Aug 19, 2016

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
Copy link
Author

58bits commented Aug 19, 2016

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 58bits changed the title Small Changes Not Compiled Small Changes to Parent Template Not Detected Aug 19, 2016
@58bits
Copy link
Author

58bits commented Aug 19, 2016

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

@58bits
Copy link
Author

58bits commented Aug 19, 2016

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
Copy link

lf87 commented Mar 14, 2018

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

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

3 participants