Skip to content

fix(cli): enhancer code fails to compile when generated into a custom folder #1678

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

Merged
merged 2 commits into from
Sep 2, 2024

Conversation

ymc9
Copy link
Member

@ymc9 ymc9 commented Sep 1, 2024

Fixes #1667

… folder

Fixes #1667
Copy link
Contributor

coderabbitai bot commented Sep 1, 2024

Walkthrough

Walkthrough

The changes introduce new functionality for handling Zod imports and custom output folders in the schema enhancement process. A private method, getZodImport, is added to determine the appropriate import path for Zod based on custom output options. Additionally, a new function retrieves custom output folders for plugins, and an optional property is added to schema loading options to allow for code generation without compilation. Regression tests are included to validate these enhancements.

Changes

Files Change Summary
packages/schema/src/plugins/enhancer/enhance/index.ts Added a private method getZodImport to determine Zod import paths based on custom output options; modified Zod schemas import statement accordingly.
packages/schema/src/plugins/plugin-utils.ts Introduced getPluginCustomOutputFolder function to retrieve custom output folders for plugins based on model and provider. Updated import statements.
packages/testtools/src/schema.ts Added optional property generateNoCompile to SchemaLoadOptions type; updated loading functions to handle this new option.
tests/regression/tests/issue-1667.test.ts Created regression tests for issue 1667 to validate Zod output enhancements through custom plugins in a Prisma schema.
tests/integration/tests/plugins/zod.test.ts Enhanced Zod plugin test suite with new plugin configurations and updated function parameters for improved testing accuracy and performance.

Assessment against linked issues

Objective Addressed Explanation
Cannot find module './zod' or its corresponding type declarations (1667)
Adding plugin @core/enhancer breaks validation checks for @core/zod plugin (1562) The changes do not explicitly address the validation issue caused by the enhancer plugin. Further testing may be required to confirm behavior.

Possibly related issues


Tip

Early access features: disabled

We are currently testing the following features in early access:

  • Anthropic claude-3-5-sonnet for code reviews: The new Claude model has stronger code understanding and code generation capabilities than the previous models. We're excited to hear your feedback as we evaluate its performance over the next few days.

Note:

  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.
  • Please join our Discord Community to provide feedback and report issues on the discussion post.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • 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 generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

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 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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Outside diff range, codebase verification and nitpick comments (1)
packages/schema/src/plugins/plugin-utils.ts (1)

122-132: LGTM! Consider adding JSDoc comments.

The code changes are approved. The getPluginCustomOutputFolder function is well-structured and follows the Single Responsibility Principle. It uses appropriate type guards and checks to ensure the correctness of the returned value.

To improve the maintainability and readability of the code, consider adding JSDoc comments to document the function's purpose, parameters, and return value. Here's an example:

/**
 * Retrieves the custom output folder for a specified plugin based on its model and provider.
 * @param zmodel - The model to search for the plugin.
 * @param provider - The provider string of the plugin.
 * @returns The custom output folder if found, otherwise `undefined`.
 */
export function getPluginCustomOutputFolder(zmodel: Model, provider: string) {
  // ...
}
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2275102 and 0636d63.

Files selected for processing (4)
  • packages/schema/src/plugins/enhancer/enhance/index.ts (3 hunks)
  • packages/schema/src/plugins/plugin-utils.ts (2 hunks)
  • packages/testtools/src/schema.ts (3 hunks)
  • tests/regression/tests/issue-1667.test.ts (1 hunks)
Additional context used
GitHub Check: CodeQL
packages/testtools/src/schema.ts

[warning] 237-237: Unsafe shell command constructed from library input
This string concatenation which depends on library input is later used in a shell command.
This string concatenation which depends on library input is later used in a shell command.
This string concatenation which depends on library input is later used in a shell command.
This string concatenation which depends on library input is later used in a shell command.
This string concatenation which depends on library input is later used in a shell command.


[warning] 243-243: Unsafe shell command constructed from library input
This string concatenation which depends on library input is later used in a shell command.
This string concatenation which depends on library input is later used in a shell command.

Additional comments not posted (8)
tests/regression/tests/issue-1667.test.ts (2)

4-28: LGTM!

The test case is well-structured and properly configures the schema with the enhancer plugin using a custom output folder. The loadSchema function is called with suitable options to focus on the generated Prisma schema and preserve TypeScript files for analysis. The lack of assertions is acceptable for a regression test that verifies the successful completion of the schema loading and code generation process.


30-59: LGTM!

The test case is well-structured and properly configures the schema with the enhancer plugin and the zod plugin using custom output folders. The loadSchema function is called with suitable options to focus on the generated Prisma schema, generate code without compilation, and then compile the generated code. The lack of assertions is acceptable for a regression test that verifies the successful completion of the schema loading, code generation, and compilation process.

packages/schema/src/plugins/plugin-utils.ts (1)

2-2: LGTM!

The import changes are approved as they are consistent with the new getPluginCustomOutputFolder function.

Also applies to: 6-6

packages/testtools/src/schema.ts (2)

138-138: LGTM!

The code change is approved.


150-150: LGTM!

The code change is approved.

packages/schema/src/plugins/enhancer/enhance/index.ts (3)

41-41: LGTM!

The import statement is approved.


134-153: LGTM!

The new private method getZodImport looks good. It correctly determines the appropriate import path for Zod based on the presence of custom output options.


104-108: LGTM!

The changes to the import statement for Zod schemas are approved. The dynamic import based on the withZodSchemas option and the path returned by getZodImport() enhances the flexibility of the import mechanism.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0636d63 and 96cd8cf.

Files selected for processing (1)
  • tests/integration/tests/plugins/zod.test.ts (5 hunks)
Additional comments not posted (3)
tests/integration/tests/plugins/zod.test.ts (3)

500-500: LGTM!

The code changes are approved.


791-794: LGTM!

The code changes are approved.


809-809: LGTM!

The code changes are approved.

Comment on lines +791 to +794
plugin enhancer {
provider = '@core/enhancer'
output = "$projectRoot/enhance"
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider merging the duplicate enhancer plugin configurations.

The enhancer plugin is configured twice with the same options. Consider merging them into a single configuration to improve maintainability and reduce duplication.

 plugin enhancer {
     provider = '@core/enhancer'
     output = "$projectRoot/enhance"
 }
-
-plugin enhancer {
-    provider = '@core/enhancer' 
-    output = "$projectRoot/enhance"
-}

Also applies to: 831-834

@ymc9 ymc9 merged commit 83bdd6d into dev Sep 2, 2024
13 checks passed
@ymc9 ymc9 deleted the fix/issue-1667 branch September 2, 2024 00:28
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.

None yet

1 participant