Skip to content

Commit 2aafa44

Browse files
authored
fix: globsExclude (unplugin#645)
1 parent cf67b8c commit 2aafa44

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

src/core/options.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,18 @@ function normalizeResolvers(resolvers: (ComponentResolver | ComponentResolver[])
2525
return toArray(resolvers).flat().map(r => typeof r === 'function' ? { resolve: r, type: 'component' } : r)
2626
}
2727

28+
function resolveGlobsExclude(root: string, glob: string) {
29+
const excludeReg = /^!/
30+
return `${excludeReg.test(glob) ? '!' : ''}${resolve(root, glob.replace(excludeReg, ''))}`
31+
}
32+
2833
export function resolveOptions(options: Options, root: string): ResolvedOptions {
2934
const resolved = Object.assign({}, defaultOptions, options) as ResolvedOptions
3035
resolved.resolvers = normalizeResolvers(resolved.resolvers)
3136
resolved.extensions = toArray(resolved.extensions)
3237

3338
if (resolved.globs) {
34-
resolved.globs = toArray(resolved.globs).map((glob: string) => slash(resolve(root, glob)))
39+
resolved.globs = toArray(resolved.globs).map((glob: string) => slash(resolveGlobsExclude(root, glob)))
3540
resolved.resolvedDirs = []
3641
}
3742
else {
@@ -40,7 +45,7 @@ export function resolveOptions(options: Options, root: string): ResolvedOptions
4045
: `{${resolved.extensions.join(',')}}`
4146

4247
resolved.dirs = toArray(resolved.dirs)
43-
resolved.resolvedDirs = resolved.dirs.map(i => slash(resolve(root, i)))
48+
resolved.resolvedDirs = resolved.dirs.map(i => slash(resolveGlobsExclude(root, i)))
4449

4550
resolved.globs = resolved.resolvedDirs.map(i => resolved.deep
4651
? slash(join(i, `**/*.${extsGlob}`))

test/search.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,30 @@ describe('search', () => {
4343

4444
expect(cleanup(ctx.componentNameMap)).toMatchSnapshot()
4545
})
46+
47+
it('should globs exclude work', () => {
48+
const ctx = new Context({
49+
globs: [
50+
'src/components/*.vue',
51+
'!src/components/ComponentA.vue',
52+
],
53+
})
54+
ctx.setRoot(root)
55+
ctx.searchGlob()
56+
57+
expect(cleanup(ctx.componentNameMap).map(i => i.as)).not.toEqual(expect.arrayContaining(['ComponentA']))
58+
})
59+
60+
it('should globs exclude work with dirs', () => {
61+
const ctx = new Context({
62+
dirs: [
63+
'src/components',
64+
'!src/components/book',
65+
],
66+
})
67+
ctx.setRoot(root)
68+
ctx.searchGlob()
69+
70+
expect(cleanup(ctx.componentNameMap).map(i => i.as)).not.toEqual(expect.arrayContaining(['Book']))
71+
})
4672
})

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy