Skip to content

Commit b1f39ba

Browse files
kolvianjosephsavona
authored andcommitted
[compiler] Update for Zod v3/v4 compatibility
Partial redo of #34710. The changes there tried to use `z.function(args, return)` to be compatible across Zod v3 and v4, but Zod 4's function API has completely changed. Instead, I've updated to just use `z.any()` where we expect a function, and manually validate that it's a function before we call the value. We already have validation of the return type (also using Zod).
1 parent 0eebd37 commit b1f39ba

File tree

8 files changed

+31
-50
lines changed

8 files changed

+31
-50
lines changed

compiler/packages/babel-plugin-react-compiler/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@
5252
"react-dom": "0.0.0-experimental-4beb1fd8-20241118",
5353
"ts-jest": "^29.1.1",
5454
"ts-node": "^10.9.2",
55-
"zod": "^3.22.4",
56-
"zod-validation-error": "^2.1.0"
55+
"zod": "^3.22.4 || ^4.0.0",
56+
"zod-validation-error": "^3.0.3 || ^4.0.0"
5757
},
5858
"resolutions": {
5959
"./**/@babel/parser": "7.7.4",

compiler/packages/babel-plugin-react-compiler/src/HIR/Environment.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ export const EnvironmentConfigSchema = z.object({
159159
* A function that, given the name of a module, can optionally return a description
160160
* of that module's type signature.
161161
*/
162-
moduleTypeProvider: z.nullable(z.function().args(z.string())).default(null),
162+
moduleTypeProvider: z.nullable(z.any()).default(null),
163163

164164
/**
165165
* A list of functions which the application compiles as macros, where
@@ -249,7 +249,7 @@ export const EnvironmentConfigSchema = z.object({
249249
* Allows specifying a function that can populate HIR with type information from
250250
* Flow
251251
*/
252-
flowTypeProvider: z.nullable(z.function().args(z.string())).default(null),
252+
flowTypeProvider: z.nullable(z.any()).default(null),
253253

254254
/**
255255
* Enables inference of optional dependency chains. Without this flag
@@ -906,6 +906,12 @@ export class Environment {
906906
if (moduleTypeProvider == null) {
907907
return null;
908908
}
909+
if (typeof moduleTypeProvider !== 'function') {
910+
CompilerError.throwInvalidConfig({
911+
reason: `Expected a function for \`moduleTypeProvider\``,
912+
loc,
913+
});
914+
}
909915
const unparsedModuleConfig = moduleTypeProvider(moduleName);
910916
if (unparsedModuleConfig != null) {
911917
const parsedModuleConfig = TypeSchema.safeParse(unparsedModuleConfig);

compiler/packages/babel-plugin-react-compiler/src/__tests__/envConfig-test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('parseConfigPragma()', () => {
2020
validateHooksUsage: 1,
2121
} as any);
2222
}).toThrowErrorMatchingInlineSnapshot(
23-
`"Error: Could not validate environment config. Update React Compiler config to fix the error. Validation error: Expected boolean, received number at "validateHooksUsage"."`,
23+
`"Error: Could not validate environment config. Update React Compiler config to fix the error. Validation error: Invalid input: expected boolean, received number at "validateHooksUsage"."`,
2424
);
2525
});
2626

@@ -38,7 +38,7 @@ describe('parseConfigPragma()', () => {
3838
],
3939
} as any);
4040
}).toThrowErrorMatchingInlineSnapshot(
41-
`"Error: Could not validate environment config. Update React Compiler config to fix the error. Validation error: autodepsIndex must be > 0 at "inferEffectDependencies[0].autodepsIndex"."`,
41+
`"Error: Could not validate environment config. Update React Compiler config to fix the error. Validation error: AutodepsIndex must be > 0 at "inferEffectDependencies[0].autodepsIndex"."`,
4242
);
4343
});
4444

compiler/packages/eslint-plugin-react-compiler/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
"@babel/parser": "^7.24.4",
1717
"@babel/plugin-proposal-private-methods": "^7.18.6",
1818
"hermes-parser": "^0.25.1",
19-
"zod": "^3.22.4",
20-
"zod-validation-error": "^3.0.3"
19+
"zod": "^3.22.4 || ^4.0.0",
20+
"zod-validation-error": "^3.0.3 || ^4.0.0"
2121
},
2222
"devDependencies": {
2323
"@babel/preset-env": "^7.22.4",

compiler/packages/react-compiler-healthcheck/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
"fast-glob": "^3.3.2",
1818
"ora": "5.4.1",
1919
"yargs": "^17.7.2",
20-
"zod": "^3.22.4",
21-
"zod-validation-error": "^3.0.3"
20+
"zod": "^3.22.4 || ^4.0.0",
21+
"zod-validation-error": "^3.0.3 || ^4.0.0"
2222
},
2323
"devDependencies": {},
2424
"engines": {

compiler/packages/react-mcp-server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"html-to-text": "^9.0.5",
2525
"prettier": "^3.3.3",
2626
"puppeteer": "^24.7.2",
27-
"zod": "^3.23.8"
27+
"zod": "^3.22.4 || ^4.0.0"
2828
},
2929
"devDependencies": {
3030
"@types/html-to-text": "^9.0.4",

compiler/yarn.lock

Lines changed: 12 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -10494,16 +10494,7 @@ string-length@^4.0.1:
1049410494
char-regex "^1.0.2"
1049510495
strip-ansi "^6.0.0"
1049610496

10497-
"string-width-cjs@npm:string-width@^4.2.0":
10498-
version "4.2.3"
10499-
resolved "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz"
10500-
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
10501-
dependencies:
10502-
emoji-regex "^8.0.0"
10503-
is-fullwidth-code-point "^3.0.0"
10504-
strip-ansi "^6.0.1"
10505-
10506-
string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
10497+
"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
1050710498
version "4.2.3"
1050810499
resolved "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz"
1050910500
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
@@ -10576,14 +10567,7 @@ string_decoder@~1.1.1:
1057610567
dependencies:
1057710568
safe-buffer "~5.1.0"
1057810569

10579-
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
10580-
version "6.0.1"
10581-
resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz"
10582-
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
10583-
dependencies:
10584-
ansi-regex "^5.0.1"
10585-
10586-
strip-ansi@^6.0.0, strip-ansi@^6.0.1:
10570+
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
1058710571
version "6.0.1"
1058810572
resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz"
1058910573
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
@@ -11360,7 +11344,7 @@ workerpool@^6.5.1:
1136011344
resolved "https://registry.npmjs.org/workerpool/-/workerpool-6.5.1.tgz"
1136111345
integrity sha512-Fs4dNYcsdpYSAfVxhnl1L5zTksjvOJxtC5hzMNl+1t9B8hTJTdKDyZ5ju7ztgPy+ft9tBFXoOlDNiOT9WUXZlA==
1136211346

11363-
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
11347+
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
1136411348
version "7.0.0"
1136511349
resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz"
1136611350
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
@@ -11378,15 +11362,6 @@ wrap-ansi@^6.2.0:
1137811362
string-width "^4.1.0"
1137911363
strip-ansi "^6.0.0"
1138011364

11381-
wrap-ansi@^7.0.0:
11382-
version "7.0.0"
11383-
resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz"
11384-
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
11385-
dependencies:
11386-
ansi-styles "^4.0.0"
11387-
string-width "^4.1.0"
11388-
strip-ansi "^6.0.0"
11389-
1139011365
wrap-ansi@^8.1.0:
1139111366
version "8.1.0"
1139211367
resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-8.1.0.tgz"
@@ -11538,17 +11513,17 @@ zod-to-json-schema@^3.24.1:
1153811513
resolved "https://registry.npmjs.org/zod-to-json-schema/-/zod-to-json-schema-3.24.5.tgz"
1153911514
integrity sha512-/AuWwMP+YqiPbsJx5D6TfgRTc4kTLjsh5SOcd4bLsfUg2RcEXrFMJl1DGgdHy2aCfsIA/cr/1JM0xcB2GZji8g==
1154011515

11541-
zod-validation-error@^2.1.0:
11542-
version "2.1.0"
11543-
resolved "https://registry.npmjs.org/zod-validation-error/-/zod-validation-error-2.1.0.tgz"
11544-
integrity sha512-VJh93e2wb4c3tWtGgTa0OF/dTt/zoPCPzXq4V11ZjxmEAFaPi/Zss1xIZdEB5RD8GD00U0/iVXgqkF77RV7pdQ==
11516+
"zod-validation-error@^3.0.3 || ^4.0.0":
11517+
version "4.0.2"
11518+
resolved "https://registry.yarnpkg.com/zod-validation-error/-/zod-validation-error-4.0.2.tgz#bc605eba49ce0fcd598c127fee1c236be3f22918"
11519+
integrity sha512-Q6/nZLe6jxuU80qb/4uJ4t5v2VEZ44lzQjPDhYJNztRQ4wyWc6VF3D3Kb/fAuPetZQnhS3hnajCf9CsWesghLQ==
1154511520

11546-
zod-validation-error@^3.0.3:
11547-
version "3.0.3"
11548-
resolved "https://registry.npmjs.org/zod-validation-error/-/zod-validation-error-3.0.3.tgz"
11549-
integrity sha512-cETTrcMq3Ze58vhdR0zD37uJm/694I6mAxcf/ei5bl89cC++fBNxrC2z8lkFze/8hVMPwrbtrwXHR2LB50fpHw==
11521+
"zod@^3.22.4 || ^4.0.0":
11522+
version "4.1.11"
11523+
resolved "https://registry.yarnpkg.com/zod/-/zod-4.1.11.tgz#4aab62f76cfd45e6c6166519ba31b2ea019f75f5"
11524+
integrity sha512-WPsqwxITS2tzx1bzhIKsEs19ABD5vmCVa4xBo2tq/SrV4RNZtfws1EnCWQXM6yh8bD08a1idvkB5MZSBiZsjwg==
1155011525

11551-
zod@^3.22.4, zod@^3.23.8, zod@^3.24.1:
11526+
zod@^3.23.8, zod@^3.24.1:
1155211527
version "3.24.3"
1155311528
resolved "https://registry.npmjs.org/zod/-/zod-3.24.3.tgz"
1155411529
integrity sha512-HhY1oqzWCQWuUqvBFnsyrtZRhyPeR7SUGv+C4+MsisMuVfSPx8HpwWqH8tRahSlt6M3PiFAcoeFhZAqIXTxoSg==

packages/eslint-plugin-react-hooks/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
"@babel/parser": "^7.24.4",
4444
"@babel/plugin-proposal-private-methods": "^7.18.6",
4545
"hermes-parser": "^0.25.1",
46-
"zod": "^3.22.4",
47-
"zod-validation-error": "^3.0.3"
46+
"zod": "^3.22.4 || ^4.0.0",
47+
"zod-validation-error": "^3.0.3 || ^4.0.0"
4848
},
4949
"devDependencies": {
5050
"@babel/eslint-parser": "^7.11.4",

0 commit comments

Comments
 (0)