vercel / micro-dev

The development environment for `micro`
MIT License
705 stars 77 forks source link

--ignore option not accepting glob #110

Open hitochan777 opened 4 years ago

hitochan777 commented 4 years ago

According to the help shown by -h, --ignore option should accept glob. However when I run with --ignore *.sqlite3, it throws an error saying:

(node:16493) UnhandledPromiseRejectionWarning: SyntaxError: Invalid regular expression: /*.sqlite3/: Nothing to repeat
This is because it uses RegExp to construct regexp object from the string and `*` is interpreted as arbitrary repetition but nothing precedes it (by the way RegExp is introduced in [this PR](https://github.com/zeit/micro-dev/pull/54)). 

Should we properly handle glob instead of relying on RegExp?

hitochan777 commented 4 years ago

I figured out the problem myself. micro-dev relies on chokidar for file watcher, and chokidar relies on anymatch for pattern matching. According to the documentation of anymatch, something like .idea to absolute path does not match. Instead we have to pass **/.idea/** if we want to ignore without using RegExp.

anymatch('node_modules/**', '/absolute/path/to/node_modules/somelib/index.js'); // false
anymatch('**/node_modules/**', '/absolute/path/to/node_modules/somelib/index.js'); // true