micro-dev icon indicating copy to clipboard operation
micro-dev copied to clipboard

--ignore option not accepting glob

Open hitochan777 opened this issue 4 years ago • 1 comments

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 avatar Nov 06 '19 11:11 hitochan777

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

hitochan777 avatar Nov 06 '19 13:11 hitochan777