lazd / gulp-replace

A string replace plugin for gulp
MIT License
496 stars 88 forks source link

Replaces first 1-2 times then does not replace #105

Closed zeshanshani closed 4 years ago

zeshanshani commented 4 years ago

Hi guys, first of all, thank you so much for this great package!

Secondly, I am facing a strange issue that when I run the replacement function for the first 1-2 times, it works perfectly fine. Then suddenly for no reason, it stops working. What I am trying to do is to replace a number value using Regex to the timestamp.

The strange thing is that, when I change the value in my Gulpfile to anything else and then run the code, it works perfectly.

Here is my code:

gulp.task('cacheClear', () => {
    var date = new Date(),
        year = date.getFullYear(),
        month = date.getMonth(),
        day = date.getDate(),
        time = date.getTime(),
        today = year + ( month + 1 ) + day + time;

    return gulp
        .src( 'functions.php' ) // Only run on changed files.
        .pipe( replace( /(define\(\s'ZAWPCACHEDATE', )(.+)(\s\);)/g, '$1' + today + '$3' ) )
        .pipe( gulp.dest( './' ) )
        .pipe( notify({ message: '\n\n✅  ===> CACHE — cleared!\n', onLast: true }) );
});

And the string I am matching is this:

define( 'ZAWPCACHEDATE', 1588786823051 );

And the replacement number is this:

1588786823051

What could it be? Permission issue or some setting perhaps?

It would be great if you can help me with this. Thank you so much in advance!

lazd commented 4 years ago

Hmm, like it only replaces in the first couple files? Or only replaces the first couple matches? Try to create a CodePen/repository/failing test reproducing the problem and re-open this issue if you can repro it.