gulp-replace icon indicating copy to clipboard operation
gulp-replace copied to clipboard

Use the same replace in multiple pipes

Open josdejong opened this issue 11 years ago • 10 comments

When I use the same replace in two pipes, one of the two pipes seemst to fail.

I try something like this:

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

var replaceStuff = replace(/foo/, function (match) {
  // ... do stuff...
  return 'bar';
});

return gulp.src('path')
      .pipe(replaceStuff)
      .pipe(gulp.dest('dest'));

return gulp.src('other/path')
      .pipe(replaceStuff)
      .pipe(gulp.dest('other/dest'));

Is this a bug or am I overlooking something?

josdejong avatar Jul 26 '14 11:07 josdejong

What do you mean by "fail?" Have you tried using /foo/g?

lazd avatar Jul 26 '14 17:07 lazd

"fail" in the sense that no files come through one of the two pipes when I use the same replaceStuff for both, and when I create a separate replaceStuff for both pipes, it works fine and both pipes output (transformed) files.

josdejong avatar Jul 26 '14 18:07 josdejong

I'm trying to write a small example to demonstrate the issue, but the issue doesn't show up in a simple example. I will let you know as soon as I can repeat this issue - maybe it turns out to be a bug in my gulpfile.

josdejong avatar Jul 26 '14 19:07 josdejong

@josdejong any update on this? Still an issue?

lazd avatar Jan 21 '15 18:01 lazd

Thanks for your reply. I haven't found a solution, instead I just created two separate instances of gulp-replace to work around the issue.

I have just updated all depencencies, and the issue is still the case.

I'm not sure whether the cause is in my gulpfile, in gulp-replace, or in gulp itself. If you are interested to have a look at it, you can reproduce the issue as follows:

  • clone the gh-pages branch of mathjs: https://github.com/josdejong/mathjs/tree/gh-pages

  • run npm install in the root of the project

  • run gulp

  • verify that after running gulp, there is a folder /docs containing the docs, which is how it should be.

  • open the file gulpfile.js, and change line 207 from:

    .pipe(injectPermalinks2)

    into:

    .pipe(injectPermalinks)

    here, injectPermalinks is an instance of gulp-replace, defined on lines 61-77. After this change, this instance of injectPermalinks is used twice in the gulpfile, in two different tasks which can run in parallel.

  • run gulp again.

  • now, at least on my computer, there is NO folder /docs created after running gulp.

josdejong avatar Jan 22 '15 10:01 josdejong

Isn't it that the first replace replaces all the /foo/ with bar so the second replace has no more /foo/ to find?

Lefthandmedia avatar Mar 28 '19 13:03 Lefthandmedia

@Lefthandmedia no it's the same replacer but used on a different stream of files.

josdejong avatar Mar 28 '19 19:03 josdejong

@josdejong is this still an issue?

lazd avatar Apr 22 '21 16:04 lazd

It has been some time 😅 . Yes same issue. When I follow the steps I wrote here https://github.com/lazd/gulp-replace/issues/21#issuecomment-71000659, I get the same end result (no docs being generated), but an error is thrown now instead of silence:

Error: write after end
    at writeAfterEnd (...\mathjs-pages\node_modules\readable-stream\lib\_stream_writable.js:288:12)

josdejong avatar Apr 24 '21 20:04 josdejong

Ah! Well that gives us something to look into. Thank you for following up!

lazd avatar Apr 26 '21 01:04 lazd