sindresorhus / gulp-rev

Static asset revisioning by appending content hash to filenames: `unicorn.css` → `unicorn-d41d8cd98f.css`
MIT License
1.54k stars 217 forks source link

Writing to/modifying existing manifest file fails #57

Closed rthauby closed 10 years ago

rthauby commented 10 years ago

As described in this section of the README

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

gulp.task('default', function () {
    // by default, gulp would pick `assets/css` as the base,
    // so we need to set it explicitly:
    return gulp.src([
        'assets/css/*.css',
        'assets/js/*.js'
    ], {base: 'assets'})
        .pipe(gulp.dest('build/assets'))
        .pipe(rev())
        .pipe(gulp.dest('build/assets'))

        // Add rev-manifest.json as a new src to prevent rev'ing rev-manifest.json
        .pipe(gulp.src('build/assets/rev-manifest.json', {base: 'assets'}))
        .pipe(rev.manifest())             // applies only changes to the manifest
        .pipe(gulp.dest('build/assets'));
});

Opening a second gulp.src gives me the following error, which I can't seem to work around. Any ideas?

stream.js:94
      throw er; // Unhandled stream error in pipe.
            ^
Error: write after end
rthauby commented 10 years ago

Fwiw, this is what my task looks like:

gulp.task('compress:sass', function(){
  return gulp.src(paths.dest.css + '/**/*.css')
    .pipe( $.clean() )
    .pipe( $.rev() )
    .pipe( gulp.dest(paths.dest.css) )
    .pipe( gulp.src(paths.dest.root + '/rev-manifest.json') )
    .pipe( $.rev.manifest() )
    .pipe( gulp.dest(paths.dest.root) );
});
codekirei commented 10 years ago

Duplicate of #55.

The functionality described in the section you quoted from the readme does not seem to be working atm; it was added by a recent PR.

I could definitely be mistaken, but I don't believe gulp allows you to call gulp.src inside a .pipe() mid-stream. I get that write after end error every time I try it.

Until this gets fixed, I recommend a combination of gulp-rename and/or gulp-extend as described by @bobthecow in #28 to avoid overwriting rev-manifest.json.

bobthecow commented 10 years ago

@sindresorhus thoughts?

sindresorhus commented 10 years ago

From the gulp changelog:

gulp.src is now a writable passthrough, this means you can use it to add files to your pipeline at any point

If that doesn't work it's a bug in gulp and should be reported there.

codekirei commented 10 years ago

@sindresorhus I believe there are two unrelated bugs in play here:

  1. Calling gulp.src mid-stream errors out. As you stated, that's gulp specific and not relevant to gulp-rev. Seems to be a known issue.
  2. Adding rev-manifest.json to src in a way that works around the above bug (e.g. event-stream.merge or gulp-filter, both tried in #55) does not preserve the contents of the original rev-manifest.json. gulp-rev writes a new manifest on each run without regard to the old manifest passed in as source.

If 2. is true, #51 is broken. Maybe that was all obvious... If so, my apologies. Just trying to help :)

sindresorhus commented 10 years ago

@codekirei You're right, gulp.src seems to be broken... Just closing this as it's a duplicate of #55, as you noted. Really appreciate your help triaging issues :)