Skip to content

refactor(cli): migrate from zod to zod/mini#847

Merged
binoy14 merged 1 commit intomainfrom
refactor/zod-mini
Mar 31, 2026
Merged

refactor(cli): migrate from zod to zod/mini#847
binoy14 merged 1 commit intomainfrom
refactor/zod-mini

Conversation

@binoy14
Copy link
Copy Markdown
Contributor

@binoy14 binoy14 commented Mar 30, 2026

Summary

  • Migrates all zod imports to zod/mini across @sanity/cli and @sanity/cli-core for ~10KB smaller bundle size
  • Converts .optional() method chaining to z.optional() wrapper, .email() to z.email(), and z.ZodError to z.core.$ZodError per the zod/mini API
  • Adds no-restricted-imports ESLint rule to prevent future imports from zod instead of zod/mini

Test plan

  • All existing tests pass (21/21 across modified modules)
  • TypeScript type checking passes for both packages
  • Lint-staged hooks pass on commit
  • Verify bundle size reduction in CI

🤖 Generated with Claude Code

@claude
Copy link
Copy Markdown

claude Bot commented Mar 30, 2026

Claude finished @binoy14's task in 1m 23s —— View job


Review

No issues found. The migration is correct:

  • All zod imports replaced with zod/mini across all 11 files
  • .optional() chain → z.optional() wrapper, .email()z.email(), z.ZodErrorz.core.$ZodError, z.ZodTypez.core.$ZodType — all per the zod/mini API
  • The ErrorTypeError change in readStudioConfig.ts:89 is consistent with how similar errors are thrown elsewhere in the codebase (getStudioWorkspaces.ts:41, getGraphQLAPIs.worker.ts:39)
  • CI confirms the expected bundle size reduction (~120KB raw / ~20.5KB gzip off @sanity/cli)
  • No remaining from 'zod' imports in the codebase
  • ESLint guard added to prevent future direct zod imports

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 30, 2026

📦 Bundle Stats — @sanity/cli

Compared against main (fe45fbe6) · v6.3.1 (npm)

@sanity/cli

Metric Value vs main (fe45fbe) vs v6.3.1
Internal (raw) 2.1 KB - -
Internal (gzip) 799 B - -
Bundled (raw) 10.95 MB -120.3 KB, -1.1% +9.01 MB, +464.9%
Bundled (gzip) 2.06 MB -20.4 KB, -1.0% +1.58 MB, +331.9%
Import time 841ms -6ms, -0.8% +26ms, +3.2%

bin:sanity

Metric Value vs main (fe45fbe) vs v6.3.1
Internal (raw) 975 B - -
Internal (gzip) 460 B - -
Bundled (raw) 9.84 MB - +9.13 MB, +1287.6%
Bundled (gzip) 1.77 MB - +1.60 MB, +940.8%
Import time 1.99s -3ms, -0.2% +1.08s, +118.6% ⚠️

🗺️ View treemap · Artifacts

Details
  • Import time regressions over 10% are flagged with ⚠️
  • Sizes shown as raw / gzip 🗜️. Internal bytes = own code only. Total bytes = with all dependencies. Import time = Node.js cold-start median.

📦 Bundle Stats — @sanity/cli-core

Compared against main (fe45fbe6) · v1.3.0 (npm)

Metric Value vs main (fe45fbe) vs v1.3.0
Internal (raw) 92.3 KB +93 B, +0.1% +93 B, +0.1%
Internal (gzip) 21.6 KB +28 B, +0.1% +28 B, +0.1%
Bundled (raw) 21.53 MB -118.6 KB, -0.5% +9.02 MB, +72.0%
Bundled (gzip) 3.41 MB -20.5 KB, -0.6% +1.58 MB, +85.9%
Import time 795ms -5ms, -0.7% +51ms, +6.9%

🗺️ View treemap · Artifacts

Details
  • Import time regressions over 10% are flagged with ⚠️
  • Sizes shown as raw / gzip 🗜️. Internal bytes = own code only. Total bytes = with all dependencies. Import time = Node.js cold-start median.

@github-actions
Copy link
Copy Markdown
Contributor

Coverage Delta

File Statements
packages/@sanity/cli-core/src/config/cli/schemas.ts 100.0% (±0%)
packages/@sanity/cli-core/src/config/studio/readStudioConfig.ts 71.4% (±0%)
packages/@sanity/cli-core/src/config/studio/readStudioConfig.worker.ts 0.0% (±0%)
packages/@sanity/cli-core/src/services/cliUserConfig.ts 100.0% (±0%)
packages/@sanity/cli-core/src/util/readPackageJson.ts 100.0% (±0%)
packages/@sanity/cli/src/actions/deploy/types.ts 0.0% (±0%)
packages/@sanity/cli/src/actions/manifest/types.ts 100.0% (±0%)
packages/@sanity/cli/src/actions/schema/types.ts 0.0% (±0%)
packages/@sanity/cli/src/actions/users/validateEmail.ts 100.0% (±0%)

Comparing 9 changed files against main @ 6c351ae1c4a5c433fce73b287d18c40f2a22a3bc

Overall Coverage

Metric Coverage
Statements 83.1% (±0%)
Branches 72.9% (±0%)
Functions 83.3% (±0%)
Lines 83.5% (±0%)

Zod 4's zod/mini variant provides the same validation with ~10KB less
bundle weight by dropping method chaining in favor of wrapper functions.
Also adds an ESLint no-restricted-imports rule to prevent future imports
from 'zod' instead of 'zod/mini'.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@binoy14 binoy14 force-pushed the refactor/zod-mini branch from 4efe43b to 0d7584e Compare March 31, 2026 18:51
@github-actions
Copy link
Copy Markdown
Contributor

Coverage Delta

File Statements
packages/@sanity/cli-core/src/config/cli/schemas.ts 100.0% (±0%)
packages/@sanity/cli-core/src/config/studio/readStudioConfig.ts 71.4% (±0%)
packages/@sanity/cli-core/src/config/studio/readStudioConfig.worker.ts 0.0% (±0%)
packages/@sanity/cli-core/src/services/cliUserConfig.ts 100.0% (±0%)
packages/@sanity/cli-core/src/util/readPackageJson.ts 100.0% (±0%)
packages/@sanity/cli/src/actions/deploy/types.ts 0.0% (±0%)
packages/@sanity/cli/src/actions/manifest/types.ts 100.0% (±0%)
packages/@sanity/cli/src/actions/schema/types.ts 0.0% (±0%)
packages/@sanity/cli/src/actions/users/validateEmail.ts 100.0% (±0%)

Comparing 9 changed files against main @ fe45fbe6fee51ae576f1f1549153c3124c66236a

Overall Coverage

Metric Coverage
Statements 83.1% (±0%)
Branches 72.9% (±0%)
Functions 83.3% (±0%)
Lines 83.5% (±0%)

@binoy14 binoy14 marked this pull request as ready for review March 31, 2026 19:03
@binoy14 binoy14 requested a review from a team as a code owner March 31, 2026 19:03
@binoy14 binoy14 requested review from mttdnt, rexxars and somerandomdude and removed request for a team March 31, 2026 19:03
@binoy14 binoy14 merged commit 7c70b4c into main Mar 31, 2026
44 checks passed
@binoy14 binoy14 deleted the refactor/zod-mini branch March 31, 2026 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants