gulp-replace
gulp-replace copied to clipboard
Use the same replace in multiple pipes
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?
What do you mean by "fail?" Have you tried using /foo/g?
"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.
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 any update on this? Still an issue?
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-pagesbranch ofmathjs: https://github.com/josdejong/mathjs/tree/gh-pages -
run
npm installin the root of the project -
run
gulp -
verify that after running
gulp, there is a folder/docscontaining the docs, which is how it should be. -
open the file
gulpfile.js, and change line 207 from:.pipe(injectPermalinks2)into:
.pipe(injectPermalinks)here,
injectPermalinksis an instance ofgulp-replace, defined on lines 61-77. After this change, this instance ofinjectPermalinksis used twice in the gulpfile, in two different tasks which can run in parallel. -
run
gulpagain. -
now, at least on my computer, there is NO folder
/docscreated after running gulp.
Isn't it that the first replace replaces all the /foo/ with bar so the second replace has no more /foo/ to find?
@Lefthandmedia no it's the same replacer but used on a different stream of files.
@josdejong is this still an issue?
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)
Ah! Well that gives us something to look into. Thank you for following up!