Skip to content

refactor: upgrade Zod to v4#264

Open
314systems wants to merge 1 commit into
pnpm:masterfrom
314systems:zod
Open

refactor: upgrade Zod to v4#264
314systems wants to merge 1 commit into
pnpm:masterfrom
314systems:zod

Conversation

@314systems
Copy link
Copy Markdown

@314systems 314systems commented Jun 1, 2026

Overview

Upgraded Zod from v3 to v4 and refactored run-install.ts to utilize the new APIs for cleaner flow and better error formatting.

Changes

  • Dependency Upgrade: Bumped zod to ^4.4.3.
  • Flow Refactoring: Replaced try/catch block containing .parse() with .safeParse() in parseRunInstall for more idiomatic TypeScript validation.
  • Log Formatting Improvement: Fixed a bug where validation errors printed as [object Object] in the logs by adopting Zod v4's new z.prettifyError() function.
  • Code Cleanup: Removed the unused named import ZodError and the internal RunInstallInput type.

Verification

  • Verified that type-checking (tsc --noEmit) passes successfully.
  • Ran pnpm run build to ensure the bundle builds without issues.

Summary by CodeRabbit

  • Dependencies

    • Updated zod to version 4.4.3.
  • Improvements

    • Enhanced validation error reporting with improved formatting and comprehensive error diagnostics on failures.

Signed-off-by: Akihiro Nagai <77012577+314systems@users.noreply.github.com>
@314systems 314systems requested a review from zkochan as a code owner June 1, 2026 01:08
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 1, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d88386f4-e28f-494b-8eaf-a4282e8ebe59

📥 Commits

Reviewing files that changed from the base of the PR and between 0e279bb and 24d83a9.

⛔ Files ignored due to path filters (2)
  • dist/index.js is excluded by !**/dist/**
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (2)
  • package.json
  • src/inputs/run-install.ts
📜 Recent review details
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2026-05-11T12:04:07.383Z
Learnt from: zkochan
Repo: pnpm/action-setup PR: 256
File: src/install-pnpm/run.ts:150-166
Timestamp: 2026-05-11T12:04:07.383Z
Learning: In pnpm/action-setup, when validating or forwarding the version value used for `pnpm self-update` and/or `devEngines.packageManager.version`, do not restrict it to exact versions or tags only—pnpm supports semver ranges for these inputs. Ensure any code that parses/validates `devEngines.packageManager.version` (and the value passed to `pnpm self-update`) allows range syntax such as `^`, `~`, and comparators (e.g. `>=8 <10`) instead of rejecting anything that isn’t a single exact version. Note: the plain `packageManager` field is different, so apply this “allow semver ranges” rule specifically to `devEngines.packageManager.version` / `self-update` handling.

Applied to files:

  • src/inputs/run-install.ts
🔇 Additional comments (4)
package.json (1)

18-18: LGTM!

src/inputs/run-install.ts (3)

3-3: LGTM!


18-18: LGTM!


27-27: Resolve: z.prettifyError() is a documented Zod v4 API — Zod v4’s error-formatting docs describe z.prettifyError(error) for converting a ZodError into a readable string, so the original concern about a missing API causing a runtime TypeError doesn’t apply.


📝 Walkthrough

Walkthrough

This PR upgrades the Zod validation library from v3 to v4 and refactors src/inputs/run-install.ts to use Zod v4's API conventions: namespace imports, safeParse with success branching, and type inference via z.infer.

Changes

Zod v4 Upgrade and Code Migration

Layer / File(s) Summary
Zod v4 Dependency Update
package.json
Zod dependency is updated from ^3.22.4 to ^4.4.3.
Zod v4 API Migration in run-install.ts
src/inputs/run-install.ts
Import statement switches to namespace import (* as z); RunInstall type is now exported via z.infer<typeof RunInstallSchema>; parseRunInstall replaces parse() with safeParse and checks result.success, using z.prettifyError() for validation failures and normalizing parsed data to RunInstall[] with handling for null, boolean true, arrays, and single objects.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🐰 From v3 bounds to v4 shores, namespace imports we adore,
safeParse shields where errors once roared, prettified and stored,
Type inference shines through infer's bright light,
Zod's newest embrace makes validation just right!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'refactor: upgrade Zod to v4' directly and clearly summarizes the main change—upgrading the Zod dependency from v3 to v4 and refactoring code to use Zod v4 APIs.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@qodo-free-for-open-source-projects
Copy link
Copy Markdown

Review Summary by Qodo

Upgrade Zod to v4 with validation refactoring

✨ Enhancement

Grey Divider

Walkthroughs

Description
• Upgraded Zod dependency from v3 to v4 for improved validation APIs
• Refactored validation logic to use safeParse() instead of try/catch
• Fixed validation error formatting using Zod v4's prettifyError() function
• Removed unused ZodError import and RunInstallInput type definition
Diagram
flowchart LR
  A["Zod v3.24.1"] -- "upgrade" --> B["Zod v4.4.3"]
  C["try/catch + parse()"] -- "refactor" --> D["safeParse()"]
  E["Error formatting bug"] -- "fix" --> F["prettifyError()"]
  G["Unused imports/types"] -- "cleanup" --> H["Removed"]

Loading

Grey Divider

File Changes

1. package.json Dependencies +1/-1

Update Zod dependency version

• Updated zod dependency from ^3.22.4 to ^4.4.3

package.json


2. pnpm-lock.yaml Dependencies +6/-5

Lock file updates for Zod v4

• Updated zod package resolution from 3.24.1 to 4.4.3
• Added deprecation notice for uuid@8.3.2

pnpm-lock.yaml


3. src/inputs/run-install.ts ✨ Enhancement +10/-15

Refactor validation to use Zod v4 APIs

• Changed import from named imports to namespace import (import * as z from 'zod')
• Replaced try/catch block with safeParse() for cleaner validation flow
• Implemented z.prettifyError() for proper error message formatting
• Removed unused ZodError import and RunInstallInput type export
• Refactored result handling to use destructured data property

src/inputs/run-install.ts


View more (1)
4. dist/index.js Miscellaneous +229/-165

Compiled distribution bundle update

• Compiled output reflecting the source code changes in run-install.ts

dist/index.js


Grey Divider

Qodo Logo

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.

1 participant