diff --git a/.changeset/perfect-wasps-grow.md b/.changeset/perfect-wasps-grow.md new file mode 100644 index 000000000000..855c709837b2 --- /dev/null +++ b/.changeset/perfect-wasps-grow.md @@ -0,0 +1,17 @@ +--- +'astro': minor +--- + +Exposes `z` from the new `astro:schema` module. This is the new recommended import source for all Zod utilities when using Astro Actions. + +## Migration for Astro Actions users + +`z` will no longer be exposed from `astro:actions`. To use `z` in your actions, import it from `astro:schema` instead: + +```diff +import { + defineAction, +- z, +} from 'astro:actions'; ++ import { z } from 'astro:schema'; +``` diff --git a/packages/astro/client.d.ts b/packages/astro/client.d.ts index ed5c1b894d28..2427a0a46a3e 100644 --- a/packages/astro/client.d.ts +++ b/packages/astro/client.d.ts @@ -172,6 +172,10 @@ declare module 'astro:components' { export * from 'astro/components'; } +declare module 'astro:schema' { + export * from 'astro/zod'; +} + type MD = import('./dist/@types/astro.js').MarkdownInstance>; interface ExportedMarkdownModuleEntities { frontmatter: MD['frontmatter']; diff --git a/packages/astro/e2e/fixtures/actions-blog/src/actions/index.ts b/packages/astro/e2e/fixtures/actions-blog/src/actions/index.ts index 7b640be51686..43ffb43d42d4 100644 --- a/packages/astro/e2e/fixtures/actions-blog/src/actions/index.ts +++ b/packages/astro/e2e/fixtures/actions-blog/src/actions/index.ts @@ -1,5 +1,6 @@ import { db, Comment, Likes, eq, sql } from 'astro:db'; -import { ActionError, defineAction, z } from 'astro:actions'; +import { ActionError, defineAction } from 'astro:actions'; +import { z } from 'astro:schema'; import { getCollection } from 'astro:content'; export const server = { diff --git a/packages/astro/e2e/fixtures/actions-react-19/src/actions/index.ts b/packages/astro/e2e/fixtures/actions-react-19/src/actions/index.ts index cd42207729cf..754db0171edc 100644 --- a/packages/astro/e2e/fixtures/actions-react-19/src/actions/index.ts +++ b/packages/astro/e2e/fixtures/actions-react-19/src/actions/index.ts @@ -1,5 +1,6 @@ import { db, Likes, eq, sql } from 'astro:db'; -import { defineAction, z, type SafeResult } from 'astro:actions'; +import { defineAction, type SafeResult } from 'astro:actions'; +import { z } from 'astro:schema'; import { experimental_getActionState } from '@astrojs/react/actions'; export const server = { diff --git a/packages/astro/playwright.config.js b/packages/astro/playwright.config.js index 26572c66c872..d9ea2c46916e 100644 --- a/packages/astro/playwright.config.js +++ b/packages/astro/playwright.config.js @@ -7,7 +7,10 @@ process.stdout.isTTY = false; export default defineConfig({ testMatch: 'e2e/*.test.js', - timeout: 40000, + timeout: 40_000, + expect: { + timeout: 6_000, + }, forbidOnly: !!process.env.CI, retries: process.env.CI ? 2 : 0, workers: process.env.CI ? 1 : undefined, diff --git a/packages/astro/playwright.firefox.config.js b/packages/astro/playwright.firefox.config.js index 00b82d999786..140f288f9e23 100644 --- a/packages/astro/playwright.firefox.config.js +++ b/packages/astro/playwright.firefox.config.js @@ -8,7 +8,10 @@ process.stdout.isTTY = false; export default defineConfig({ // TODO: add more tests like view transitions and audits, and fix them. Some of them are failing. testMatch: ['e2e/css.test.js', 'e2e/prefetch.test.js', 'e2e/view-transitions.test.js'], - timeout: 40000, + timeout: 40_000, + expect: { + timeout: 6_000, + }, forbidOnly: !!process.env.CI, retries: process.env.CI ? 2 : 0, workers: process.env.CI ? 1 : undefined, diff --git a/packages/astro/src/actions/runtime/virtual/client.ts b/packages/astro/src/actions/runtime/virtual/client.ts index 424552a9fe06..c80e6778ae7b 100644 --- a/packages/astro/src/actions/runtime/virtual/client.ts +++ b/packages/astro/src/actions/runtime/virtual/client.ts @@ -3,12 +3,3 @@ export * from './shared.js'; export function defineAction() { throw new Error('[astro:action] `defineAction()` unexpectedly used on the client.'); } - -export const z = new Proxy( - {}, - { - get() { - throw new Error('[astro:action] `z` unexpectedly used on the client.'); - }, - }, -); diff --git a/packages/astro/src/actions/runtime/virtual/server.ts b/packages/astro/src/actions/runtime/virtual/server.ts index fcb0dc6030dd..cd1b4269ed38 100644 --- a/packages/astro/src/actions/runtime/virtual/server.ts +++ b/packages/astro/src/actions/runtime/virtual/server.ts @@ -6,8 +6,6 @@ import { ActionError, ActionInputError, type SafeResult, callSafely } from './sh export * from './shared.js'; -export { z } from 'zod'; - export type ActionAccept = 'form' | 'json'; export type ActionHandler = TInputSchema extends z.ZodType diff --git a/packages/astro/src/core/create-vite.ts b/packages/astro/src/core/create-vite.ts index 93bf266dc99b..28ce9810aab3 100644 --- a/packages/astro/src/core/create-vite.ts +++ b/packages/astro/src/core/create-vite.ts @@ -194,6 +194,10 @@ export async function createVite( find: 'astro:middleware', replacement: 'astro/virtual-modules/middleware.js', }, + { + find: 'astro:schema', + replacement: 'astro/zod', + }, { find: 'astro:components', replacement: 'astro/components', diff --git a/packages/astro/test/fixtures/actions/src/actions/index.ts b/packages/astro/test/fixtures/actions/src/actions/index.ts index 881656994f22..ed7692799353 100644 --- a/packages/astro/test/fixtures/actions/src/actions/index.ts +++ b/packages/astro/test/fixtures/actions/src/actions/index.ts @@ -1,4 +1,5 @@ -import { defineAction, ActionError, z } from 'astro:actions'; +import { defineAction, ActionError } from 'astro:actions'; +import { z } from 'astro:schema'; const passwordSchema = z .string()