0

If I make two files in two sibling directories with different content:

nvioli$ echo "a" > test1/file.txt
nvioli$ echo "b" > test2/file.txt

then use gulp to output the first one to a destination folder, and try to overwrite it with the second one, filtering with gulp-changed using the Sha1Digest comparator:

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

gulp.task('test1', function(){
        return gulp.src("test1/file.txt")
            .pipe(gulp.dest("dst"))
    });

gulp.task('test2', function(){
        return gulp.src("test2/file.txt")
            .pipe(changed("dst"), {hasChanged: changed.compareSha1Digest})
            .pipe(gulp.dest("dst"))
    });

nvioli$ gulp test1
[16:18:01] Using gulpfile ~/git/node/gulpfile.js
[16:18:01] Starting 'test1'...
[16:18:01] Finished 'test1' after 12 ms
nvioli$ gulp test2
[16:18:16] Using gulpfile ~/git/node/gulpfile.js
[16:18:16] Starting 'test2'...
[16:18:16] Finished 'test2' after 22 ms

I would expect the file to be overwritten since the source file in test2 differs in content from the existing one in the dst folder, but this is not the case:

nvioli$ cat dst/file.txt
a

Can someone please clear up my misunderstanding?

nvioli
  • 4,137
  • 3
  • 22
  • 38

1 Answers1

1

I guess the options have to be part of the changed() plugins arguments. (;

Change

.pipe(changed("dst"), {hasChanged: changed.compareSha1Digest})

to

.pipe(changed("dst", {hasChanged: changed.compareSha1Digest}))
naeramarth7
  • 6,030
  • 1
  • 22
  • 26