New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support ignore
option for glob import
#2495
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 |
@@ -59,7 +60,7 @@ export async function transformImportGlob( | |||
} | |||
const files = glob.sync(pattern, { | |||
cwd: base, | |||
ignore: ['**/node_modules/**'] | |||
ignore: ['**/node_modules/**', ...(ignore ? [ignore] : [])] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The other solution of #1903 would be something like import.meta.glob('...', { node_modules: true })
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I will implement it later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 ignoringcomponents
orutils
directories, 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:components
orutils
directory.
or_
d.ts
test.ts
,spec.ts
,e2e.ts
That will be difficult to achieve if only one pattern can be specified (make duplicated multiple level path rule in
glob pattern
is very difficult, See mrmlnc/fast-glob#306), but that can be easy if theignore
option offast-glob
can 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.js
will be ignored, the above will be transformed into the following: