@@ -8,7 +8,11 @@ interface PackageJson {
88 devDependencies ?: Record < string , string > ;
99}
1010
11- function resolveProjectDep ( opts : { pkg : PackageJson ; cwd : string ; dep : string } ) {
11+ function resolveProjectDep ( opts : {
12+ pkg : PackageJson ;
13+ cwd : string ;
14+ dep : string ;
15+ } ) {
1216 if (
1317 opts . pkg . dependencies ?. [ opts . dep ] ||
1418 opts . pkg . devDependencies ?. [ opts . dep ]
@@ -25,56 +29,57 @@ function compareVersion(version: string, targetVersion: string): number {
2529 const parseVersion = ( v : string ) => {
2630 // 解析版本号,处理 beta/alpha/rc 等预发布版本
2731 const match = v . match ( / ^ ( \d + ) \. ( \d + ) \. ( \d + ) (?: - ( .+ ?) \. ( \d + ) ) ? / ) ;
28- if ( ! match ) return { major : 0 , minor : 0 , patch : 0 , prerelease : '' , prereleaseNum : 0 } ;
29-
32+ if ( ! match )
33+ return { major : 0 , minor : 0 , patch : 0 , prerelease : '' , prereleaseNum : 0 } ;
34+
3035 return {
3136 major : parseInt ( match [ 1 ] , 10 ) ,
3237 minor : parseInt ( match [ 2 ] , 10 ) ,
3338 patch : parseInt ( match [ 3 ] , 10 ) ,
3439 prerelease : match [ 4 ] || '' ,
35- prereleaseNum : parseInt ( match [ 5 ] || '0' , 10 )
40+ prereleaseNum : parseInt ( match [ 5 ] || '0' , 10 ) ,
3641 } ;
3742 } ;
38-
43+
3944 const v1 = parseVersion ( version ) ;
4045 const v2 = parseVersion ( targetVersion ) ;
41-
46+
4247 // 比较主版本号
4348 if ( v1 . major !== v2 . major ) return v1 . major - v2 . major ;
4449 // 比较次版本号
4550 if ( v1 . minor !== v2 . minor ) return v1 . minor - v2 . minor ;
4651 // 比较修订版本号
4752 if ( v1 . patch !== v2 . patch ) return v1 . patch - v2 . patch ;
48-
53+
4954 // 如果都没有预发布版本,则相等
5055 if ( ! v1 . prerelease && ! v2 . prerelease ) return 0 ;
51-
56+
5257 // 正式版本大于预发布版本
5358 if ( ! v1 . prerelease && v2 . prerelease ) return 1 ;
5459 if ( v1 . prerelease && ! v2 . prerelease ) return - 1 ;
55-
60+
5661 // 比较预发布版本
5762 if ( v1 . prerelease !== v2 . prerelease ) {
5863 return v1 . prerelease . localeCompare ( v2 . prerelease ) ;
5964 }
60-
65+
6166 // 比较预发布版本号
6267 return v1 . prereleaseNum - v2 . prereleaseNum ;
6368}
6469
6570function checkVersionCompatibility ( version : string ) {
6671 const minRequiredVersion = '2.2.0-beta.6' ;
67-
72+
6873 // 检查是否满足最低版本要求
6974 if ( compareVersion ( version , minRequiredVersion ) < 0 ) {
7075 console . warn (
7176 `[winjs-plugin-antdv] 警告:当前 ant-design-vue 版本 (${ version } ) 不支持 AntDesignVueResolver。\n` +
72- `AntDesignVueResolver 需要 ant-design-vue@${ minRequiredVersion } 或更高版本。\n` +
73- `请升级您的 ant-design-vue 版本:npm install ant-design-vue@latest`
77+ `AntDesignVueResolver 需要 ant-design-vue@${ minRequiredVersion } 或更高版本。\n` +
78+ `请升级您的 ant-design-vue 版本:npm install ant-design-vue@latest` ,
7479 ) ;
7580 return false ;
7681 }
77-
82+
7883 return true ;
7984}
8085
@@ -85,15 +90,14 @@ export default (api: IApi) => {
8590 resolveProjectDep ( {
8691 pkg : api . pkg ,
8792 cwd : api . cwd ,
88- dep : 'ant-design-vue'
93+ dep : 'ant-design-vue' ,
8994 } ) || dirname ( require . resolve ( 'ant-design-vue/package.json' ) ) ;
90- } catch ( _ ) {
91- }
95+ } catch ( _ ) { }
9296
9397 function checkPkgPath ( ) {
9498 if ( ! pkgPath ) {
9599 throw new Error (
96- `Can't find ant-design-vue package. Please install antd first.`
100+ `Can't find ant-design-vue package. Please install antd first.` ,
97101 ) ;
98102 }
99103 }
@@ -106,7 +110,7 @@ export default (api: IApi) => {
106110 checkVersionCompatibility ( antdvVersion ) ;
107111 memo . antdv = {
108112 pkgPath,
109- version : antdvVersion
113+ version : antdvVersion ,
110114 } ;
111115 return memo ;
112116 } ) ;
@@ -119,64 +123,93 @@ export default (api: IApi) => {
119123 . object ( {
120124 exclude : zod
121125 . array ( zod . string ( ) )
122- . describe ( '排除自动导入的组件列表。数组元素为组件名称(不含前缀),如 ["Button", "Input"]。被排除的组件需要手动导入。' )
126+ . describe (
127+ '排除自动导入的组件列表。数组元素为组件名称(不含前缀),如 ["Button", "Input"]。被排除的组件需要手动导入。' ,
128+ )
123129 . default ( [ ] )
124130 . optional ( ) ,
125131 importStyle : zod
126- . union ( [ zod . boolean ( ) , zod . literal ( 'css' ) , zod . literal ( 'less' ) , zod . literal ( 'css-in-js' ) ] )
127- . describe ( '样式导入方式。true 或 "css" 导入编译后的 CSS 文件,"less" 导入 Less 源文件以支持主题定制,"css-in-js" 导入 CSS-in-JS 样式,false 不自动导入样式。默认为 "css"。' )
132+ . union ( [
133+ zod . boolean ( ) ,
134+ zod . literal ( 'css' ) ,
135+ zod . literal ( 'less' ) ,
136+ zod . literal ( 'css-in-js' ) ,
137+ ] )
138+ . describe (
139+ '样式导入方式。true 或 "css" 导入编译后的 CSS 文件,"less" 导入 Less 源文件以支持主题定制,"css-in-js" 导入 CSS-in-JS 样式,false 不自动导入样式。默认为 "css"。' ,
140+ )
128141 . optional ( ) ,
129142 resolveIcons : zod
130143 . boolean ( )
131- . describe ( '是否自动解析和导入 Ant Design Vue 的图标组件。设为 true 时,将自动解析并导入图标组件,无需手动导入。需要安装 @ant-design/icons-vue 包。默认为 false。' )
144+ . describe (
145+ '是否自动解析和导入 Ant Design Vue 的图标组件。设为 true 时,将自动解析并导入图标组件,无需手动导入。需要安装 @ant-design/icons-vue 包。默认为 false。' ,
146+ )
132147 . default ( false )
133148 . optional ( ) ,
134149 cjs : zod
135150 . boolean ( )
136- . describe ( '是否使用 CommonJS 构建版本。设为 true 时使用 CommonJS 构建,false 使用 ES 模块构建。默认为 false。' )
151+ . describe (
152+ '是否使用 CommonJS 构建版本。设为 true 时使用 CommonJS 构建,false 使用 ES 模块构建。默认为 false。' ,
153+ )
137154 . default ( false )
138155 . optional ( ) ,
139156 packageName : zod
140157 . string ( )
141- . describe ( '重命名包名。用于指定 ant-design-vue 包的别名或自定义包名。默认为 "ant-design-vue"。' )
158+ . describe (
159+ '重命名包名。用于指定 ant-design-vue 包的别名或自定义包名。默认为 "ant-design-vue"。' ,
160+ )
142161 . default ( 'ant-design-vue' )
143162 . optional ( ) ,
144163 prefix : zod
145164 . string ( )
146- . describe ( '组件名称前缀。默认为 "A",对应 "AButton"、"AInput" 等组件名。如需自定义可修改此配置。' )
165+ . describe (
166+ '组件名称前缀。默认为 "A",对应 "AButton"、"AInput" 等组件名。如需自定义可修改此配置。' ,
167+ )
147168 . default ( 'A' )
148- . optional ( )
169+ . optional ( ) ,
149170 } )
150- . describe ( 'Ant Design Vue 自动导入插件配置。集成 unplugin-vue-components 的 AntDesignVueResolver,提供 Ant Design Vue 组件和样式的按需自动导入功能,支持 Vue2 和 Vue3 版本。' )
171+ . describe (
172+ 'Ant Design Vue 自动导入插件配置。集成 unplugin-vue-components 的 AntDesignVueResolver,提供 Ant Design Vue 组件和样式的按需自动导入功能,支持 Vue2 和 Vue3 版本。' ,
173+ )
151174 . optional ( )
152175 . default ( { } ) ;
153- }
176+ } ,
154177 } ,
155- enableBy : api . EnableBy . config
178+ enableBy : api . EnableBy . config ,
156179 } ) ;
157180
158181 // 获取用户配置,如果没有配置则使用默认值
159182 const userConfig = api . config . antdv || { } ;
160183 const resolverConfig = {
161184 // 排除的组件列表:默认为空数组
162- ...( userConfig . exclude && userConfig . exclude . length > 0 && { exclude : userConfig . exclude } ) ,
185+ ...( userConfig . exclude &&
186+ userConfig . exclude . length > 0 && { exclude : userConfig . exclude } ) ,
163187 // 样式导入方式:用户配置优先,否则使用默认值 'css'
164- importStyle : userConfig . importStyle !== undefined ? userConfig . importStyle : 'css' ,
188+ importStyle :
189+ userConfig . importStyle !== undefined ? userConfig . importStyle : 'css' ,
165190 // 是否解析图标:默认为 false
166- resolveIcons : userConfig . resolveIcons !== undefined ? userConfig . resolveIcons : false ,
191+ resolveIcons :
192+ userConfig . resolveIcons !== undefined ? userConfig . resolveIcons : false ,
167193 // 是否使用 CommonJS:默认为 false
168194 ...( userConfig . cjs !== undefined && { cjs : userConfig . cjs } ) ,
169195 // 包名:默认为 'ant-design-vue'
170- ...( userConfig . packageName && userConfig . packageName !== 'ant-design-vue' && { packageName : userConfig . packageName } ) ,
196+ ...( userConfig . packageName &&
197+ userConfig . packageName !== 'ant-design-vue' && {
198+ packageName : userConfig . packageName ,
199+ } ) ,
171200 // 组件前缀:默认为 'A'
172- ...( userConfig . prefix && userConfig . prefix !== 'A' && { prefix : userConfig . prefix } )
201+ ...( userConfig . prefix &&
202+ userConfig . prefix !== 'A' && { prefix : userConfig . prefix } ) ,
173203 } ;
174204
175205 const unComponents = {
176- resolvers : [ AntDesignVueResolver ( resolverConfig ) ]
206+ resolvers : [ AntDesignVueResolver ( resolverConfig ) ] ,
177207 } ;
178208
179- api . userConfig . autoImport = deepmerge ( {
180- unComponents
181- } , api . userConfig . autoImport || { } ) ;
182- }
209+ api . userConfig . autoImport = deepmerge (
210+ {
211+ unComponents,
212+ } ,
213+ api . userConfig . autoImport || { } ,
214+ ) ;
215+ } ;
0 commit comments