Skip to content

nicoespeon/zod-v3-to-v4

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

393 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Zod v3 to v4

NPM version GitHub Actions Workflow Status All Contributors

This is a codemod (a tool that automatically transforms code) for migrating from Zod v3 to v4.

The migration guide can be found at https://zod.dev/v4/changelog

zod-v3-to-v4-demo

Using this codemod

This assumes you have Node.js installed.

The first step for you is to upgrade your Zod version to v4. In doubt, check your package.json. Note that if you're using Zod through Astro v6, you don't need to upgrade Zod manually.

Then, you can use this codemod to automatically migrate your code from Zod v3 to v4 syntax.

This codemod also migrates .vue files containing Zod schemas.

Interactive CLI

You can run it with the following command:

npx zod-v3-to-v4

It will ask you for the path to your tsconfig.json file, and then it will go through all your files and migrate Zod v3 code to v4.

Non-interactive CLI

Alternatively, you can pass the path to your tsconfig.json file as an argument:

npx zod-v3-to-v4 path/to/your/tsconfig.json

This is useful if you ever need to run the codemod in script (e.g. in a CI pipeline).

Installing it as a package

You can also install it as a package and run it from your project:

npm install -ED zod-v3-to-v4

And then run it with:

npx zod-v3-to-v4

Reporting issues

If the codemod missed something or did something wrong, please open an issue.

Contributing

This project uses node.js and pnpm. To get started, run:

pnpm install

To run the tests, run:

pnpm test

We use ts-morph to parse and transform the code.

Useful links:

Playground

If you want to test the codemod from CLI, you can use the playground folder. It contains a tsconfig.json file and some sample TypeScript files with Zod v3 code. You can run the codemod on these files with:

pnpm playground

Or interactively:

pnpm playground:interactive
# Then enter: playground/tsconfig.json

Contributors

Nicolas Carlo
Nicolas Carlo

πŸ€” πŸ’» πŸ“– πŸ‘€ πŸ’¬
HiDeoo
HiDeoo

πŸ€” πŸ’»
Gajus Kuizinas
Gajus Kuizinas

πŸ€”
Kirill Loskutov
Kirill Loskutov

πŸ›
Schrubitteflau
Schrubitteflau

πŸ€” πŸ’»
Erik
Erik

πŸ›
Einar GuΓ°ni GuΓ°jΓ³nsson
Einar GuΓ°ni GuΓ°jΓ³nsson

πŸ›
Daniel Ugbeye
Daniel Ugbeye

πŸ€”
Kevin Firko
Kevin Firko

πŸ› πŸ€”
Greg Sims
Greg Sims

πŸ›
PowerSupply
PowerSupply

πŸ›
Christophe Frèrebeau
Christophe Frèrebeau

πŸ›
aelligsen
aelligsen

πŸ€”
Nikolaus Z
Nikolaus Z

πŸ›
Bastien Jorge
Bastien Jorge

πŸ›
Daniel Friesen
Daniel Friesen

πŸ›
Marvin Affeldt
Marvin Affeldt

πŸ€”
Abdullah Alaqeel
Abdullah Alaqeel

πŸ›
Wonder Woman
Wonder Woman

πŸ›
nzhiti
nzhiti

πŸ€”
Simon Roberts
Simon Roberts

πŸ›
yann-combarnous
yann-combarnous

πŸ›
acdoussan
acdoussan

πŸ›
Mats Julius Funke
Mats Julius Funke

πŸ€”
popfendi
popfendi

πŸ›
LuΓ­s Azevedo
LuΓ­s Azevedo

πŸ€” πŸ›
Florian Lefebvre
Florian Lefebvre

πŸ› πŸ€” πŸ‘€
Robert Cooper
Robert Cooper

πŸ›
Khiet Tam Nguyen
Khiet Tam Nguyen

πŸ€”
Neil Richter
Neil Richter

πŸ€”
Jeremy Bogatirsky
Jeremy Bogatirsky

πŸ’»
Greg W
Greg W

πŸ›
paulrudy
paulrudy

πŸ›
Tiago tms Silveira
Tiago tms Silveira

πŸ›
M. Hossein Zendehpey
M. Hossein Zendehpey

πŸ›
Arun Kumar
Arun Kumar

πŸ€”
Add your contributions

About

A codemod to migrate from Zod v3 to v4

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Contributors