Skip to content
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

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

Open
nimo23 opened this issue Jul 17, 2015 · 11 comments
Open

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

nimo23 opened this issue Jul 17, 2015 · 11 comments

Comments

@nimo23
Copy link

nimo23 commented Jul 17, 2015

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.

@sholladay
Copy link

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

@jdnichollsc
Copy link

+1
Is very important remove deleted files :/

@tschaub
Copy link
Owner

tschaub commented Mar 23, 2016

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.

@jdnichollsc
Copy link

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
Copy link

Can gulp-newer works with subdirectories?

@tschaub
Copy link
Owner

tschaub commented Mar 24, 2016

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.

@jdnichollsc
Copy link

yes, is correct :)

@jdnichollsc
Copy link

@nimo23 See my example! 👯 #33 (comment)

@retrocausal
Copy link

retrocausal commented May 2, 2016

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
Copy link

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?

@jimbuck
Copy link

jimbuck commented Jun 7, 2016

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?)
    }
  });
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants