sindresorhus / gulp-nunjucks

Precompile Nunjucks templates
MIT License
152 stars 20 forks source link

Update extension by changing file path #27

Closed froddd closed 6 years ago

froddd commented 6 years ago

setting file.extname = '.js' seems to only work on Vinyl file objects, meaning tests are passing but precompiling produces .html files when run on actual templates. Updating the file path using the Node path module works on all files.

sindresorhus commented 6 years ago

The file there is a Vinyl file object, though.

froddd commented 6 years ago

When the tests are run, file is a Vinyl object. The file passed from through2 isn't.

froddd commented 6 years ago
$ npm install gulp through2 vinyl
$ echo '<h1>test</h1>' > template.html

gulpfile.js:

const gulp = require('gulp');
const through = require('through2');
const vinyl = require('vinyl');

gulp.task('default', () =>
  gulp.src('template.html')
    .pipe(through.obj(function (file, enc, cb) {
      console.log('File is Vinyl:', vinyl.isVinyl(file))
      cb(null, file)
    }))
);
$ gulp
[14:02:24] Using gulpfile ~/test-nunjucks/gulpfile.js
[14:02:24] Starting 'default'...
File is Vinyl: false
[14:02:24] Finished 'default' after 20 ms
sindresorhus commented 6 years ago

Returns a stream of Vinyl files that can be piped to plugins. - https://github.com/gulpjs/gulp/blob/master/docs/API.md#gulpsrcglobs-options

The problem is that Vinyl is outdated in Gulp v3.

sindresorhus commented 6 years ago

I've fixed this in a patch release.