1- import { defineNuxtModule , addComponent , addImports , logger } from '@nuxt/kit' ;
2- import type { NuxtModule } from '@nuxt/schema' ;
1+ import { defineNuxtModule , addComponent , addImports , logger , resolveModule } from '@nuxt/kit' ;
2+ import type { Nuxt , NuxtModule } from '@nuxt/schema' ;
33import { isPackageExists } from 'local-pkg' ;
44
55type ComponentName = 'Field' | 'Form' | 'ErrorMessage' | 'FieldArray' ;
@@ -51,7 +51,7 @@ export default defineNuxtModule<VeeValidateNuxtOptions>({
5151 autoImports : true ,
5252 componentNames : { } ,
5353 } ,
54- setup ( options ) {
54+ setup ( options , nuxt ) {
5555 if ( options . autoImports ) {
5656 composables . forEach ( composable => {
5757 addImports ( {
@@ -75,25 +75,27 @@ export default defineNuxtModule<VeeValidateNuxtOptions>({
7575 }
7676
7777 if ( options . typedSchemaPackage === 'yup' ) {
78- checkForYup ( options ) ;
78+ checkForYup ( options , nuxt ) ;
7979 return ;
8080 }
8181
8282 if ( options . typedSchemaPackage === 'zod' ) {
83- checkForZod ( options ) ;
83+ checkForZod ( options , nuxt ) ;
8484 return ;
8585 }
8686
8787 if ( options . typedSchemaPackage === 'valibot' ) {
88- checkForValibot ( options ) ;
88+ checkForValibot ( options , nuxt ) ;
8989 return ;
9090 }
9191
92- if ( ! checkForYup ( options ) ) {
93- if ( ! checkForZod ( options ) ) {
94- checkForValibot ( options ) ;
92+ if ( ! checkForYup ( options , nuxt ) ) {
93+ if ( ! checkForZod ( options , nuxt ) ) {
94+ checkForValibot ( options , nuxt ) ;
9595 }
9696 }
97+
98+ addMjsAlias ( 'vee-validate' , 'vee-validate' , nuxt ) ;
9799 } ,
98100} ) as NuxtModule < VeeValidateNuxtOptions > ;
99101
@@ -113,7 +115,7 @@ function checkSchemaResolverDependencies(pkgName: (typeof schemaProviders)[numbe
113115 }
114116}
115117
116- function checkForValibot ( options : VeeValidateNuxtOptions ) {
118+ function checkForValibot ( options : VeeValidateNuxtOptions , nuxt : Nuxt ) {
117119 checkSchemaResolverDependencies ( 'valibot' ) ;
118120 if ( isPackageExists ( '@vee-validate/valibot' ) && isPackageExists ( 'valibot' ) ) {
119121 logger . info ( 'Using valibot with vee-validate' ) ;
@@ -125,13 +127,15 @@ function checkForValibot(options: VeeValidateNuxtOptions) {
125127 } ) ;
126128 }
127129
130+ addMjsAlias ( '@vee-validate/valibot' , 'vee-validate-valibot' , nuxt ) ;
131+
128132 return true ;
129133 }
130134
131135 return false ;
132136}
133137
134- function checkForZod ( options : VeeValidateNuxtOptions ) {
138+ function checkForZod ( options : VeeValidateNuxtOptions , nuxt : Nuxt ) {
135139 checkSchemaResolverDependencies ( 'zod' ) ;
136140 if ( isPackageExists ( '@vee-validate/zod' ) && isPackageExists ( 'zod' ) ) {
137141 logger . info ( 'Using zod with vee-validate' ) ;
@@ -143,13 +147,15 @@ function checkForZod(options: VeeValidateNuxtOptions) {
143147 } ) ;
144148 }
145149
150+ addMjsAlias ( '@vee-validate/zod' , 'vee-validate-zod' , nuxt ) ;
151+
146152 return true ;
147153 }
148154
149155 return false ;
150156}
151157
152- function checkForYup ( options : VeeValidateNuxtOptions ) {
158+ function checkForYup ( options : VeeValidateNuxtOptions , nuxt : Nuxt ) {
153159 checkSchemaResolverDependencies ( 'yup' ) ;
154160 if ( isPackageExists ( '@vee-validate/yup' ) && isPackageExists ( 'yup' ) ) {
155161 logger . info ( 'Using yup with vee-validate' ) ;
@@ -161,12 +167,23 @@ function checkForYup(options: VeeValidateNuxtOptions) {
161167 } ) ;
162168 }
163169
170+ addMjsAlias ( '@vee-validate/yup' , 'vee-validate-yup' , nuxt ) ;
171+
164172 return true ;
165173 }
166174
167175 return false ;
168176}
169177
178+ function addMjsAlias ( pkgName : string , fileName : string , nuxt : Nuxt ) {
179+ // FIXME: Deprecated, idk why since it duplicate imports
180+ nuxt . options . alias [ pkgName ] =
181+ nuxt . options . alias [ pkgName ] ||
182+ resolveModule ( `${ pkgName } /dist/${ fileName } .mjs` , {
183+ paths : [ nuxt . options . rootDir , import . meta. url ] ,
184+ } ) ;
185+ }
186+
170187declare module '@nuxt/schema' {
171188 interface NuxtConfig {
172189 'vee-validate' ?: VeeValidateNuxtOptions ;
0 commit comments