Skip to content

Commit 0ff51df

Browse files
matthewpflorian-lefebvresarah11918
authored
Upgrade to Zod 4 (#14956)
* feat: upgrade to Zod v4 Consolidate Zod v3 to v4 upgrade with comprehensive changes: - Remove dual Zod version support, standardize on v4 - Simplify type systems and remove experimental.zod4 flag - Update dependencies: js-yaml, magic-string, magicast to latest versions - Replace kleur with piccolore for CLI colors - Refactor content layer, actions, and config to use unified Zod handling - Simplify JSON schema generation and type generation - Remove z3/z4 branching logic throughout codebase - Update error handling to work with unified Zod implementation BREAKING CHANGE: Zod v3 support removed, project now requires Zod v4+ * Remove Zod v3 support, keep only v4 - Remove all z3 imports and replace with z4/zod - Remove z3-specific functions (formDataToZ3Object, handleZ3FormDataGetAll/Get, unwrapBaseZ3ObjectSchema, createZ3Image) - Remove dual-version type unions, simplify to z4-only types - Remove z3ErrorMap function, keep only z4ErrorMap - Remove checkZodSchemaCompatibility calls (no longer needed) - Simplify vite-plugin-experimental-zod4/utils.ts to no-op - Update package.json to require zod ^4.0.0 - Update test files and exports to reference z4 versions * Finish upgrade * skip these tests for now * skip this one too * correct mark the received item * fix config-validate tests * merge: resolve conflicts between zod4-m and next * fix remaining build error * remove references to zod4 thing * fixes * prevent the crash * switch to the native zod to json schema * oops * fix content layer tests * fix error map tests * fix actions test * fix intellisense tsts * fix schema test * fix: types * Update Svelte to exactly 5.43.8 in package and fixtures * fix svelte tests * fix more e2e * fix cloudflare tests * fix defineMiddleware issue * remove unused reference * fix examples types * pr comment stuff * changeset * remove experiemental flag * add some debugging here * remove debugging stuff * Update packages/astro/src/actions/vite-plugin-actions.ts Co-authored-by: Florian Lefebvre <[email protected]> * fix * fix: import * use zod/v4 imports in core * remove createDefineAction * remove unnecessary type alias * remove unused z4reference * rename stuff * unskip tests * rename back to createImage * nit * revert markdown change * put errorMap name back * address feedback on rss * fix: exports * Update packages/astro-rss/src/index.ts Co-authored-by: Florian Lefebvre <[email protected]> * Update packages/astro-rss/src/schema.ts Co-authored-by: Florian Lefebvre <[email protected]> * Update packages/astro-rss/src/util.ts Co-authored-by: Florian Lefebvre <[email protected]> * Update packages/astro/src/assets/fonts/config.ts Co-authored-by: Florian Lefebvre <[email protected]> * Update packages/astro/src/assets/fonts/types.ts Co-authored-by: Florian Lefebvre <[email protected]> * Update packages/astro/src/content/loaders/types.ts Co-authored-by: Florian Lefebvre <[email protected]> * Update packages/astro/src/content/config.ts Co-authored-by: Florian Lefebvre <[email protected]> * Update packages/astro/src/core/config/schemas/relative.ts Co-authored-by: Florian Lefebvre <[email protected]> * Update packages/astro/test/units/config/config-validate.test.js Co-authored-by: Florian Lefebvre <[email protected]> * Update packages/astro/test/units/actions/form-data-to-object.test.js Co-authored-by: Florian Lefebvre <[email protected]> * Update packages/astro/src/core/config/schemas/refined.ts Co-authored-by: Florian Lefebvre <[email protected]> * Update packages/astro/src/content/content-layer.ts Co-authored-by: Florian Lefebvre <[email protected]> * Update packages/astro/src/content/types-generator.ts Co-authored-by: Florian Lefebvre <[email protected]> * Update packages/astro/src/content/utils.ts Co-authored-by: Florian Lefebvre <[email protected]> * Use $ZodError * Update packages/astro/src/core/csp/config.ts Co-authored-by: Florian Lefebvre <[email protected]> * fix the build * fix e2e test * replace z4 with z * increase vercel test timeout * pr comments * export ImageFunction * use prefault * Validate experimental features special * bring back old locales * fix test * db needs to be a patch too * fix chainability of image * update zod imports * Discard changes to packages/integrations/svelte/package.json * Discard changes to packages/integrations/svelte/test/fixtures/async-rendering/package.json * refresh lockfile * chore: changeset * fix: reference() * skip broken svelte test * Update .changeset/dance-ornate-keen.md Co-authored-by: Sarah Rainsberger <[email protected]> * fix config vlaidate test --------- Co-authored-by: Florian Lefebvre <[email protected]> Co-authored-by: Sarah Rainsberger <[email protected]>
1 parent 941d8f2 commit 0ff51df

70 files changed

Lines changed: 614 additions & 511 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.changeset/busy-humans-smoke.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@astrojs/sitemap': patch
3+
'@astrojs/rss': patch
4+
'@astrojs/db': patch
5+
---
6+
7+
Updates usage of zod to own dependency rather than relying on `astro/zod`

.changeset/dance-ornate-keen.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'astro': major
3+
---
4+
5+
Astro v6.0 upgrades to Zod v4 for schema validation - ([v6 upgrade guidance](https://v6.docs.astro.build/en/guides/upgrade-to/v6/#zod-4))

examples/blog/src/content.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { defineCollection } from 'astro:content';
22
import { glob } from 'astro/loaders';
3-
import { z } from 'astro/zod';
3+
import { z } from 'astro/zod'
44

55
const blog = defineCollection({
66
// Load Markdown and MDX files in the `src/content/blog/` directory.
@@ -13,7 +13,7 @@ const blog = defineCollection({
1313
// Transform string to Date object
1414
pubDate: z.coerce.date(),
1515
updatedDate: z.coerce.date().optional(),
16-
heroImage: image().optional(),
16+
heroImage: z.optional(image()),
1717
}),
1818
});
1919

examples/starlog/src/content.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const releases = defineCollection({
1616
alt: z.string(),
1717
}),
1818
// Transform string to Date object
19-
date: z.date({ coerce: true }),
19+
date: z.coerce.date(),
2020
}),
2121
});
2222

packages/astro-rss/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"@types/xml2js": "^0.4.14",
3131
"astro": "workspace:*",
3232
"astro-scripts": "workspace:*",
33+
"zod": "^3.25.76",
3334
"xml2js": "0.6.2"
3435
},
3536
"dependencies": {

packages/astro-rss/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { z } from 'astro/zod';
1+
import { z } from 'zod/v3';
22
import { XMLBuilder, XMLParser } from 'fast-xml-parser';
33
import colors from 'piccolore';
44
import { rssSchema } from './schema.js';

packages/astro-rss/src/schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { z } from 'astro/zod';
1+
import { z } from 'zod/v3';
22

33
export const rssSchema = z.object({
44
title: z.string().optional(),

packages/astro-rss/src/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { z } from 'astro/zod';
1+
import type { z } from 'zod/v3';
22
import type { RSSOptions } from './index.js';
33

44
/** Normalize URL to its canonical form */

packages/astro/components/Code.astro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import type { ThemePresets } from '@astrojs/markdown-remark';
33
import type { ShikiTransformer, ThemeRegistration, ThemeRegistrationRaw } from 'shiki';
44
import { bundledLanguages } from 'shiki/langs';
55
import { getCachedHighlighter } from '../dist/core/shiki.js';
6-
import type { CodeLanguage } from '../dist/types/public';
7-
import type { HTMLAttributes } from '../types';
6+
import type { CodeLanguage } from '../dist/types/public/common.js';
7+
import type { HTMLAttributes } from '../types.js';
88
99
interface Props extends Omit<HTMLAttributes<'pre'>, 'lang'> {
1010
/** The code to highlight. Required. */

packages/astro/components/Image.astro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
22
import { getImage, imageConfig, type LocalImageProps, type RemoteImageProps } from 'astro:assets';
3-
import type { UnresolvedImageTransform } from '../dist/assets/types';
3+
import type { UnresolvedImageTransform } from '../dist/assets/types.js';
44
import { AstroError, AstroErrorData } from '../dist/core/errors/index.js';
5-
import type { HTMLAttributes } from '../types';
5+
import type { HTMLAttributes } from '../types.js';
66
77
// The TypeScript diagnostic for JSX props uses the last member of the union to suggest props, so it would be better for
88
// LocalImageProps to be last. Unfortunately, when we do this the error messages that remote images get are complete nonsense

0 commit comments

Comments
 (0)