Skip to content

Develop Zod to Valibot codemod #1191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 108 commits into
base: main
Choose a base branch
from
Draft

Develop Zod to Valibot codemod #1191

wants to merge 108 commits into from

Conversation

EltonLobo07
Copy link
Collaborator

@EltonLobo07 EltonLobo07 commented May 10, 2025

Motivation

Just a few days before Valibot v1 was about to be released, @fabian-hiller created a poll on X. The results were pretty clear - The community needs a Zod to Valibot codemod! We also think the codemod will help Valibot and the projects that wish to migrate from Zod to Valibot. That's why we have decided to develop an official Zod to Valibot codemod.

How do we plan to develop the codemod?

In most cases, Zod to Valibot code transformation is very easy since both APIs have a lot of similarities. We recommend reading this guide for more details. However, we also discovered some cases were tricky or impossible to transform. That's why we think this would be the best strategy to develop the codemod:

  1. Identify the cases that cover most of the uses and create tests for them.
  2. Develop the codemod by using the tests from the previous step.
  3. Release an initial version of the codemod.
  4. Keep on improving the codemod till it's perfect.

Over the last month, we have identified most of the cases. You can find the tests associated with all of the identified cases here. Step number 2 is where we will need community's help.

Goal

The main purpose of this draft PR is to get some amount of help from interested contributors to develop the codemod.

Project structure

Everything related to the codemod is inside /codemod/zod-to-valibot on the zod-to-valibot-codemod branch. The __testfixtures__ folder contains tests for each identified case. The test-setup.test.ts file inside the src folder is where the names of the tests that are completed (the Zod to Valibot transformation works) are placed. The transform folder inside the src folder contains all of the logic related to the codemod.

How to contribute

Before you get started, we recommend reading the contributing doc.

Most of the time, these are the steps you will follow:

  1. Pick an unassigned test from the progress table.
  2. Add a comment to this PR indicating you wish to work on the picked test and start working only after getting a thumbs up from @EltonLobo07 or @fabian-hiller.
  3. Once done, add the test to the test setup.
  4. If every test in the test setup pass, create a PR to the zod-to-valibot-codemod branch!

Some important points to keep in mind:

  • The tests might not be perfect. They might contain subtle mistakes, might not cover all of the cases, and so on. Use each test as a starting point. Feel free to improve them.
  • The folder and code structure inside the /src/transform folder are not fixed. Feel free to use your own judgment while adding new files or code.
  • Sometimes you may have to modify the existing code of a file. Don't hesitate to modify any of the existing code. Just make sure all of the tests in the test setup pass.
  • If there is a Zod feature that is not covered in the tests, feel free to discuss it in our Discord group. I will be adding some more tests as we progress building the codemod. Keep an eye on the progress table.

If you have any questions, feel free to reach out to us on Discord. There is a section dedicated to the codemod!

Progress table

Test Author Pull Request Merged
array-element @EltonLobo07 NA
array-nonempty @EltonLobo07 NA
array-schema @EltonLobo07 NA
array-validation-methods @EltonLobo07 NA
bigint-validation-methods @EltonLobo07 NA
coerce-bigint-schema @EltonLobo07 NA
coerce-boolean-schema @EltonLobo07 NA
coerce-date-schema @EltonLobo07 NA
coerce-number-schema @EltonLobo07 NA
coerce-string-schema @EltonLobo07 NA
custom-schema - - -
date-validation-methods @EltonLobo07 NA
default-import-with-alias @EltonLobo07 NA
default-import-with-specific-alias @EltonLobo07 NA
default-import @EltonLobo07 NA
default @EltonLobo07 NA
describe @EltonLobo07 NA
discriminated-union-schema @EltonLobo07 NA
instanceof-schema @EltonLobo07 NA
intersection-schema @EltonLobo07 NA
literal-schema @EltonLobo07 NA
map-schema @EltonLobo07 NA
named-import-with-alias @EltonLobo07 NA
named-import-with-specific-alias @EltonLobo07 NA
named-import @EltonLobo07 NA
namespace-import @EltonLobo07 NA
native-enum @EltonLobo07 NA
nullable-schema @EltonLobo07 NA
nullish-schema @EltonLobo07 NA
number-validation-methods @EltonLobo07 NA
object-catchall @EltonLobo07 - -
object-extend - - -
object-keyof @EltonLobo07 NA
object-merge - - -
object-omit @EltonLobo07 NA
object-partial @EltonLobo07 NA
object-passthrough @EltonLobo07 NA
object-pick @EltonLobo07 NA
object-required @EltonLobo07 NA
object-shape @EltonLobo07 NA
object-strict @EltonLobo07 NA
object-strip @EltonLobo07 NA
optional-schema @EltonLobo07 NA
parsing @EltonLobo07 NA
readonly @EltonLobo07 NA
record-schema @niconiahi #1205
schema-chain @EltonLobo07 NA
schema-options @EltonLobo07 NA
set-schema @EltonLobo07 NA
set-validation-methods @EltonLobo07 NA
specific-default-import @EltonLobo07 NA
specific-namespace-import @EltonLobo07 NA
string-validation-methods @EltonLobo07 NA
tuple-schema @niconiahi #1206 -
type-inference - - -
union-schema @EltonLobo07 NA
validation-error-msg @EltonLobo07 NA
zod-enum @EltonLobo07 NA
zod-pipe - - -

niconiahi and others added 4 commits May 26, 2025 11:03
unify the transformation of all components of a Zod schema, specifically
transform Zod properties the same way other components of a Zod schema
are transformed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority This has priority tooling Tooling for devs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants