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.dest() does not close files when using from watch() #2403

Open
petr-buchin opened this issue Dec 19, 2019 · 4 comments
Open

gulp.dest() does not close files when using from watch() #2403

petr-buchin opened this issue Dec 19, 2019 · 4 comments

Comments

@petr-buchin
Copy link

petr-buchin commented Dec 19, 2019

I needed to create new issue since @phated closed my previous issue

What were you expecting to happen?
I'm running gulp.watch() locally to recompile static files in public/dist directory.
I also watch public/dist directory with Skaffold to propagate changes to containers in my Kubernetes cluster.
What actually happened?
File changes does not get propagated when files are changed by gulp, but they propagated when I change them by some text redactor.
I traced gulp process and looks like gulp does not close files when writes to them.
I searched for some option in gulp.dest() but did not find anything.

Also interesting, that tasks, which are triggered from watch(), work good and close files when they are triggered not inside watch().

Please post a sample of your gulpfile (preferably reduced to just the bit that's not working)
This task is running from .gulp.watch() task

gulp.task('myapp.js', () => {
  return gulp.src(SRC_PATH + '/myapp.app.js')
    .pipe(plumber())
    .pipe(bro({
      transform: [
        babelify,
        [browserifyCss, { global: true }]
      ]
    }))
    .pipe(rename('myapp.min.js'))
    .pipe(base64())
    .pipe(development(sourcemaps.init({ loadMaps: true })))
    .pipe(production(ngAnnotate()))
    .pipe(production(uglify()))
    .pipe(development(sourcemaps.write('.')))
    .pipe(production(rev()))
    .pipe(assetManifest({
      bundleName: 'myapp-scripts',
      log: development() && !isWatching,
      manifestFile: MANIFEST_FILE,
      pathPrepend: MANIFEST_PREPEND_PATH
    }))
    .pipe(gulp.dest(getTenantAssetsPath('myapp')))
});

What version of gulp are you using?
4.0.2

What versions of npm and node are you using?
NPM: 6.11.3
Node: v10.17.0
OS: MacOs Catalina

@phated
Copy link
Member

phated commented Dec 19, 2019

Depending on what watcher you are using, you might need to update your fs.Stats on the files you are creating. https://gulpjs.com/docs/en/api/dest#metadata-updates

@phated
Copy link
Member

phated commented Dec 19, 2019

If nothing in your pipeline updates fs.Stats, we will create a file with the same timestamp as the source inputs.

@petr-buchin
Copy link
Author

@phated after some research, I realized that skaffold uses golang lib fsnotify, which tries to open file in exclusive mode before notifying about file change.
Is there some possibility in gulp to not keep files open during watch?

@bakura10
Copy link

Hi,

I have a similar issue that I'm not able to solve (only on Gulp 4, Gulp 3 works correctly). My use case is pretty similar: I have one watcher that is doing some processing, and copying the result file into a different folder. Then I have another watcher that watches for changes in this directory. If I manually change the file in text editor, the wathcer works. However if the file is changed by the first watch task, then the second watch does not detect the change. It looks like this:

function css() {
  return src('css/theme.css')
    // Do stuff and copy result to another folder
    .pipe(dest('dist/assets'));
}

exports.default = () => {
  watch('css/**/*.css', css);
  watch('dist/assets/theme.css', () => {
    // Only outputted if I manually edit the "dist/assets/theme.css" file, but never when the file is changed by the first task
    console.log('foo');
  });
};

What are the options (beside downgrading to Gulp 3) to achieve that @phated ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

3 participants