diff --git a/README.md b/README.md index c88388fa..abf23b5f 100644 --- a/README.md +++ b/README.md @@ -414,7 +414,10 @@ Components({ version: 2.7, // Only provide types of components in library (registered globally) - types: [] + // see https://github.com/unplugin/unplugin-vue-components/blob/main/src/core/type-imports/index.ts + types: [ + /* ... */ + ], }) ``` diff --git a/examples/vite-vue2/package.json b/examples/vite-vue2/package.json index 7eacda86..9c2d9e66 100644 --- a/examples/vite-vue2/package.json +++ b/examples/vite-vue2/package.json @@ -7,7 +7,7 @@ "dev": "cross-env DEBUG=unplugin-vue-components:* vite" }, "dependencies": { - "vue": "^3.5.17" + "vue": "2.7.16" }, "devDependencies": { "@vitejs/plugin-vue2": "^2.3.3", diff --git a/examples/vue-cli/package.json b/examples/vue-cli/package.json index 55177d55..52ae37d2 100644 --- a/examples/vue-cli/package.json +++ b/examples/vue-cli/package.json @@ -9,7 +9,7 @@ "dependencies": { "@vue/composition-api": "^1.7.2", "core-js": "^3.43.0", - "vue": "^3.5.17" + "vue": "2.7.16" }, "devDependencies": { "@vue/cli-plugin-babel": "^5.0.8", diff --git a/examples/vue-cli/vue.config.js b/examples/vue-cli/vue.config.js index 466b02db..46fec0c6 100644 --- a/examples/vue-cli/vue.config.js +++ b/examples/vue-cli/vue.config.js @@ -1,6 +1,6 @@ -const IconsResolver = require('unplugin-icons/resolver') -const Icons = require('unplugin-icons/webpack') -const ScriptSetup = require('unplugin-vue2-script-setup/webpack') +const IconsResolver = require('unplugin-icons/resolver').default +const Icons = require('unplugin-icons/webpack').default +const ScriptSetup = require('unplugin-vue2-script-setup/webpack').default const Components = require('unplugin-vue-components/webpack') /** diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index de11794b..36d63fb8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -112,12 +112,12 @@ importers: examples/vite-vue2: dependencies: vue: - specifier: ^3.5.17 - version: 3.5.17(typescript@5.8.3) + specifier: 2.7.16 + version: 2.7.16 devDependencies: '@vitejs/plugin-vue2': specifier: ^2.3.3 - version: 2.3.3(vite@7.0.0(@types/node@24.0.7)(jiti@2.4.2)(tsx@4.19.3)(yaml@2.8.0))(vue@3.5.17(typescript@5.8.3)) + version: 2.3.3(vite@7.0.0(@types/node@24.0.7)(jiti@2.4.2)(tsx@4.19.3)(yaml@2.8.0))(vue@2.7.16) cross-env: specifier: ^7.0.3 version: 7.0.3 @@ -175,20 +175,20 @@ importers: dependencies: '@vue/composition-api': specifier: ^1.7.2 - version: 1.7.2(vue@3.5.17(typescript@5.8.3)) + version: 1.7.2(vue@2.7.16) core-js: specifier: ^3.43.0 version: 3.43.0 vue: - specifier: ^3.5.17 - version: 3.5.17(typescript@5.8.3) + specifier: 2.7.16 + version: 2.7.16 devDependencies: '@vue/cli-plugin-babel': specifier: ^5.0.8 - version: 5.0.8(@vue/cli-service@5.0.8(@vue/compiler-sfc@3.5.17)(lodash@4.17.21)(webpack-sources@3.2.3))(core-js@3.43.0)(vue@3.5.17(typescript@5.8.3)) + version: 5.0.8(@vue/cli-service@5.0.8(@vue/compiler-sfc@3.5.17)(lodash@4.17.21)(webpack-sources@3.2.3))(core-js@3.43.0)(vue@2.7.16) '@vue/cli-plugin-typescript': specifier: ^5.0.8 - version: 5.0.8(@vue/cli-service@5.0.8(@vue/compiler-sfc@3.5.17)(lodash@4.17.21)(webpack-sources@3.2.3))(eslint@9.30.0(jiti@2.4.2))(typescript@5.8.3)(vue@3.5.17(typescript@5.8.3)) + version: 5.0.8(@vue/cli-service@5.0.8(@vue/compiler-sfc@3.5.17)(lodash@4.17.21)(webpack-sources@3.2.3))(eslint@9.30.0(jiti@2.4.2))(typescript@5.8.3)(vue@2.7.16) '@vue/cli-service': specifier: ^5.0.8 version: 5.0.8(@vue/compiler-sfc@3.5.17)(lodash@4.17.21)(webpack-sources@3.2.3) @@ -203,7 +203,7 @@ importers: version: link:../.. unplugin-vue2-script-setup: specifier: ^0.11.4 - version: 0.11.4(@vue/composition-api@1.7.2(vue@3.5.17(typescript@5.8.3)))(@vue/runtime-dom@3.5.17)(rollup@4.44.1) + version: 0.11.4(@vue/composition-api@1.7.2(vue@2.7.16))(@vue/runtime-dom@3.5.17)(rollup@4.44.1) examples/vue-cli-vue3: dependencies: @@ -1838,6 +1838,9 @@ packages: '@vue/compiler-dom@3.5.17': resolution: {integrity: sha512-+2UgfLKoaNLhgfhV5Ihnk6wB4ljyW1/7wUIog2puUqajiC29Lp5R/IKDdkebh9jTbTogTbsgB+OY9cEWzG95JQ==} + '@vue/compiler-sfc@2.7.16': + resolution: {integrity: sha512-KWhJ9k5nXuNtygPU7+t1rX6baZeqOYLEforUPjgNDBnLicfHCoi48H87Q8XyLZOrNNsmhuwKqtpDQWjEFe6Ekg==} + '@vue/compiler-sfc@3.2.45': resolution: {integrity: sha512-1jXDuWah1ggsnSAOGsec8cFjT/K6TMZ0sPL3o3d84Ft2AYZi2jWJgRMjw4iaK0rBfA89L5gw427H4n1RZQBu6Q==} @@ -5678,6 +5681,10 @@ packages: peerDependencies: typescript: '>=5.0.0' + vue@2.7.16: + resolution: {integrity: sha512-4gCtFXaAA3zYZdTp5s4Hl2sozuySsgz4jy1EnpBHNfpMa9dK1ZCG7viqBPCwXtmgc8nHqUsAu3G4gtmXkkY3Sw==} + deprecated: Vue 2 has reached EOL and is no longer actively maintained. See https://v2.vuejs.org/eol/ for more details. + vue@3.2.45: resolution: {integrity: sha512-9Nx/Mg2b2xWlXykmCwiTUCWHbWIj53bnkizBxKai1g61f2Xit700A1ljowpTIM11e3uipOeiPcSqnmBg6gyiaA==} @@ -7401,10 +7408,10 @@ snapshots: dependencies: vue: 3.5.17(typescript@5.8.3) - '@vitejs/plugin-vue2@2.3.3(vite@7.0.0(@types/node@24.0.7)(jiti@2.4.2)(tsx@4.19.3)(yaml@2.8.0))(vue@3.5.17(typescript@5.8.3))': + '@vitejs/plugin-vue2@2.3.3(vite@7.0.0(@types/node@24.0.7)(jiti@2.4.2)(tsx@4.19.3)(yaml@2.8.0))(vue@2.7.16)': dependencies: vite: 7.0.0(@types/node@24.0.7)(jiti@2.4.2)(tsx@4.19.3)(yaml@2.8.0) - vue: 3.5.17(typescript@5.8.3) + vue: 2.7.16 '@vitejs/plugin-vue@6.0.0(vite@7.0.0(@types/node@24.0.7)(jiti@2.4.2)(tsx@4.19.3)(yaml@2.8.0))(vue@3.5.17(typescript@5.8.3))': dependencies: @@ -7507,6 +7514,29 @@ snapshots: transitivePeerDependencies: - supports-color + '@vue/babel-preset-app@5.0.8(@babel/core@7.27.7)(core-js@3.43.0)(vue@2.7.16)': + dependencies: + '@babel/core': 7.27.7 + '@babel/helper-compilation-targets': 7.27.2 + '@babel/helper-module-imports': 7.27.1 + '@babel/plugin-proposal-class-properties': 7.16.7(@babel/core@7.27.7) + '@babel/plugin-proposal-decorators': 7.17.9(@babel/core@7.27.7) + '@babel/plugin-syntax-dynamic-import': 7.8.3(@babel/core@7.27.7) + '@babel/plugin-syntax-jsx': 7.16.7(@babel/core@7.27.7) + '@babel/plugin-transform-runtime': 7.17.0(@babel/core@7.27.7) + '@babel/preset-env': 7.16.11(@babel/core@7.27.7) + '@babel/runtime': 7.17.2 + '@vue/babel-plugin-jsx': 1.1.1(@babel/core@7.27.7) + '@vue/babel-preset-jsx': 1.2.4(@babel/core@7.27.7) + babel-plugin-dynamic-import-node: 2.3.3 + core-js-compat: 3.41.0 + semver: 7.7.2 + optionalDependencies: + core-js: 3.43.0 + vue: 2.7.16 + transitivePeerDependencies: + - supports-color + '@vue/babel-preset-app@5.0.8(@babel/core@7.27.7)(core-js@3.43.0)(vue@3.5.17(typescript@5.8.3))': dependencies: '@babel/core': 7.27.7 @@ -7587,6 +7617,25 @@ snapshots: '@vue/cli-overlay@5.0.8': {} + '@vue/cli-plugin-babel@5.0.8(@vue/cli-service@5.0.8(@vue/compiler-sfc@3.5.17)(lodash@4.17.21)(webpack-sources@3.2.3))(core-js@3.43.0)(vue@2.7.16)': + dependencies: + '@babel/core': 7.27.7 + '@vue/babel-preset-app': 5.0.8(@babel/core@7.27.7)(core-js@3.43.0)(vue@2.7.16) + '@vue/cli-service': 5.0.8(@vue/compiler-sfc@3.5.17)(lodash@4.17.21)(webpack-sources@3.2.3) + '@vue/cli-shared-utils': 5.0.8 + babel-loader: 8.2.3(@babel/core@7.27.7)(webpack@5.70.0) + thread-loader: 3.0.4(webpack@5.70.0) + webpack: 5.70.0 + transitivePeerDependencies: + - '@swc/core' + - core-js + - encoding + - esbuild + - supports-color + - uglify-js + - vue + - webpack-cli + '@vue/cli-plugin-babel@5.0.8(@vue/cli-service@5.0.8(@vue/compiler-sfc@3.5.17)(lodash@4.17.21)(webpack-sources@3.2.3))(core-js@3.43.0)(vue@3.5.17(typescript@5.8.3))': dependencies: '@babel/core': 7.27.7 @@ -7613,7 +7662,7 @@ snapshots: transitivePeerDependencies: - encoding - '@vue/cli-plugin-typescript@5.0.8(@vue/cli-service@5.0.8(@vue/compiler-sfc@3.5.17)(lodash@4.17.21)(webpack-sources@3.2.3))(eslint@9.30.0(jiti@2.4.2))(typescript@5.8.3)(vue@3.5.17(typescript@5.8.3))': + '@vue/cli-plugin-typescript@5.0.8(@vue/cli-service@5.0.8(@vue/compiler-sfc@3.5.17)(lodash@4.17.21)(webpack-sources@3.2.3))(eslint@9.30.0(jiti@2.4.2))(typescript@5.8.3)(vue@2.7.16)': dependencies: '@babel/core': 7.27.7 '@types/webpack-env': 1.16.3 @@ -7625,7 +7674,7 @@ snapshots: thread-loader: 3.0.4(webpack@5.70.0) ts-loader: 9.2.8(typescript@5.8.3)(webpack@5.70.0) typescript: 5.8.3 - vue: 3.5.17(typescript@5.8.3) + vue: 2.7.16 webpack: 5.70.0 transitivePeerDependencies: - '@swc/core' @@ -7816,6 +7865,14 @@ snapshots: '@vue/compiler-core': 3.5.17 '@vue/shared': 3.5.17 + '@vue/compiler-sfc@2.7.16': + dependencies: + '@babel/parser': 7.27.7 + postcss: 8.5.6 + source-map: 0.6.1 + optionalDependencies: + prettier: 2.8.8 + '@vue/compiler-sfc@3.2.45': dependencies: '@babel/parser': 7.27.7 @@ -7923,15 +7980,15 @@ snapshots: - walrus - whiskers + '@vue/composition-api@1.7.2(vue@2.7.16)': + dependencies: + vue: 2.7.16 + '@vue/composition-api@1.7.2(vue@3.2.45)': dependencies: vue: 3.2.45 optional: true - '@vue/composition-api@1.7.2(vue@3.5.17(typescript@5.8.3))': - dependencies: - vue: 3.5.17(typescript@5.8.3) - '@vue/devtools-api@6.6.4': {} '@vue/language-core@2.2.10(typescript@5.8.3)': @@ -11731,7 +11788,7 @@ snapshots: unplugin-utils: 0.2.4 vite: 7.0.0(@types/node@24.0.7)(jiti@2.4.2)(tsx@4.19.3)(yaml@2.8.0) - unplugin-vue2-script-setup@0.11.4(@vue/composition-api@1.7.2(vue@3.5.17(typescript@5.8.3)))(@vue/runtime-dom@3.5.17)(rollup@4.44.1): + unplugin-vue2-script-setup@0.11.4(@vue/composition-api@1.7.2(vue@2.7.16))(@vue/runtime-dom@3.5.17)(rollup@4.44.1): dependencies: '@antfu/utils': 0.7.10 '@babel/core': 7.27.7 @@ -11742,7 +11799,7 @@ snapshots: '@rollup/pluginutils': 5.1.4(rollup@4.44.1) '@vue/compiler-core': 3.5.17 '@vue/compiler-dom': 3.5.17 - '@vue/composition-api': 1.7.2(vue@3.5.17(typescript@5.8.3)) + '@vue/composition-api': 1.7.2(vue@2.7.16) '@vue/reactivity-transform': 3.3.4 '@vue/runtime-dom': 3.5.17 '@vue/shared': 3.5.17 @@ -12023,6 +12080,11 @@ snapshots: '@vue/language-core': 2.2.10(typescript@5.8.3) typescript: 5.8.3 + vue@2.7.16: + dependencies: + '@vue/compiler-sfc': 2.7.16 + csstype: 3.1.3 + vue@3.2.45: dependencies: '@vue/compiler-dom': 3.2.45 diff --git a/src/core/options.ts b/src/core/options.ts index 4ac7cd9c..699062bc 100644 --- a/src/core/options.ts +++ b/src/core/options.ts @@ -3,6 +3,7 @@ import { join, resolve } from 'node:path' import { slash, toArray } from '@antfu/utils' import { getPackageInfoSync, isPackageExists } from 'local-pkg' import { detectTypeImports } from './type-imports/detect' +import { escapeSpecialChars } from './utils' export const defaultOptions: Omit, 'include' | 'exclude' | 'excludeNames' | 'transformer' | 'globs' | 'globsExclude' | 'directives' | 'types' | 'version'> = { dirs: 'src/components', @@ -63,8 +64,8 @@ export function resolveOptions(options: Options, root: string): ResolvedOptions i = i.slice(1) } return resolved.deep - ? prefix + slash(join(i, `**/*.${extsGlob}`)) - : prefix + slash(join(i, `*.${extsGlob}`)) + ? prefix + escapeSpecialChars(slash(join(i, `**/*.${extsGlob}`))) + : prefix + escapeSpecialChars(slash(join(i, `*.${extsGlob}`))) }) if (!resolved.extensions.length) diff --git a/src/core/utils.ts b/src/core/utils.ts index 53e1c132..ab86231d 100644 --- a/src/core/utils.ts +++ b/src/core/utils.ts @@ -242,3 +242,9 @@ export function isExclude(name: string, exclude?: FilterPattern): boolean { } return false } + +const ESCAPE_PARENTHESES_REGEX = /[()]/g + +export function escapeSpecialChars(str: string): string { + return str.replace(ESCAPE_PARENTHESES_REGEX, '\\$&') +} diff --git a/test/utils.test.ts b/test/utils.test.ts index cdabab87..a9f38bf2 100644 --- a/test/utils.test.ts +++ b/test/utils.test.ts @@ -1,6 +1,6 @@ import type { ResolvedOptions } from '../src' import { describe, expect, it } from 'vitest' -import { getNameFromFilePath } from '../src/core/utils' +import { escapeSpecialChars, getNameFromFilePath } from '../src/core/utils' describe('getNameFromFilePath', () => { const options: Partial = { @@ -20,3 +20,9 @@ describe('getNameFromFilePath', () => { expect(getNameFromFilePath(inComponentFilePath, options as ResolvedOptions)).toBe('a1-b2-c3-d4-ef-ghi') }) }) + +describe('escapeSpecialChars', () => { + it('should escape parentheses', () => { + expect(escapeSpecialChars('component()')).toBe('component\\(\\)') + }) +}) 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