From aebb8bbf46c552f6535a178cd57fa6585fdfd98b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=A2=E6=B5=B7=E5=AE=87?= Date: Thu, 27 Jun 2024 17:25:52 +0800 Subject: [PATCH] fix: fix `matchGlobs` function to correctly handle negation patterns, fix vite-vue3/vite.config.ts import paths --- examples/vite-vue3/vite.config.ts | 4 ++-- src/core/utils.ts | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/examples/vite-vue3/vite.config.ts b/examples/vite-vue3/vite.config.ts index 9e676841..162caa74 100644 --- a/examples/vite-vue3/vite.config.ts +++ b/examples/vite-vue3/vite.config.ts @@ -3,7 +3,7 @@ import type { UserConfig } from 'vite' import Vue from '@vitejs/plugin-vue' import Components from 'unplugin-vue-components/vite' import { VantResolver } from 'unplugin-vue-components/resolvers' -import Markdown from 'vite-plugin-vue-markdown' +import Markdown from 'unplugin-vue-markdown/vite' import Icons from 'unplugin-icons/vite' import IconsResolver from 'unplugin-icons/resolver' import Inspect from 'vite-plugin-inspect' @@ -18,7 +18,7 @@ const config: UserConfig = { Vue({ include: [/\.vue$/, /\.md$/], }), - Markdown(), + Markdown({}), Icons(), Inspect(), Components({ diff --git a/src/core/utils.ts b/src/core/utils.ts index 307b7514..df1084a2 100644 --- a/src/core/utils.ts +++ b/src/core/utils.ts @@ -58,8 +58,10 @@ export function isEmpty(value: any) { export function matchGlobs(filepath: string, globs: string[]) { for (const glob of globs) { - if (minimatch(slash(filepath), glob)) - return true + const isNegated = glob.startsWith('!') + const match = minimatch(slash(filepath), isNegated ? glob.slice(1) : glob) + if (match) + return !isNegated } return false } @@ -143,7 +145,7 @@ export function getNameFromFilePath(filePath: string, options: ResolvedOptions): if (globalNamespaces.some((name: string) => folders.includes(name))) folders = folders.filter(f => !globalNamespaces.includes(f)) - folders = folders.map(f => f.replace(/[^a-zA-Z0-9\-]/g, '')) + folders = folders.map(f => f.replace(/[^a-z0-9\-]/gi, '')) if (filename.toLowerCase() === 'index') filename = ''