feat: support ignore option for glob import#2495
Conversation
|
Seems it will be better to support multiple patterns instead of the fg.sync(['*.json', '!package-lock.json']); // ['package.json']
fg.sync('*.json', { ignore: ['package-lock.json'] }); // ['package.json']I will try to support multiple patterns. |
|
Oops, this PR lacks some processing of |
…test results in different environments
|
It will be helpful for me, to write like import.meta.glob(`./**/index.vue`, { deep: 1 }) |
|
I will suggest only support pattern like |
| const files = glob.sync(pattern, { | ||
| cwd: base, | ||
| ignore: ['**/node_modules/**'] | ||
| ignore: ['**/node_modules/**', ...(ignore ? [ignore] : [])] |
There was a problem hiding this comment.
Should we also overwrite the default ignore option if the user explicit set ignore option. In that case, we could also close #1903 by import.meta.glob('...', { ignore: [] }).
There was a problem hiding this comment.
The other solution of #1903 would be something like import.meta.glob('...', { node_modules: true })
There was a problem hiding this comment.
I think we should leave a ignoreNodeModules option (like your second solution) to support this, otherwise, the user will have to manually add the node_modules item every time the ignore option is used.
|
Close in favor of #7537 (targeting v3.0) |
Motivation
Sometimes we need to ignore some files or directories when using
import.meta.glob, such as ignoringcomponentsorutilsdirectories, files beginning with_or., etc.A typical application scenario is:
In a file-based routing system, all files starting with lowercase letters and numbers in the pages directory will be automatically imported as routers by
src/pages/**/[a-z0-9]*.tsx, and the following files or directory will be ignored:componentsorutilsdirectory.or_d.tstest.ts,spec.ts,e2e.tsThat will be difficult to achieve if only one pattern can be specified (make duplicated multiple level path rule in
glob patternis very difficult, See mrmlnc/fast-glob#306), but that can be easy if theignoreoption offast-globcan be specified.Document
You can also pass the second argument to ignore some files:
That will ignore all files whose name starts with
b, the file./dir/bar.jswill be ignored, the above will be transformed into the following: