gulp
gulp copied to clipboard
gulp.watch not works if watched glob contains Japanese characters folder name
- 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'...
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
.
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.
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.`);
});
});
This issue is due to micromatch
which is used in chokidar
.
I think it related to NFD filename on macOSX. NFD's "ダ" is "タ" + " " ". NFD's "ダ" chrcode deffer from NFC's "ダ" chrcode.
We've just added a Bug Bounty of $50 on this issue if anyone wants to solve it.
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.
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.
I'd also happily accept a PR to fix it if someone wants to earn the bounty. Just let me know.
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