Skip to content

Commit

Permalink
feat(nuxt): add valibot support (#4412)
Browse files Browse the repository at this point in the history
  • Loading branch information
userquin committed Aug 13, 2023
1 parent 7bd8e75 commit d2cc9bc
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion packages/nuxt/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,44 @@ export default defineNuxtModule<VeeValidateNuxtOptions>({

const usingYup = checkForYup(options);
if (!usingYup) {
checkForZod(options);
if (!checkForZod(options)) {
checkForValibot(options);
}
}
},
}) as NuxtModule<VeeValidateNuxtOptions>;

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(
Expand Down

0 comments on commit d2cc9bc

Please sign in to comment.