zod-v3-to-v4 1.5.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/collect-imports.js +1 -1
- package/dist/migrate.js +9 -6
- package/package.json +17 -14
package/dist/collect-imports.js
CHANGED
|
@@ -2,7 +2,7 @@ import { SyntaxKind } from "ts-morph";
|
|
|
2
2
|
export function collectZodImportDeclarations(sourceFile) {
|
|
3
3
|
return sourceFile
|
|
4
4
|
.getImportDeclarations()
|
|
5
|
-
.filter((importDeclaration) => ["zod", "zod/
|
|
5
|
+
.filter((importDeclaration) => ["zod", "zod/v3"].includes(importDeclaration.getModuleSpecifierValue()));
|
|
6
6
|
}
|
|
7
7
|
export function getZodName(importDeclarations) {
|
|
8
8
|
const zodImport = importDeclarations[0]
|
package/dist/migrate.js
CHANGED
|
@@ -7,13 +7,16 @@ import { isZodNode } from "./zod-node.js";
|
|
|
7
7
|
export function migrateZodV3ToV4(sourceFile, options = {}) {
|
|
8
8
|
const importDeclarations = collectZodImportDeclarations(sourceFile);
|
|
9
9
|
const zodName = getZodName(importDeclarations);
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
importDeclarations.forEach((declaration) => {
|
|
11
|
+
if (declaration.getModuleSpecifier().getText() === "zod/v3") {
|
|
12
|
+
declaration.setModuleSpecifier("zod");
|
|
13
|
+
}
|
|
14
|
+
if (options.migrateImportDeclarations) {
|
|
15
|
+
// Use `zod/v4` explicit import. Not needed for an actual migration.
|
|
16
|
+
// Useful for testing, so we can have v3.25 and typecheck both v3 and v4
|
|
14
17
|
declaration.setModuleSpecifier("zod/v4");
|
|
15
|
-
}
|
|
16
|
-
}
|
|
18
|
+
}
|
|
19
|
+
});
|
|
17
20
|
collectZodReferences(importDeclarations).forEach((node) => {
|
|
18
21
|
if (node.wasForgotten()) {
|
|
19
22
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zod-v3-to-v4",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "Migrate Zod from v3 to v4",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"zod",
|
|
@@ -25,6 +25,20 @@
|
|
|
25
25
|
"README.md",
|
|
26
26
|
"dist/*.js"
|
|
27
27
|
],
|
|
28
|
+
"scripts": {
|
|
29
|
+
"prebuild": "rimraf dist",
|
|
30
|
+
"build": "tsc --project tsconfig.build.json",
|
|
31
|
+
"postbuild": "chmod +x dist/index.js",
|
|
32
|
+
"format": "prettier . --write",
|
|
33
|
+
"format-check": "prettier . --list-different",
|
|
34
|
+
"playground": "pnpm playground:interactive playground/tsconfig.json",
|
|
35
|
+
"playground:interactive": "node --experimental-strip-types --disable-warning=ExperimentalWarning src/index.ts",
|
|
36
|
+
"prepare": "husky",
|
|
37
|
+
"prepublishOnly": "pnpm typecheck && pnpm test && pnpm build",
|
|
38
|
+
"test": "vitest run",
|
|
39
|
+
"test:watch": "vitest watch",
|
|
40
|
+
"typecheck": "tsc --noEmit"
|
|
41
|
+
},
|
|
28
42
|
"lint-staged": {
|
|
29
43
|
"*": "prettier --ignore-unknown --write"
|
|
30
44
|
},
|
|
@@ -45,16 +59,5 @@
|
|
|
45
59
|
"vitest": "3.1.4",
|
|
46
60
|
"zod": "3.25.12"
|
|
47
61
|
},
|
|
48
|
-
"
|
|
49
|
-
|
|
50
|
-
"build": "tsc --project tsconfig.build.json",
|
|
51
|
-
"postbuild": "chmod +x dist/index.js",
|
|
52
|
-
"format": "prettier . --write",
|
|
53
|
-
"format-check": "prettier . --list-different",
|
|
54
|
-
"playground": "pnpm playground:interactive playground/tsconfig.json",
|
|
55
|
-
"playground:interactive": "node --experimental-strip-types --disable-warning=ExperimentalWarning src/index.ts",
|
|
56
|
-
"test": "vitest run",
|
|
57
|
-
"test:watch": "vitest watch",
|
|
58
|
-
"typecheck": "tsc --noEmit"
|
|
59
|
-
}
|
|
60
|
-
}
|
|
62
|
+
"packageManager": "pnpm@9.15.4+sha512.b2dc20e2fc72b3e18848459b37359a32064663e5627a51e4c74b2c29dd8e8e0491483c3abb40789cfd578bf362fb6ba8261b05f0387d76792ed6e23ea3b1b6a0"
|
|
63
|
+
}
|