Skip to content

feat: graceful multiple imports exit + transform and refine #1273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

paoloricciuti
Copy link
Contributor

Some other small codemod fixes: this fixes transform, refine and adds a comment to explain why it's not possible to migrate the file when there's multiple zod imports (i also think we could try to be a bit smarter here and still migrate if at least one import is z from zod but that would lead to squiggles in the file unless we also replace all the zod types)

@Copilot Copilot AI review requested due to automatic review settings August 8, 2025 12:43
Copy link

vercel bot commented Aug 8, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
valibot ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 8, 2025 0:46am

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement New feature or request labels Aug 8, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for transforming Zod's refine and transform methods to their Valibot equivalents and improves error handling for multiple import scenarios. The changes enhance the codemod to handle more Zod patterns while providing better feedback when transformation fails.

  • Adds transformation support for refine (to Valibot's check) and transform methods
  • Improves error handling by adding descriptive comments when imports cannot be transformed
  • Includes comprehensive test coverage for the new functionality

Reviewed Changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
schemas-and-links.ts Registers refine and transform method transformers
transform/transform.ts Implements Zod transform to Valibot transform conversion
refine/refine.ts Implements Zod refine to Valibot check conversion with message extraction
index.ts Adds error comment injection for unsuccessful import transformations
imports.ts Adds cause field to error return types for better error reporting
constants.ts Adds refine and transform to supported Zod methods list
test files Adds test fixtures for new functionality and multiple import scenarios

return arg.properties[0].value;
}
return arg;
}) as typeof args;
Copy link
Preview

Copilot AI Aug 8, 2025

Choose a reason for hiding this comment

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

The type assertion as typeof args is potentially unsafe. Consider using a type guard or proper type narrowing to ensure type safety when transforming arguments.

Suggested change
}) as typeof args;
});

Copilot uses AI. Check for mistakes.

Comment on lines +11 to +19
// If the argument is an object with { message: "..." }, extract the message
if (
arg.type === 'ObjectExpression' &&
arg.properties.length === 1 &&
arg.properties[0].type === 'ObjectProperty' &&
arg.properties[0].key.type === 'Identifier' &&
arg.properties[0].key.name === 'message'
) {
return arg.properties[0].value;
Copy link
Preview

Copilot AI Aug 8, 2025

Choose a reason for hiding this comment

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

The nested conditional checks for object structure are complex and brittle. Consider extracting this logic into a separate helper function with proper type guards for better maintainability and testing.

Suggested change
// If the argument is an object with { message: "..." }, extract the message
if (
arg.type === 'ObjectExpression' &&
arg.properties.length === 1 &&
arg.properties[0].type === 'ObjectProperty' &&
arg.properties[0].key.type === 'Identifier' &&
arg.properties[0].key.name === 'message'
) {
return arg.properties[0].value;
if (isMessageObjectExpression(arg)) {
// If the argument is an object with { message: "..." }, extract the message
// TypeScript type narrowing ensures arg is ObjectExpression here
return (arg.properties[0] as j.ObjectProperty).value;

Copilot uses AI. Check for mistakes.

@paoloricciuti paoloricciuti changed the title feat: graceful multiple imports exit feat: graceful multiple imports exit + transform and refine Aug 8, 2025
Copy link

pkg-pr-new bot commented Aug 10, 2025

Open in StackBlitz

npm i https://pkg.pr.new/valibot@1273

commit: 9be3593

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant