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

Gulp 4: gulp.watch().on('rename') feature request #1927

Closed
Dan503 opened this issue Mar 12, 2017 · 2 comments
Closed

Gulp 4: gulp.watch().on('rename') feature request #1927

Dan503 opened this issue Mar 12, 2017 · 2 comments

Comments

@Dan503
Copy link

Dan503 commented Mar 12, 2017

This has become a major pain point for me in Gulp 4.

I have tasks that I will want to have occur both when a file is added and removed from the file system.

What were you expecting to happen?

I have this basic code where it watches my sass files. If I add or remove an scss file from the folder structure, I want my sass task to do a full re-compile (ie. do extra stuff like generating new files). If I just make changes it only does a basic compile with whatever files already exist.

gulp.watch([
  '**/*.scss',
])
.on('unlink', gulp.series('sass:+extra'))
.on('add', gulp.series('sass:+extra'))
.on('change', gulp.series('sass:compile'));

I would also want the 'sass:+extra' task to run when a sass file is renamed. And it does... however...

What actually happened?

When I rename a file, it will run 'sass:+extra' twice.

I understand why it does this. I'm both adding and removing a file from the file system at the same time and thus I'm triggering both events and firing the task twice.

This is very difficult to work around. Debounce functions don't even seem to prevent it.

If there was a gulp.watch().on('rename') feature that paid attention to files that are being added and removed from the file system simultaneously, and blocked the unlink and add events from firing when the event is triggered, it would solve the issue.

So ideally, I would want to be able to write Pug code like this, and only have the sass:+extra task run only once based on the action that occurred:

gulp.watch([
  '**/*.scss',
])
.on('rename', gulp.series('sass:+extra'))
.on('unlink', gulp.series('sass:+extra'))
.on('add', gulp.series('sass:+extra'))
.on('change', gulp.series('sass:compile'));

What version of gulp are you using?

CLI version 1.2.2
Local version 4.0.0-alpha.2

What versions of npm and node are you using?

node 4.4.7
npm 3.10.6

@Dan503 Dan503 changed the title Gulp 4: gulp.watch().on('rename') feature request Gulp 4: gulp.watch().on('rename') feature request Mar 12, 2017
@phated
Copy link
Member

phated commented Mar 12, 2017

We return a chokidar instance, so you should ask them on their repository. I'm guessing they will say no because it's not a trivial thing and the native libraries don't expose it.

@phated phated closed this as completed Mar 12, 2017
@Dan503
Copy link
Author

Dan503 commented Mar 13, 2017

Ok, the issue already exists in Chokidar: paulmillr/chokidar#303

It's been open since 2015 and it still hasn't been fixed yet :(

There is a code snippet they have provided though that should help prevent tasks from running twice.

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

2 participants