gulp icon indicating copy to clipboard operation
gulp copied to clipboard

gulp.watch not works if watched glob contains Japanese characters folder name

Open aruku7230 opened this issue 6 years ago • 10 comments

  • gulp: 4.00
  • node: 8.9.4
  • npm: 5.8.0
  • OS: macOS 10.12.6

gulpfile.json

const gulp = require('gulp');
const watchGlob = 'folder/**/*';

gulp.task('test', () => {
    gulp.watch(watchGlob, (done) => { done() })
            .on('change', (path) => {
                console.log(`File ${path} changed.`);
            });
});

run test task and change folder/foo file result output is:

Starting 'test'... File folder/foo changed. Starting ''... Finished '' after 1.45 ms

change watchGlob

const watchGlob = 'フォルダ/**/*';

run test task and change フォルダ/foo file. result output is:

Starting 'test'...

aruku7230 avatar Apr 13 '18 12:04 aruku7230

This is most likely a bug in one of the underlying libraries gulp uses for file watching. Interestingly, the フォルダ/** and フォルダ/* glob patterns do react as expected, as does changing a file like フォルダ/foo/bar.

rgroothuijsen avatar Apr 30 '18 21:04 rgroothuijsen

Can you test it with https://github.com/paulmillr/chokidar directly and see if you can reproduce it? If so the issue goes there, if not we can look into it here.

Thanks for the report.

yocontra avatar Apr 30 '18 21:04 yocontra

Reproduce it use chokidar. It's a issue with chokidar.

const watchGlob = 'フォルダ/**/*';

gulp.task('test', () => {
    const chokidar = require('chokidar');
    chokidar.watch(watchGlob, (done) => { done() })
            .on('change', (path) => {
                console.log(`File ${path} changed.`);
            });
});

aruku7230 avatar May 12 '18 05:05 aruku7230

This issue is due to micromatch which is used in chokidar.

sttk avatar May 12 '18 07:05 sttk

I think it related to NFD filename on macOSX. NFD's "ダ" is "タ" + " " ". NFD's "ダ" chrcode deffer from NFC's "ダ" chrcode.

MasatoMakino avatar Aug 23 '18 11:08 MasatoMakino

We've just added a Bug Bounty of $50 on this issue if anyone wants to solve it.

phated avatar Nov 14 '18 19:11 phated

I think I have the issue narrowed down to a RegExp in the nanomatch package. This issue is not restricted to Japanese, but to any directory that doesn't end in 0-9, a-z, A-Z, or _. I opened https://github.com/micromatch/nanomatch/issues/18.

pe8ter avatar Nov 18 '18 06:11 pe8ter

but to any directory that doesn't end in 0-9, a-z, A-Z, or _.

The regex was written to only match valid path characters, but this clearly was shortsighted and insensitive to non-English languages. I will get that fixed.

jonschlinkert avatar Nov 18 '18 07:11 jonschlinkert

I'd also happily accept a PR to fix it if someone wants to earn the bounty. Just let me know.

jonschlinkert avatar Nov 18 '18 07:11 jonschlinkert

This is actually going to have to wait until gulp 5.0 to be fixed because it relies on a rewrite of the micromatch parser (which only made sense to be released as a major), and that version will only be used in a version of chokidar that doesn't support all versions of nodejs we support in 4.x

phated avatar Apr 20 '19 17:04 phated