-
Notifications
You must be signed in to change notification settings - Fork 87
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
Only modify files that match the replace expression #70
Comments
Interesting... This definitely sounds like a bug. I'd accept a PR to fix it. |
Sure thing. How about something like the following before the skipBinary check? options = options || {};
if(options.testFirst === null || options.testFirst)
{
if(!String(file.contents).match(search))
{
return callback(null, file);
}
} This way users can opt out of the extra regular expression check if they are more concerned with performance than stream modification. |
Hmm, I'd rather do it without introducing a new option... Perhaps we can perform the replacement as normal, test for equality, and if they're equal, then don't modify the file? |
Okay, fair enough. How about placing the check (without options) at the start of the function doReplace()
{
if(!String(file.contents).match(search))
{
return callback(null, file);
}
... To do it before this point would probably require the check in two places (the |
Is there a problem preventing this fix? |
@akaleeroy the problem is there is no PR with the fix and tests :) Feel free to send one along and I'll review it! |
@lazd Haha, yeah, I figured it out as soon as I ran the tests function doReplace() {
if(!String(file.contents).match(search)) {
return callback(null, null);
}
// ... Swallowing the file by passing |
I worked around this issue using Maybe there should be an option, passthrough |
@akaleeroy Nice gist. It's a shame a fix can't be directly incorporated into |
From what I can tell, the
gulp-replace
modifies all files regardless of whether they match the replace condition or not.My scenario is that
gulp-replace
correctly updates my files but also myfonts
,images
andtext
files that are Unicode format. TheskipBinary
option successfully skips thefonts
&images
but my.txt
files that have unicode characters in them are still left broken.Some other skip options would be nice, but surely it would be better to skip modifying files unless they actually have a match?
Thoughts?
P.S. Thanks for providing a very useful module :)
The text was updated successfully, but these errors were encountered: