diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8e031e46..53fc27dd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,13 +15,13 @@ jobs: steps: - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v4 + - name: Set node uses: actions/setup-node@v4 with: node-version: lts/* - - run: corepack enable - - name: Setup run: npm i -g @antfu/ni @@ -43,13 +43,13 @@ jobs: steps: - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v4 + - name: Set node version to ${{ matrix.node }} uses: actions/setup-node@v4 with: node-version: ${{ matrix.node }} - - run: corepack enable - - name: Setup run: npm i -g @antfu/ni diff --git a/package.json b/package.json index 19c0076b..f3022ea4 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "unplugin-vue-components", "type": "module", - "version": "28.3.0", + "version": "28.4.0", "packageManager": "pnpm@10.4.0", "description": "Components auto importing for Vue", "author": "antfu ", diff --git a/src/core/declaration.ts b/src/core/declaration.ts index 2c4b633d..99a5945e 100644 --- a/src/core/declaration.ts +++ b/src/core/declaration.ts @@ -118,6 +118,7 @@ export function getDeclaration(ctx: Context, filepath: string, originalImports?: // @ts-nocheck // Generated by unplugin-vue-components // Read more: https://github.com/vuejs/core/pull/3399 +// biome-ignore lint: disable export {} /* prettier-ignore */ diff --git a/src/core/fs/glob.ts b/src/core/fs/glob.ts index eb917792..912d326b 100644 --- a/src/core/fs/glob.ts +++ b/src/core/fs/glob.ts @@ -12,6 +12,7 @@ export function searchComponents(ctx: Context) { onlyFiles: true, cwd: root, absolute: true, + expandDirectories: false, }) if (!files.length && !ctx.options.resolvers?.length) diff --git a/src/core/options.ts b/src/core/options.ts index 2c3939dc..fa4b1ddb 100644 --- a/src/core/options.ts +++ b/src/core/options.ts @@ -4,7 +4,7 @@ import { slash, toArray } from '@antfu/utils' import { getPackageInfoSync, isPackageExists } from 'local-pkg' import { detectTypeImports } from './type-imports/detect' -export const defaultOptions: Omit, 'include' | 'exclude' | 'excludeNames' | 'transformer' | 'globs' | 'directives' | 'types' | 'version'> = { +export const defaultOptions: Omit, 'include' | 'exclude' | 'excludeNames' | 'transformer' | 'globs' | 'globsExclude' | 'directives' | 'types' | 'version'> = { dirs: 'src/components', extensions: 'vue', deep: true, @@ -17,7 +17,6 @@ export const defaultOptions: Omit, 'include' | 'exclude' | 'ex transformerUserResolveFunctions: true, resolvers: [], - globsExclude: [], importPathTransform: v => v, @@ -30,7 +29,7 @@ function normalizeResolvers(resolvers: (ComponentResolver | ComponentResolver[]) function resolveGlobsExclude(root: string, glob: string) { const excludeReg = /^!/ - return `${excludeReg.test(glob) ? '!' : ''}${resolve(root, glob.replace(excludeReg, ''))}` + return slash(`${excludeReg.test(glob) ? '!' : ''}${resolve(root, glob.replace(excludeReg, ''))}`) } export function resolveOptions(options: Options, root: string): ResolvedOptions { @@ -39,7 +38,8 @@ export function resolveOptions(options: Options, root: string): ResolvedOptions resolved.extensions = toArray(resolved.extensions) if (resolved.globs) { - resolved.globs = toArray(resolved.globs).map((glob: string) => slash(resolveGlobsExclude(root, glob))) + resolved.globs = toArray(resolved.globs) + .map(glob => resolveGlobsExclude(root, glob)) resolved.resolvedDirs = [] } else { @@ -48,17 +48,38 @@ export function resolveOptions(options: Options, root: string): ResolvedOptions : `{${resolved.extensions.join(',')}}` resolved.dirs = toArray(resolved.dirs) - resolved.resolvedDirs = resolved.dirs.map(i => slash(resolveGlobsExclude(root, i))) - resolved.globs = resolved.resolvedDirs.map(i => resolved.deep - ? slash(join(i, `**/*.${extsGlob}`)) - : slash(join(i, `*.${extsGlob}`)), - ) + const globs = resolved.dirs.map(i => resolveGlobsExclude(root, i)) + + resolved.resolvedDirs = globs.filter(i => !i.startsWith('!')) + resolved.globs = globs.map((i) => { + let prefix = '' + if (i.startsWith('!')) { + prefix = '!' + i = i.slice(1) + } + return resolved.deep + ? prefix + slash(join(i, `**/*.${extsGlob}`)) + : prefix + slash(join(i, `*.${extsGlob}`)) + }) if (!resolved.extensions.length) throw new Error('[unplugin-vue-components] `extensions` option is required to search for components') } + if (!resolved.globsExclude) + resolved.globsExclude = [`**/node_modules/**`] + resolved.globsExclude = toArray(resolved.globsExclude || []) + .map(i => resolveGlobsExclude(root, i)) + + // Move negated globs to globsExclude + resolved.globs = resolved.globs.filter((i) => { + if (!i.startsWith('!')) + return true + resolved.globsExclude.push(i.slice(1)) + return false + }) + resolved.dts = !resolved.dts ? false : resolve( diff --git a/src/core/resolvers/tdesign.ts b/src/core/resolvers/tdesign.ts index 4ebf3e4d..283d7368 100644 --- a/src/core/resolvers/tdesign.ts +++ b/src/core/resolvers/tdesign.ts @@ -46,6 +46,13 @@ export function TDesignResolver(options: TDesignResolverOptions = {}): Component } } + if (name.startsWith('TTypography') || name.startsWith('Typography')) { + return { + name: name.slice(name.startsWith('TTypography') ? 11 : 10), + from: `tdesign-${library}${importFrom}`, + } + } + if (name.match(/^T[A-Z]/) || pluginList.includes(name)) { const importName = name.match(/^T[A-Z]/) ? name.slice(1) : name diff --git a/src/types.ts b/src/types.ts index f16133a7..a7010bb4 100644 --- a/src/types.ts +++ b/src/types.ts @@ -98,7 +98,7 @@ export interface Options { /** * Negated glob patterns to exclude files from being detected as components. * - * @default [] + * @default ['/**\/node_modules/**'] */ globsExclude?: string | string[] @@ -209,6 +209,7 @@ export type ResolvedOptions = Omit< dirs: string[] resolvedDirs: string[] globs: string[] + globsExclude: string[] dts: string | false root: string } diff --git a/test/__snapshots__/dts.test.ts.snap b/test/__snapshots__/dts.test.ts.snap index 7dabf7c9..75752379 100644 --- a/test/__snapshots__/dts.test.ts.snap +++ b/test/__snapshots__/dts.test.ts.snap @@ -5,6 +5,7 @@ exports[`dts > components only 1`] = ` // @ts-nocheck // Generated by unplugin-vue-components // Read more: https://github.com/vuejs/core/pull/3399 +// biome-ignore lint: disable export {} /* prettier-ignore */ @@ -23,6 +24,7 @@ exports[`dts > directive only 1`] = ` // @ts-nocheck // Generated by unplugin-vue-components // Read more: https://github.com/vuejs/core/pull/3399 +// biome-ignore lint: disable export {} /* prettier-ignore */ @@ -39,6 +41,7 @@ exports[`dts > getDeclaration 1`] = ` // @ts-nocheck // Generated by unplugin-vue-components // Read more: https://github.com/vuejs/core/pull/3399 +// biome-ignore lint: disable export {} /* prettier-ignore */ @@ -97,6 +100,7 @@ exports[`dts > vue 2.7 components only 1`] = ` // @ts-nocheck // Generated by unplugin-vue-components // Read more: https://github.com/vuejs/core/pull/3399 +// biome-ignore lint: disable export {} /* prettier-ignore */ @@ -115,6 +119,7 @@ exports[`dts > writeDeclaration - keep unused 1`] = ` // @ts-nocheck // Generated by unplugin-vue-components // Read more: https://github.com/vuejs/core/pull/3399 +// biome-ignore lint: disable export {} /* prettier-ignore */ @@ -139,6 +144,7 @@ exports[`dts > writeDeclaration 1`] = ` // @ts-nocheck // Generated by unplugin-vue-components // Read more: https://github.com/vuejs/core/pull/3399 +// biome-ignore lint: disable export {} /* prettier-ignore */ diff --git a/test/search.test.ts b/test/search.test.ts index e48bec4d..3277da05 100644 --- a/test/search.test.ts +++ b/test/search.test.ts @@ -1,5 +1,5 @@ import { relative, resolve } from 'pathe' -import { describe, expect, it } from 'vitest' +import { describe, expect, it, onTestFailed } from 'vitest' import { Context } from '../src/core/context' const root = resolve(__dirname, '../examples/vite-vue3') @@ -64,10 +64,18 @@ describe('search', () => { '!src/components/book', ], }) + + onTestFailed(() => { + console.error('resolved options') + console.error(ctx.options) + }) + ctx.setRoot(root) ctx.searchGlob() - expect(cleanup(ctx.componentNameMap).map(i => i.as)).not.toEqual(expect.arrayContaining(['Book'])) + expect(cleanup(ctx.componentNameMap).map(i => i.as)) + .not + .contain('Book') }) it('should excludeNames', () => { diff --git a/vitest.config.ts b/vitest.config.ts index 637aa94f..93c91c41 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -2,10 +2,12 @@ import { defineConfig } from 'vite' export default defineConfig({ test: { - deps: { - inline: [ - '@babel/types', - ], + server: { + deps: { + inline: [ + '@babel/types', + ], + }, }, }, }) 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