Skip to content

Commit 2cc31b5

Browse files
authored
chore(deps): upgrade zod from v3 to v4 and update imports (#11883)
* chore(deps): upgrade zod from v3 to v4 and update imports * fix: snapshot
1 parent 6503227 commit 2cc31b5

File tree

10 files changed

+50
-62
lines changed

10 files changed

+50
-62
lines changed

packages/rspack/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@
5858
"typescript": "^5.9.3",
5959
"watchpack": "^2.4.4",
6060
"webpack-sources": "3.3.3",
61-
"zod": "^3.25.76",
62-
"zod-validation-error": "3.5.3"
61+
"zod": "^4.1.12",
62+
"zod-validation-error": "^4.0.2"
6363
},
6464
"dependencies": {
6565
"@module-federation/runtime-tools": "0.20.0",

packages/rspack/rslib.config.mts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@ const fixZodTypePlugin: rsbuild.RsbuildPlugin = {
8686
const content = await fs.promises.readFile(filePath, "utf-8");
8787
const newContent = content
8888
.replace(
89-
`import * as z from "zod/v4";`,
90-
`// @ts-ignore\nimport * as z from "zod/v4";`
89+
`import * as z from "zod";`,
90+
`// @ts-ignore\nimport * as z from "zod";`
9191
)
9292
.replace(
93-
`import type { z } from "zod/v4";`,
94-
`// @ts-ignore\nimport type { z } from "zod/v4";`
93+
`import type { z } from "zod";`,
94+
`// @ts-ignore\nimport type { z } from "zod";`
9595
);
9696

9797
if (content !== newContent) {

packages/rspack/src/schema/config.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import nodePath from "node:path";
2-
import * as z from "zod/v4";
3-
import { createErrorMap, fromZodError } from "zod-validation-error/v4";
2+
import * as z from "zod";
3+
import { createErrorMap, fromZodError } from "zod-validation-error";
44
import type * as t from "../config/types";
55
import { memoize } from "../util/memoize";
66
import { getZodSwcLoaderOptionsSchema } from "./loaders";
77
import { anyFunction, intOrInfinity, numberOrInfinity } from "./utils";
88

99
z.config({
10-
jitless: true
10+
jitless: true,
11+
customError: createErrorMap()
1112
});
1213

1314
export const getExternalsTypeSchema = memoize(
@@ -524,10 +525,7 @@ export const getRspackOptionsSchema = memoize(() => {
524525

525526
if (!res.success) {
526527
const validationErr = fromZodError(res.error, {
527-
prefix: "Invalid options for 'builtin:swc-loader'",
528-
error: createErrorMap({
529-
issuesInTitleCase: false
530-
})
528+
prefix: "Invalid options for 'builtin:swc-loader'"
531529
});
532530
ctx.issues.push({
533531
code: "custom",

packages/rspack/src/schema/loaders.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import type {
2222
UmdConfig
2323
} from "@swc/types";
2424
import type { Assumptions } from "@swc/types/assumptions";
25-
import * as z from "zod/v4";
25+
import * as z from "zod";
2626
import type { CollectTypeScriptInfoOptions } from "../builtin-loader/swc/collectTypeScriptInfo";
2727
import type { PluginImportOptions } from "../builtin-loader/swc/pluginImport";
2828
import type {

packages/rspack/src/schema/plugins.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { JsBuildMeta } from "@rspack/binding";
2-
import * as z from "zod/v4";
2+
import * as z from "zod";
33
import type {
44
HtmlRspackPluginOptions,
55
TemplateParamFunction,

packages/rspack/src/schema/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as z from "zod/v4";
1+
import * as z from "zod";
22

33
// Zod v4 doesn't support Infinity, so we need to use a custom type
44
// See: https://github.com/colinhacks/zod/issues/4721

packages/rspack/src/schema/validate.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { z } from "zod/v4";
2-
import { createErrorMap, fromZodError } from "zod-validation-error/v4";
1+
import type { z } from "zod";
2+
import { fromZodError } from "zod-validation-error";
33

44
export class ValidationError extends Error {
55
constructor(message: string) {
@@ -82,17 +82,12 @@ export function validate<T extends z.ZodType>(
8282
}
8383

8484
function toValidationError(error: z.ZodError): ValidationError {
85-
// Instead of using `z.config({ customError: createErrorMap() })` to customize the error message,
86-
// we use `createErrorMap` to customize the error message.
87-
// This gives us fine-grained control over the error messages.
88-
const customErrorMap = createErrorMap();
8985
const separator = "\n- ";
9086
const validationErr = fromZodError(error, {
9187
prefix:
9288
"Invalid configuration object. Rspack has been initialized using a configuration object that does not match the API schema.",
9389
prefixSeparator: separator,
94-
issueSeparator: separator,
95-
error: customErrorMap
90+
issueSeparator: separator
9691
});
9792
return new ValidationError(validationErr.message);
9893
}

pnpm-lock.yaml

Lines changed: 27 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/rspack-test/Validation.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ describe("Validation", () => {
164164
expect(log).toMatchInlineSnapshot(`
165165
Array [
166166
Invalid configuration object. Rspack has been initialized using a configuration object that does not match the API schema.
167-
- Expected string at "output.devtoolModuleFilenameTemplate" or Expected function, received object at "output.devtoolModuleFilenameTemplate",
167+
- Expected string, received set at "output.devtoolModuleFilenameTemplate" or Expected function, received object at "output.devtoolModuleFilenameTemplate",
168168
]
169169
`);
170170
}
@@ -224,8 +224,8 @@ describe("Validation", () => {
224224
message => {
225225
expect(message).toMatchInlineSnapshot(`
226226
Invalid configuration object. Rspack has been initialized using a configuration object that does not match the API schema.
227-
- Expected string at "output.filename" or Expected function, received object at "output.filename"
228-
- Expected string at "output.devtoolModuleFilenameTemplate" or Expected function, received object at "output.devtoolModuleFilenameTemplate"
227+
- Expected string, received array at "output.filename" or Expected function, received object at "output.filename"
228+
- Expected string, received set at "output.devtoolModuleFilenameTemplate" or Expected function, received object at "output.devtoolModuleFilenameTemplate"
229229
`);
230230
},
231231
"strict",
@@ -286,8 +286,8 @@ describe("Validation", () => {
286286
message => {
287287
expect(message).toMatchInlineSnapshot(`
288288
Invalid configuration object. Rspack has been initialized using a configuration object that does not match the API schema.
289-
- Expected string at "output.filename" or Expected function, received object at "output.filename"
290-
- Expected string at "output.devtoolModuleFilenameTemplate" or Expected function, received object at "output.devtoolModuleFilenameTemplate"
289+
- Expected string, received array at "output.filename" or Expected function, received object at "output.filename"
290+
- Expected string, received set at "output.devtoolModuleFilenameTemplate" or Expected function, received object at "output.devtoolModuleFilenameTemplate"
291291
`);
292292
},
293293
log => {

tests/rspack-test/compilerCases/splitchunks-minchunks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module.exports = {
2626
expect(Array.isArray(errors)).toBeTruthy();
2727
expect(errors.length).toBe(1);
2828
expect(errors[0].toString()).toContain(
29-
'Number must be greater or equal to 1 at "optimization.splitChunks.minChunks"'
29+
'Number must be greater than or equal to 1 at "optimization.splitChunks.minChunks"'
3030
);
3131
context.clearError(name);
3232
}

0 commit comments

Comments
 (0)