diff --git a/README.md b/README.md index da6c6288..0928c180 100644 --- a/README.md +++ b/README.md @@ -241,13 +241,13 @@ Supported Resolvers: - [Dev UI](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/devui.ts) ```ts -// vite.config.js -import Components from 'unplugin-vue-components/vite' import { AntDesignVueResolver, ElementPlusResolver, VantResolver, } from 'unplugin-vue-components/resolvers' +// vite.config.js +import Components from 'unplugin-vue-components/vite' // your plugin installation Components({ diff --git a/examples/vite-vue3/vite.config.ts b/examples/vite-vue3/vite.config.ts index 162caa74..926eae87 100644 --- a/examples/vite-vue3/vite.config.ts +++ b/examples/vite-vue3/vite.config.ts @@ -1,11 +1,11 @@ -import path from 'node:path' import type { UserConfig } from 'vite' +import path from 'node:path' import Vue from '@vitejs/plugin-vue' -import Components from 'unplugin-vue-components/vite' +import IconsResolver from 'unplugin-icons/resolver' +import Icons from 'unplugin-icons/vite' import { VantResolver } from 'unplugin-vue-components/resolvers' +import Components from 'unplugin-vue-components/vite' 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' const config: UserConfig = { diff --git a/examples/vue-cli/src/main.ts b/examples/vue-cli/src/main.ts index f3344c96..d23b63b9 100644 --- a/examples/vue-cli/src/main.ts +++ b/examples/vue-cli/src/main.ts @@ -1,5 +1,5 @@ -import Vue from 'vue' import VueCompostionAPI from '@vue/composition-api' +import Vue from 'vue' import App from './App.vue' import './index.css' diff --git a/examples/vue-cli/vue.config.js b/examples/vue-cli/vue.config.js index 6511f304..466b02db 100644 --- a/examples/vue-cli/vue.config.js +++ b/examples/vue-cli/vue.config.js @@ -1,6 +1,6 @@ -const ScriptSetup = require('unplugin-vue2-script-setup/webpack') -const Icons = require('unplugin-icons/webpack') const IconsResolver = require('unplugin-icons/resolver') +const Icons = require('unplugin-icons/webpack') +const ScriptSetup = require('unplugin-vue2-script-setup/webpack') const Components = require('unplugin-vue-components/webpack') /** diff --git a/src/core/context.ts b/src/core/context.ts index 480e164b..fcb627db 100644 --- a/src/core/context.ts +++ b/src/core/context.ts @@ -1,16 +1,16 @@ -import { relative } from 'node:path' import type fs from 'node:fs' -import process from 'node:process' -import Debug from 'debug' import type { UpdatePayload, ViteDevServer } from 'vite' -import { slash, throttle, toArray } from '@antfu/utils' import type { ComponentInfo, Options, ResolvedOptions, Transformer } from '../types' +import { relative } from 'node:path' +import process from 'node:process' +import { slash, throttle, toArray } from '@antfu/utils' +import Debug from 'debug' import { DIRECTIVE_IMPORT_PREFIX } from './constants' -import { getNameFromFilePath, isExclude, matchGlobs, normalizeComponentInfo, parseId, pascalCase, resolveAlias } from './utils' -import { resolveOptions } from './options' -import { searchComponents } from './fs/glob' import { writeDeclaration } from './declaration' +import { searchComponents } from './fs/glob' +import { resolveOptions } from './options' import transformer from './transformer' +import { getNameFromFilePath, isExclude, matchGlobs, normalizeComponentInfo, parseId, pascalCase, resolveAlias } from './utils' const debug = { components: Debug('unplugin-vue-components:context:components'), diff --git a/src/core/declaration.ts b/src/core/declaration.ts index 2d96dc78..2c4b633d 100644 --- a/src/core/declaration.ts +++ b/src/core/declaration.ts @@ -1,11 +1,11 @@ -import { dirname, isAbsolute, relative } from 'node:path' +import type { ComponentInfo, Options } from '../types' +import type { Context } from './context' import { existsSync } from 'node:fs' import { mkdir, readFile, writeFile as writeFile_ } from 'node:fs/promises' +import { dirname, isAbsolute, relative } from 'node:path' import { notNullish, slash } from '@antfu/utils' -import type { ComponentInfo, Options } from '../types' -import type { Context } from './context' -import { getTransformedPath } from './utils' import { resolveTypeImports } from './type-imports/detect' +import { getTransformedPath } from './utils' const multilineCommentsRE = /\/\*.*?\*\//gs const singlelineCommentsRE = /\/\/.*$/gm diff --git a/src/core/fs/glob.ts b/src/core/fs/glob.ts index bea9ee48..459a6643 100644 --- a/src/core/fs/glob.ts +++ b/src/core/fs/glob.ts @@ -1,6 +1,6 @@ -import fg from 'fast-glob' -import Debug from 'debug' import type { Context } from '../context' +import Debug from 'debug' +import fg from 'fast-glob' const debug = Debug('unplugin-vue-components:glob') diff --git a/src/core/options.ts b/src/core/options.ts index 4b44e914..2bdfd819 100644 --- a/src/core/options.ts +++ b/src/core/options.ts @@ -1,7 +1,7 @@ +import type { ComponentResolver, ComponentResolverObject, Options, ResolvedOptions } from '../types' import { join, resolve } from 'node:path' import { slash, toArray } from '@antfu/utils' import { getPackageInfoSync, isPackageExists } from 'local-pkg' -import type { ComponentResolver, ComponentResolverObject, Options, ResolvedOptions } from '../types' import { detectTypeImports } from './type-imports/detect' export const defaultOptions: Omit, 'include' | 'exclude' | 'excludeNames' | 'transformer' | 'globs' | 'directives' | 'types' | 'version'> = { diff --git a/src/core/resolvers/_READ_BEFORE_CONTRIBUTE.md b/src/core/resolvers/_READ_BEFORE_CONTRIBUTE.md index 4de44ff5..8733031a 100644 --- a/src/core/resolvers/_READ_BEFORE_CONTRIBUTE.md +++ b/src/core/resolvers/_READ_BEFORE_CONTRIBUTE.md @@ -9,10 +9,10 @@ Instead, we suggest UI libraries to maintain and publish their own resolvers, as We recommend to have it under a submodule, or publish as a separate package. ```ts -import Components from 'unplugin-vue-components' - import MyLibResolver from 'my-lib/auto-import-resolver' // <-- +import Components from 'unplugin-vue-components' + export default defineConfig({ plugins: [ Components({ diff --git a/src/core/resolvers/arco.ts b/src/core/resolvers/arco.ts index 8ade3fb7..ae4bcd0d 100644 --- a/src/core/resolvers/arco.ts +++ b/src/core/resolvers/arco.ts @@ -1,5 +1,5 @@ -import Debug from 'debug' import type { ComponentInfo, ComponentResolver } from '../../types' +import Debug from 'debug' import { isExclude, kebabCase, pascalCase } from '../utils' const debug = Debug('unplugin-vue-components:resolvers:arco') diff --git a/src/core/resolvers/devui.ts b/src/core/resolvers/devui.ts index ca04d461..059af297 100644 --- a/src/core/resolvers/devui.ts +++ b/src/core/resolvers/devui.ts @@ -1,5 +1,5 @@ -import { kebabCase } from '../utils' import type { ComponentInfo, ComponentResolver } from '../../types' +import { kebabCase } from '../utils' export interface DevResolverOptions { /** diff --git a/src/core/resolvers/element-plus.ts b/src/core/resolvers/element-plus.ts index f4d939c1..3b312d74 100644 --- a/src/core/resolvers/element-plus.ts +++ b/src/core/resolvers/element-plus.ts @@ -1,5 +1,5 @@ -import { compare } from 'compare-versions' import type { ComponentInfo, ComponentResolver, SideEffectsInfo } from '../../types' +import { compare } from 'compare-versions' import { getPkgVersion, kebabCase } from '../utils' export interface ElementPlusResolverOptions { diff --git a/src/core/resolvers/idux.ts b/src/core/resolvers/idux.ts index fd004392..55153706 100644 --- a/src/core/resolvers/idux.ts +++ b/src/core/resolvers/idux.ts @@ -1,6 +1,6 @@ -import { resolveModule } from 'local-pkg' -import { compare } from 'compare-versions' import type { ComponentResolver } from '../../types' +import { compare } from 'compare-versions' +import { resolveModule } from 'local-pkg' import { getPkgVersion, kebabCase } from '../utils' // @keep-sorted diff --git a/src/core/resolvers/index.ts b/src/core/resolvers/index.ts index ea5c4220..820e1b30 100644 --- a/src/core/resolvers/index.ts +++ b/src/core/resolvers/index.ts @@ -1,11 +1,18 @@ export * from './antdv' +export * from './arco' +export * from './bootstrap-vue' +export * from './devui' export * from './element-plus' export * from './element-ui' export * from './headless-ui' export * from './idux' export * from './inkline' +export * from './ionic' +export * from './layui-vue' export * from './naive-ui' export * from './prime-vue' +export * from './quasar' +export * from './tdesign' export * from './vant' export * from './varlet-ui' export * from './veui' @@ -13,10 +20,3 @@ export * from './view-ui' export * from './vuetify' export * from './vueuse' export * from './vueuse-directive' -export * from './quasar' -export * from './devui' -export * from './arco' -export * from './tdesign' -export * from './layui-vue' -export * from './bootstrap-vue' -export * from './ionic' diff --git a/src/core/resolvers/layui-vue.ts b/src/core/resolvers/layui-vue.ts index afbf358a..c61419c9 100644 --- a/src/core/resolvers/layui-vue.ts +++ b/src/core/resolvers/layui-vue.ts @@ -1,6 +1,6 @@ import type { FilterPattern } from '@rollup/pluginutils' -import { isExclude } from '../utils' import type { ComponentInfo, ComponentResolver, SideEffectsInfo } from '../../types' +import { isExclude } from '../utils' const matchComponents = [ { diff --git a/src/core/resolvers/quasar.ts b/src/core/resolvers/quasar.ts index 3163b21e..f1ddfbce 100644 --- a/src/core/resolvers/quasar.ts +++ b/src/core/resolvers/quasar.ts @@ -1,6 +1,6 @@ +import type { ComponentResolver } from '../../types' import { promises as fs } from 'node:fs' import { resolveModule } from 'local-pkg' -import type { ComponentResolver } from '../../types' /** * Resolver for Quasar diff --git a/src/core/resolvers/varlet-ui.ts b/src/core/resolvers/varlet-ui.ts index 9a4bb2d2..c74d42fc 100644 --- a/src/core/resolvers/varlet-ui.ts +++ b/src/core/resolvers/varlet-ui.ts @@ -1,4 +1,4 @@ -import type { ComponentResolveResult, ComponentResolver } from '../../types' +import type { ComponentResolver, ComponentResolveResult } from '../../types' import { kebabCase } from '../utils' export interface VarletUIResolverOptions { diff --git a/src/core/resolvers/veui.ts b/src/core/resolvers/veui.ts index 5cdeaddb..732ce5cc 100644 --- a/src/core/resolvers/veui.ts +++ b/src/core/resolvers/veui.ts @@ -1,6 +1,6 @@ +import type { ComponentResolver, SideEffectsInfo } from '../../types' import { join, normalize } from 'node:path' import { resolvePathSync } from 'mlly' -import type { ComponentResolver, SideEffectsInfo } from '../../types' import { camelCase, kebabCase, pascalCase } from '../utils' interface VeuiPeerConfig { diff --git a/src/core/resolvers/vueuse-directive.ts b/src/core/resolvers/vueuse-directive.ts index 08fef1f0..2e97d364 100644 --- a/src/core/resolvers/vueuse-directive.ts +++ b/src/core/resolvers/vueuse-directive.ts @@ -1,7 +1,7 @@ +import type { ComponentResolver } from '../../types' import { readFileSync } from 'node:fs' import process from 'node:process' import { resolveModule } from 'local-pkg' -import type { ComponentResolver } from '../../types' let directives: string[] | undefined diff --git a/src/core/resolvers/vueuse.ts b/src/core/resolvers/vueuse.ts index 84a8f77b..e9a5ca78 100644 --- a/src/core/resolvers/vueuse.ts +++ b/src/core/resolvers/vueuse.ts @@ -1,7 +1,7 @@ +import type { ComponentResolver } from '../../types' import { readFileSync } from 'node:fs' import process from 'node:process' import { resolveModule } from 'local-pkg' -import type { ComponentResolver } from '../../types' let components: string[] | undefined diff --git a/src/core/transformer.ts b/src/core/transformer.ts index f8c5a672..6640d1b6 100644 --- a/src/core/transformer.ts +++ b/src/core/transformer.ts @@ -1,10 +1,10 @@ -import Debug from 'debug' -import MagicString from 'magic-string' import type { TransformResult } from 'unplugin' import type { SupportedTransformer } from '..' import type { Transformer } from '../types' -import { DISABLE_COMMENT } from './constants' import type { Context } from './context' +import Debug from 'debug' +import MagicString from 'magic-string' +import { DISABLE_COMMENT } from './constants' import transformComponent from './transforms/component' import transformDirectives from './transforms/directive' diff --git a/src/core/transforms/component.ts b/src/core/transforms/component.ts index f27b2cba..7d2bc2ce 100644 --- a/src/core/transforms/component.ts +++ b/src/core/transforms/component.ts @@ -1,9 +1,9 @@ -import Debug from 'debug' import type MagicString from 'magic-string' -import { pascalCase, stringifyComponentImport } from '../utils' +import type { SupportedTransformer } from '../..' import type { Context } from '../context' import type { ResolveResult } from '../transformer' -import type { SupportedTransformer } from '../..' +import Debug from 'debug' +import { pascalCase, stringifyComponentImport } from '../utils' const debug = Debug('unplugin-vue-components:transform:component') diff --git a/src/core/transforms/directive/index.ts b/src/core/transforms/directive/index.ts index 30c07d29..bcf9ad9d 100644 --- a/src/core/transforms/directive/index.ts +++ b/src/core/transforms/directive/index.ts @@ -1,9 +1,9 @@ -import Debug from 'debug' import type MagicString from 'magic-string' -import { pascalCase, stringifyComponentImport } from '../../utils' -import type { Context } from '../../context' import type { SupportedTransformer } from '../../..' +import type { Context } from '../../context' +import Debug from 'debug' import { DIRECTIVE_IMPORT_PREFIX } from '../../constants' +import { pascalCase, stringifyComponentImport } from '../../utils' import vue2Resolver from './vue2' import vue3Resolver from './vue3' diff --git a/src/core/transforms/directive/vue2.ts b/src/core/transforms/directive/vue2.ts index 85987772..8eb962fe 100644 --- a/src/core/transforms/directive/vue2.ts +++ b/src/core/transforms/directive/vue2.ts @@ -8,8 +8,8 @@ import type { VariableDeclaration, } from '@babel/types' import type MagicString from 'magic-string' -import { importModule, isPackageExists } from 'local-pkg' import type { ResolveResult } from '../../transformer' +import { importModule, isPackageExists } from 'local-pkg' /** * Get Vue 2 render function position diff --git a/src/core/type-imports/detect.ts b/src/core/type-imports/detect.ts index 5b318fce..f0015734 100644 --- a/src/core/type-imports/detect.ts +++ b/src/core/type-imports/detect.ts @@ -1,6 +1,6 @@ -import { isPackageExists } from 'local-pkg' -import { notNullish } from '@antfu/utils' import type { ComponentInfo, TypeImport } from '../../types' +import { notNullish } from '@antfu/utils' +import { isPackageExists } from 'local-pkg' import { TypeImportPresets } from '.' export function detectTypeImports(): TypeImport[] { diff --git a/src/core/unplugin.ts b/src/core/unplugin.ts index b2b43344..14c1b9b7 100644 --- a/src/core/unplugin.ts +++ b/src/core/unplugin.ts @@ -1,11 +1,11 @@ +import type { ResolvedConfig, ViteDevServer } from 'vite' +import type { Watching } from 'webpack' +import type { Options, PublicPluginAPI } from '../types' import { existsSync } from 'node:fs' import process from 'node:process' -import { createUnplugin } from 'unplugin' import { createFilter } from '@rollup/pluginutils' import chokidar from 'chokidar' -import type { ResolvedConfig, ViteDevServer } from 'vite' -import type { Watching } from 'webpack' -import type { Options, PublicPluginAPI } from '../types' +import { createUnplugin } from 'unplugin' import { Context } from './context' import { shouldTransform, stringifyComponentImport } from './utils' diff --git a/src/core/utils.ts b/src/core/utils.ts index ab57c665..eb5c8f3f 100644 --- a/src/core/utils.ts +++ b/src/core/utils.ts @@ -1,14 +1,14 @@ +import type { FilterPattern } from '@rollup/pluginutils' +import type { ComponentInfo, ImportInfo, ImportInfoLegacy, Options, ResolvedOptions } from '../types' +import type { Context } from './context' import { parse } from 'node:path' import process from 'node:process' -import { minimatch } from 'minimatch' import { slash, toArray } from '@antfu/utils' import { getPackageInfo, isPackageExists, } from 'local-pkg' -import type { FilterPattern } from '@rollup/pluginutils' -import type { ComponentInfo, ImportInfo, ImportInfoLegacy, Options, ResolvedOptions } from '../types' -import type { Context } from './context' +import { minimatch } from 'minimatch' import { DISABLE_COMMENT } from './constants' export const isSSR = Boolean(process.env.SSR || process.env.SSG || process.env.VITE_SSR || process.env.VITE_SSG) diff --git a/src/index.ts b/src/index.ts index 0eea7e27..4cb35701 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,3 @@ -export * from './types' export { default } from './core/unplugin' -export { camelCase, pascalCase, kebabCase } from './core/utils' +export { camelCase, kebabCase, pascalCase } from './core/utils' +export * from './types' diff --git a/src/nuxt.ts b/src/nuxt.ts index 8561c8ae..2513ee5d 100644 --- a/src/nuxt.ts +++ b/src/nuxt.ts @@ -1,9 +1,9 @@ -import { addVitePlugin, addWebpackPlugin, defineNuxtModule } from '@nuxt/kit' - // Workaround for: // src/nuxt.ts(5,1): error TS2742: The inferred type of 'default' cannot be named without a reference to '.pnpm/@nuxt+schema@3.0.0_rollup@2.79.0/node_modules/@nuxt/schema'. This is likely not portable. A type annotation is necessary. import type { } from '@nuxt/schema' + import type { Options } from './types' +import { addVitePlugin, addWebpackPlugin, defineNuxtModule } from '@nuxt/kit' import unplugin from '.' export default defineNuxtModule({ diff --git a/src/types.ts b/src/types.ts index 967d9486..69dceae1 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,6 +1,6 @@ +import type { Awaitable } from '@antfu/utils' import type { FilterPattern } from '@rollup/pluginutils' import type { TransformResult } from 'unplugin' -import type { Awaitable } from '@antfu/utils' export interface ImportInfoLegacy { /** diff --git a/test/dts.test.ts b/test/dts.test.ts index fa36a288..b26ccba4 100644 --- a/test/dts.test.ts +++ b/test/dts.test.ts @@ -1,7 +1,7 @@ +import type { ComponentResolver } from '../src' import { readFile, writeFile } from 'node:fs/promises' import path from 'node:path' import { describe, expect, it } from 'vitest' -import type { ComponentResolver } from '../src' import { Context } from '../src/core/context' import { getDeclaration, parseDeclaration } from '../src/core/declaration' diff --git a/test/resolvers/arco.test.ts b/test/resolvers/arco.test.ts index 09ff6b7a..daa9ab77 100644 --- a/test/resolvers/arco.test.ts +++ b/test/resolvers/arco.test.ts @@ -1,7 +1,7 @@ +import type { ComponentResolveResult, ComponentResolverObject } from '../../src' import { describe, expect, it } from 'vitest' -import { ArcoResolver } from '../../src/resolvers' -import type { ComponentResolveResult, ComponentResolverObject } from '../../src' +import { ArcoResolver } from '../../src/resolvers' function testNoIconComponentResolve(resolver: ComponentResolverObject) { expect(resolver.resolve('AButton')).toEqual({ diff --git a/test/resolvers/element-plus.test.ts b/test/resolvers/element-plus.test.ts index 3dc0e7a9..753bb5c8 100644 --- a/test/resolvers/element-plus.test.ts +++ b/test/resolvers/element-plus.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from 'vitest' -import { ElementPlusResolver } from '../../src/resolvers' import { Context } from '../../src/core/context' +import { ElementPlusResolver } from '../../src/resolvers' describe('element Plus Resolver', () => { it('components and directives should be transformed', async () => { diff --git a/test/resolvers/tdesign.test.ts b/test/resolvers/tdesign.test.ts index 9db58e2d..3b220fb9 100644 --- a/test/resolvers/tdesign.test.ts +++ b/test/resolvers/tdesign.test.ts @@ -1,7 +1,7 @@ +import type { ComponentResolverObject } from '../../src' import { describe, expect, it } from 'vitest' -import { TDesignResolver } from '../../src/resolvers' -import type { ComponentResolverObject } from '../../src' +import { TDesignResolver } from '../../src/resolvers' describe('tDesignResolver', () => { it('name matching string rule should not be resolved', async () => { diff --git a/test/transform.test.ts b/test/transform.test.ts index ddf12595..5909896f 100644 --- a/test/transform.test.ts +++ b/test/transform.test.ts @@ -1,5 +1,5 @@ -import { describe, expect, it } from 'vitest' import type { ComponentResolver } from '../src' +import { describe, expect, it } from 'vitest' import { Context } from '../src/core/context' const resolver: ComponentResolver[] = [ diff --git a/test/utils.test.ts b/test/utils.test.ts index 767b9e6d..cdabab87 100644 --- a/test/utils.test.ts +++ b/test/utils.test.ts @@ -1,5 +1,5 @@ -import { describe, expect, it } from 'vitest' import type { ResolvedOptions } from '../src' +import { describe, expect, it } from 'vitest' import { getNameFromFilePath } from '../src/core/utils' describe('getNameFromFilePath', () => {