Skip to content

Detaching Zod plugin#2869

Merged
RobinTail merged 84 commits intomasterfrom
detach-plugin
Aug 7, 2025
Merged

Detaching Zod plugin#2869
RobinTail merged 84 commits intomasterfrom
detach-plugin

Conversation

@RobinTail
Copy link
Copy Markdown
Owner

@RobinTail RobinTail commented Aug 2, 2025

This should enable developing and distributing the Zod plugin separately. The framework will depend on it, but the plugin features could be reused in other projects, such as zod-sockets. The helper method getBrand() is moving to the plugin. Proprietary schema remain within the framework.

Summary by CodeRabbit

  • New Features

    • Introduced @express-zod-api/zod-plugin as a standalone package enhancing Zod schemas with new methods and runtime helpers.
    • Enabled selection and publishing of the zod-plugin workspace in project workflows.
  • Bug Fixes

    • Improved symbol usage for storing logger instances in Express response locals to avoid conflicts.
  • Documentation

    • Added detailed documentation for the Zod plugin with usage examples.
    • Simplified the main README's description of Zod schema extensions.
  • Chores

    • Updated workspace and package configurations to support the new plugin and manage dependencies.
    • Enhanced build and test configurations for the new package and improved treeshaking.
  • Tests

    • Added and updated tests verifying Zod plugin schema extensions and API consistency.
    • Adjusted test imports and removed outdated prototype extension tests.
  • Refactor

    • Migrated imports to use the new external Zod plugin package throughout the codebase.
    • Improved build configuration for better TypeScript declaration generation and treeshaking.

@RobinTail RobinTail added enhancement New feature or request refactoring The better way to achieve the same result miracle Mysterious events are happening here labels Aug 2, 2025
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Aug 2, 2025

Walkthrough

A new zod-plugin package is introduced, extending Zod schemas with additional methods and runtime helpers. The main package is updated to use this external plugin, updating imports, dependencies, and build/test configurations. Workflow and workspace files are amended to recognize and manage the new package. Minor symbol and metadata handling adjustments are made for logger storage.

Changes

Cohort / File(s) Change Summary
GitHub Workflow Updates
.github/workflows/bump.yml, .github/workflows/npm-publish.yml
Added "zod-plugin" as a selectable workspace option in workflow inputs for version bumping and npm publishing. Modified checkout step to fetch full git history for versioning.
Workspace & Dependency Management
pnpm-workspace.yaml, express-zod-api/package.json
Added zod-plugin to the workspace, introduced dependency catalogs, patched dependencies, and updated dependencies to use workspace and catalog references.
New zod-plugin Package
zod-plugin/*
Introduced a new package with augmentation logic, helpers, remap utilities, configuration files, tests, and documentation. Provides new Zod schema extensions and runtime helpers.
Express Zod API: Plugin Integration
express-zod-api/src/index.ts, express-zod-api/src/deep-checks.ts, express-zod-api/src/documentation-helpers.ts, express-zod-api/src/endpoint.ts, express-zod-api/src/schema-walker.ts, express-zod-api/vitest.setup.ts, express-zod-api/tests/*.spec.ts
Changed imports of Zod augmentation and helpers from local modules to the new external @express-zod-api/zod-plugin package. Updated tests and setup accordingly.
Logger Symbol Refactoring
express-zod-api/src/server-helpers.ts, express-zod-api/tests/server-helpers.spec.ts, zod-plugin/augmentation.ts, zod-plugin/helpers.ts
Replaced use of metaSymbol with a symbol derived from the package name (localsID) for logger storage and plugin presence checks. Adjusted related tests and removed metaSymbol export.
Build & Lint Configuration
eslint.config.js, express-zod-api/tsup.config.ts, zod-plugin/tsup.config.ts, patches/tsup.patch
Updated ESLint ignores and test globs for the new package, added a workaround for preserving plugin side effects in DTS files, and patched tsup/rollup treeshaking behavior.
Documentation Updates
README.md, zod-plugin/README.md
Simplified main README's Zod plugin section and added detailed documentation for the new plugin.
Other Test & Config Additions
zod-plugin/vitest.config.ts, zod-plugin/vitest.setup.ts, zod-plugin/tsconfig.json
Added test and TypeScript configuration files for the new plugin package.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ExpressZodAPI
    participant ZodPlugin

    User->>ExpressZodAPI: Uses Zod schema with .example(), .deprecated(), etc.
    ExpressZodAPI->>ZodPlugin: Imports and applies Zod augmentations (side effects)
    ExpressZodAPI->>ZodPlugin: Calls getBrand() for runtime brand retrieval
    ExpressZodAPI->>ExpressZodAPI: Uses extended Zod schemas in API logic
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • Detaching migration #2736: Adds "zod-plugin" as a workspace option in GitHub Actions workflows, similar to this PR's workflow updates for managing multiple workspaces.
  • v25 is for Sara Millerey González #2741: Extensive migration from "zod/v4" imports to "zod" imports and updating internal Zod core type imports, related due to overlapping import and modularization changes.
  • v24 is for Ashley Burton #2546: Major Zod v4 integration and branding refactor; conceptually related due to modularizing branding and plugin imports consistent with the new zod-plugin package.

Suggested labels

refactoring

Poem

A plugin hops in, with Zod in its stride,
New helpers and brands, all bundled inside.
Workflows now spot it, configs align,
Logger’s new symbol—how clever, how fine!
With tests and docs tidy, this patch is complete—
A rabbit’s new toolkit, both nimble and neat! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7309004 and 099e411.

📒 Files selected for processing (1)
  • express-zod-api/package.json (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • express-zod-api/package.json
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch detach-plugin

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@RobinTail
Copy link
Copy Markdown
Owner Author

RobinTail commented Aug 3, 2025

not clear what to do with proprietary branded schemas yet...

perhaps getBrand() and those branded types should go into the plugin too.

@RobinTail
Copy link
Copy Markdown
Owner Author

need to rethink/clarify the strategy

@RobinTail RobinTail closed this Aug 3, 2025
@RobinTail
Copy link
Copy Markdown
Owner Author

RobinTail commented Aug 4, 2025

The strategy:

  • the plugin should be a required production (regular) dependency of the framework
    • thus, all the usage of its method would remain intact
    • getBrand() should be moved to the plugin
    • getExamples() could be implemented there as well for simplicity
  • detaching the plugin would allow using its features, such as runtime brands in other projects, like zod-sockets
  • proprietary types should be kept in the framework for a while
    • they can be extracted later to another small package, also to make them reusable, such as buffer-schema and date-in/out one.

@RobinTail RobinTail reopened this Aug 4, 2025
@RobinTail RobinTail removed the refactoring The better way to achieve the same result label Aug 5, 2025
@RobinTail
Copy link
Copy Markdown
Owner Author

RobinTail commented Aug 6, 2025

time to publish the EZ and QA it having the plugin separated

❌ Failed to publish: must prebuild the plugin, because we run the local workspace tests

Error: src/deep-checks.ts(9,26): error TS2307: Cannot find module '@express-zod-api/zod-plugin' or its corresponding type declarations.

@RobinTail
Copy link
Copy Markdown
Owner Author

RobinTail commented Aug 7, 2025

✅ published
✅ the plugin reference substitution worked fine
✅ the import is present both in JS and DTS
✅ the framework operation retained

✅ QA passed

Copy link
Copy Markdown
Owner Author

@RobinTail RobinTail left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏁 Ready

@RobinTail RobinTail merged commit d627274 into master Aug 7, 2025
5 checks passed
@RobinTail RobinTail deleted the detach-plugin branch August 7, 2025 19:49
@coderabbitai coderabbitai Bot mentioned this pull request Aug 7, 2025
RobinTail added a commit that referenced this pull request Aug 7, 2025
Following #2869 


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **New Features**
* Enhanced Zod schemas with new utility methods: `example`,
`deprecated`, and `label` for improved metadata handling.
  * Introduced a `brand` property for custom schema branding.
* Added a `remap` method to object schemas for flexible key
transformation.

* **Refactor**
* Reorganized and separated runtime augmentation logic to improve
maintainability and clarity.

* **Tests**
  * Updated test descriptions for clarity; test logic remains unchanged.

* **Chores**
  * Updated internal setup to use the new runtime augmentation module.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
@coderabbitai coderabbitai Bot mentioned this pull request Aug 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI/CD dependencies Pull requests that update a dependency file documentation Improvements or additions to documentation enhancement New feature or request miracle Mysterious events are happening here patched Some dependency is patched

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant