From d2cc9bc37f52ac962762f87cfe8371c2cf6f4051 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaqu=C3=ADn=20S=C3=A1nchez?= Date: Mon, 14 Aug 2023 01:09:38 +0200 Subject: [PATCH] feat(nuxt): add valibot support (#4412) --- packages/nuxt/src/module.ts | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/packages/nuxt/src/module.ts b/packages/nuxt/src/module.ts index 64019d1cf..0f846d035 100644 --- a/packages/nuxt/src/module.ts +++ b/packages/nuxt/src/module.ts @@ -62,11 +62,44 @@ export default defineNuxtModule({ const usingYup = checkForYup(options); if (!usingYup) { - checkForZod(options); + if (!checkForZod(options)) { + checkForValibot(options); + } } }, }) as NuxtModule; +function checkForValibot(options: VeeValidateNuxtOptions) { + if (isPackageExists('valibot') && !isPackageExists('@vee-validate/valibot')) { + logger.warn( + 'You seem to be using valibot, but you have not installed @vee-validate/valibot. Please install it to use valibot with vee-validate.', + ); + return true; + } + + if (isPackageExists('@vee-validate/valibot') && !isPackageExists('valibot')) { + logger.warn( + 'You seem to be using @vee-validate/valibot, but you have not installed valibot. Please install it to use valibot with vee-validate.', + ); + return true; + } + + if (isPackageExists('@vee-validate/valibot') && isPackageExists('valibot')) { + logger.info('Using valibot with vee-validate'); + if (options.autoImports) { + addImports({ + name: 'toTypedSchema', + as: 'toTypedSchema', + from: '@vee-validate/valibot', + }); + } + + return true; + } + + return false; +} + function checkForZod(options: VeeValidateNuxtOptions) { if (isPackageExists('zod') && !isPackageExists('@vee-validate/zod')) { logger.warn(