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: Watch only fires once when used with paths instead of globs #1322

Closed
flying-sheep opened this issue Oct 11, 2015 · 4 comments
Closed

Comments

@flying-sheep
Copy link

Hi, with gulp-babel and gulp 4:

import gulp from 'gulp'
import babel from 'gulp-babel'

const paths = {
    main: 'client/src/main.js',
}

gulp.task('compile-main', () =>
    gulp.src(paths.main, { since: gulp.lastRun('compile-main') })
        .pipe(babel())
        .pipe(gulp.dest('client')))

gulp.task('watch', () =>
    gulp.watch(paths.main, gulp.series('compile-main')))

gulp.task('default', gulp.series('watch'))

this is the output:

[14:52:51] Requiring external module babel-core/register
[14:52:52] Using gulpfile ~/Dev/Web/electro-pub/gulpfile.babel.js
[14:52:52] Starting 'default'...
[14:52:52] Starting 'watch'...

after hitting ctrl-s on the watched file once, this is added:

[14:53:22] Starting 'series'...
[14:53:22] Starting 'compile-main'...
[14:53:23] Finished 'compile-main' after 119 ms
[14:53:23] Finished 'series' after 120 ms

but then each subsequent ctrl-s is ignored.

removing the { since: gulp.lastRun('compile-main') } has no effect.


i know that my editor saves by writing to a tempfile and moving the tempfile to where the original file is, in order to make saves atomic in case of errors.

using a glob instead of a path fixes this, so i guess the problem is that using a path makes the watcher watch a file handle instead of the directory.

@flying-sheep flying-sheep changed the title Gulp 4: Watch only fires once Gulp 4: Watch only fires once when used with paths instead of globs Oct 11, 2015
@phated
Copy link
Member

phated commented Oct 19, 2015

Pinging @es128

@es128
Copy link
Contributor

es128 commented Oct 19, 2015

Seems related to paulmillr/chokidar#237, which is caused by editor atomic save weirdness combined with watching a single file. You already happened upon the workaround solution, which is to force a watcher to be attached at the directory level by using a glob pattern (even a pattern that matches only the particular file like [f]ile.txt will work for this purpose). Some other potential workaround solutions discussed in the linked thread (such as enabling polling or using a different editor).

@phated
Copy link
Member

phated commented Oct 19, 2015

@es128 thanks! going to close since you've outlined all that can be done and pointed to the underlying issue.

@phated phated closed this as completed Oct 19, 2015
@flying-sheep
Copy link
Author

flying-sheep commented Oct 6, 2016

that’s not all that can be done. gulp could e.g. automatically detect file patterns and convert them to glob patterns, like @es128 described.

or chokidar could do it

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

No branches or pull requests

3 participants