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

deleted file in src-directory will not be considered by gulp-newer

Open nimo23 opened this issue 10 years ago • 11 comments
trafficstars

For example, having these files in src-directory :

  • src/a.css
  • src/b.css

and this in target-directory:

  • dist/min.css

Changing the content of "a.css" or putting a new file in src-directory ("c.css") will trigger gulp-newer to make a new "min.css". However, when deleting "a.css", then gulp-newer does not treat it as a change, hence "min.css" will have the content of "a.css" after running the task, even "a.css" does not exist anymore.

Would be nice, if gulp-newer is able to consider deleted files in src-dir.

nimo23 avatar Jul 17 '15 06:07 nimo23

Wouldn't your watch task have to take care of this? Once the file is deleted, there is nothing to compare.

sholladay avatar Sep 02 '15 23:09 sholladay

+1 Is very important remove deleted files :/

jdnichollsc avatar Mar 23 '16 20:03 jdnichollsc

Could someone provide some code or an example that better reproduces the issue?

It is true that the plugin doesn't "consider" deleted files. There is no state retained by the plugin at all. Every time you run it, it compares source file times to destination file times. The act of deleting a file isn't communicated in any way to the plugin.

tschaub avatar Mar 23 '16 22:03 tschaub

For example... I want to use this plugin to compress only the new images using gulp-imagemin (instead of all images), but What happen with the deleted images (in the origin)? I want to delete these automatically

See my example: https://github.com/jdnichollsc/Ionic-Starter-Template/blob/master/gulpfile.js I don't want to delete all the images in the destination, what do you think? :)

jdnichollsc avatar Mar 24 '16 16:03 jdnichollsc

Can gulp-newer works with subdirectories?

jdnichollsc avatar Mar 24 '16 17:03 jdnichollsc

The gulp-newer plugin only limits which source files are included in a pipeline. It is not the job of this plugin to delete files.

If you delete a source file and you want the corresponding destination file to be delete it, you'd need to delete it manually, clean, or use a plugin that deletes selectively. I haven't used it, but gulp-deleted looks like it does the latter.

tschaub avatar Mar 24 '16 22:03 tschaub

yes, is correct :)

jdnichollsc avatar Mar 24 '16 23:03 jdnichollsc

@nimo23 See my example! :dancers: https://github.com/tschaub/gulp-newer/issues/33#issuecomment-201163329

jdnichollsc avatar Mar 25 '16 06:03 jdnichollsc

The issue is this

Let us assume, our css directory has three files

|-project  |-css    |-a.css    |-b.css    |-c.css

And, let our destination look like so:

|-build   |-css     |-concatenated.css

Notice that concatenated.css is,

a.css + b.css + c.css

let our task be defined like so: Task "optimizeCss"

gulp.src(css/**/*.css)
 .pipe(newer('build/css/concatenated.css'))
   .pipe(concat('concatenated.css'))
    .pipe(gulp.dest('build/css'))

Now, let us consider watching the css directory like so:

$.watch(['css/**/*'], ['optimizeCss']);

Run #1: No files are added or modified. SO,No files are newer than concatenated.css, so everything remains same

Run #2: Let us edit a.css Now, since a.css has a timestamp lesser than concatenated.css, all the three files are concatenated again. SO FAR SOOOOO GOOD!

Run #3: Let us DELETE c.css

Now, the source folder which is project/css, contains only

  1. a.css and
  2. b.css

SO, CONCATENATED.CSS = A.CSS + B.CSS

IS that correct??

BUT BUT BUT,

when the Newer task is triggered on deletion of c.css,

the result is

CONCATENATED.CSS = A+B+C

BUT hello! C is no longer there!!!!!!!

then why does the gulp-newer pipe it? It shouldnt

Edit: gulp-newer doesn't pipe anything down the pipline

retrocausal avatar May 02 '16 12:05 retrocausal

Well, I figured the problem is because, when you delete a file,

and no other files are changed, gulp-newer doesn't pipe anything at all

hence, your destination remains unedited to incorporate the deletion

Any workaround for this?

retrocausal avatar May 02 '16 13:05 retrocausal

To borrow inspiration from the gulp-remember usage example, would something like the following work?

gulp.task('watch', function () {
  var watcher = gulp.watch(scriptsGlob, ['scripts']); // watch the same files in our scripts task
  watcher.on('change', function (event) {
    if (event.type === 'deleted') {
      // Handled deleted file (delete the dest file maybe?)
    }
  });
});

jimbuck avatar Jun 07 '16 15:06 jimbuck