Skip to content

Commit 76db01d

Browse files
authored
fix(config): update validation for omitted integrations fields with newer Zod versions (#16531)
1 parent 3af3543 commit 76db01d

2 files changed

Lines changed: 19 additions & 13 deletions

File tree

.changeset/soft-ducks-validate.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'astro': patch
3+
---
4+
5+
Fixes config validation for omitted `integrations` fields with newer Zod versions.

packages/astro/src/core/config/schemas/base.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
import type { OutgoingHttpHeaders } from 'node:http';
21
import type {
32
RehypePlugin as _RehypePlugin,
43
RemarkPlugin as _RemarkPlugin,
54
RemarkRehype as _RemarkRehype,
6-
ShikiConfig,
75
Smartypants as _Smartypants,
6+
ShikiConfig,
87
} from '@astrojs/markdown-remark';
98
import { markdownConfigDefaults, syntaxHighlightDefaults } from '@astrojs/markdown-remark';
9+
import type { OutgoingHttpHeaders } from 'node:http';
1010
import { type BuiltinTheme, bundledThemes } from 'shiki';
1111
import * as z from 'zod/v4';
1212
import { FontFamilySchema } from '../../../assets/fonts/config.js';
13+
import { SvgOptimizerSchema } from '../../../assets/svg/config.js';
1314
import { EnvSchema } from '../../../env/schema.js';
1415
import type { AstroUserConfig, ViteUserConfig } from '../../../types/public/config.js';
15-
import { allowedDirectivesSchema, cspAlgorithmSchema, cspHashSchema } from '../../csp/config.js';
1616
import { CacheSchema, RouteRulesSchema } from '../../cache/config.js';
17+
import { allowedDirectivesSchema, cspAlgorithmSchema, cspHashSchema } from '../../csp/config.js';
1718
import { SessionSchema } from '../../session/config.js';
18-
import { SvgOptimizerSchema } from '../../../assets/svg/config.js';
1919

2020
// The below types are required boilerplate to work around a Zod issue since v3.21.2. Since that version,
2121
// Zod's compiled TypeScript would "simplify" certain values to their base representation, causing references
@@ -193,15 +193,16 @@ export const AstroConfigSchema = z.object({
193193
.union([z.literal('where'), z.literal('class'), z.literal('attribute')])
194194
.optional()
195195
.default('attribute'),
196-
adapter: z.object({ name: z.string(), hooks: z.object({}).passthrough().default({}) }).optional(),
197-
integrations: z.preprocess(
198-
// preprocess
199-
(val) => (Array.isArray(val) ? val.flat(Number.POSITIVE_INFINITY).filter(Boolean) : val),
200-
// validate
201-
z
202-
.array(z.object({ name: z.string(), hooks: z.object({}).passthrough().default({}) }))
203-
.default(ASTRO_CONFIG_DEFAULTS.integrations),
204-
),
196+
adapter: z.object({ name: z.string(), hooks: z.object({}).loose().default({}) }).optional(),
197+
integrations: z
198+
.preprocess(
199+
// preprocess
200+
(val) => (Array.isArray(val) ? val.flat(Number.POSITIVE_INFINITY).filter(Boolean) : val),
201+
// validate
202+
z.array(z.object({ name: z.string(), hooks: z.object({}).loose().default({}) })),
203+
)
204+
.optional()
205+
.default(ASTRO_CONFIG_DEFAULTS.integrations),
205206
build: z
206207
.object({
207208
format: z

0 commit comments

Comments
 (0)