Skip to content

Conversation

@clayne11
Copy link
Contributor

@clayne11 clayne11 commented Jul 3, 2025

Add --proto-lock/-l option to specify existing proto lock file path. This is necessary for environments like Bazel where input and output files must be at different paths. Making assumptions about paths in general with Bazel often leads to issues due to Bazel's sandboxing.

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Added support for specifying an optional proto lock file path when generating protobuf schemas via the CLI.
  • Refactor

    • Improved the proto lock file loading process for better flexibility and reliability.
    • Enhanced asynchronous file handling for protobuf schema generation commands.

Checklist

@coderabbitai
Copy link

coderabbitai bot commented Jul 3, 2025

Walkthrough

The command-line interface for generating protobuf schemas now supports an optional --proto-lock argument to specify a proto lock file path. The proto lock data loading logic has been refactored to use asynchronous helper functions, replacing synchronous filesystem calls and updating function signatures to use options objects for improved flexibility.

Changes

File(s) Change Summary
cli/src/commands/grpc-service/commands/generate.ts Added optional --proto-lock CLI argument; refactored proto lock file loading to use async helper functions; replaced synchronous fs calls with async fs.promises calls; updated function signatures to use options objects (CLIOptions, GenerationOptions); added new exported async helpers exists and fetchLockData; adjusted imports and typings; explicitly typed spinner as Ora.

📜 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 7ae4b1a and 3464a4e.

📒 Files selected for processing (1)
  • cli/src/commands/grpc-service/commands/generate.ts (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • cli/src/commands/grpc-service/commands/generate.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Analyze (go)
  • GitHub Check: Analyze (javascript-typescript)
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
    • @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 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.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in 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.

@github-actions github-actions bot added the cli label Jul 3, 2025
@clayne11 clayne11 force-pushed the curtis.layne/proto-lock-fix branch from 2db1f78 to caeb35c Compare July 3, 2025 06:23
Copy link

@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
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cd9ddb2 and caeb35c.

📒 Files selected for processing (1)
  • cli/src/commands/grpc-service/commands/generate.ts (6 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
cli/src/commands/grpc-service/commands/generate.ts (1)
cli/src/commands/router/commands/plugin/toolchain.ts (1)
  • generateProtoAndMapping (354-393)
🪛 GitHub Actions: wgc CI
cli/src/commands/grpc-service/commands/generate.ts

[warning] 1-1: Prettier formatting check failed. Run 'prettier --write' to fix code style issues.

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (go)
🔇 Additional comments (5)
cli/src/commands/grpc-service/commands/generate.ts (5)

1-1: LGTM: Import addition is appropriate.

The addition of the exists import from node:fs/promises is correct and necessary for the async file existence checks in the new fetchLockData function.


19-22: LGTM: CLI option implementation is well-structured.

The new --proto-lock option is properly implemented with both short (-l) and long form, includes appropriate description, and follows the existing pattern for optional arguments.


57-57: LGTM: Parameter passing is correct.

The options.protoLock parameter is correctly passed to the generateProtoAndMapping function.


87-87: LGTM: Function signature update is appropriate.

The addition of the optional protoLockFile parameter maintains backward compatibility while enabling the new functionality.


96-96: LGTM: Refactoring to async helper function improves code organization.

The replacement of inline synchronous lock data reading with the async fetchLockData helper function improves code organization and enables the new custom proto lock file functionality.

@clayne11 clayne11 force-pushed the curtis.layne/proto-lock-fix branch from caeb35c to a6949bd Compare July 3, 2025 06:29
@endigma
Copy link
Member

endigma commented Jul 3, 2025

Hi @clayne11, thanks for the fix! We're currently experimenting with coderabbitai pull request AI review thing you can see above, which likes to make a lot of noise while PRs are being worked on if they aren't in the draft state. Until CI (looks like just a prettier fail) is fixed and you're happy with the state, would you mind marking it as a draft?

@clayne11 clayne11 force-pushed the curtis.layne/proto-lock-fix branch 2 times, most recently from 57bb4f6 to 93b4db0 Compare July 3, 2025 17:08
@clayne11
Copy link
Contributor Author

clayne11 commented Jul 3, 2025

Should be good to go now @endigma. CodeRabbit was helpful, it pointed out a real issue.

@clayne11 clayne11 closed this Jul 3, 2025
@clayne11 clayne11 reopened this Jul 3, 2025
@endigma endigma requested a review from Noroth July 7, 2025 11:24
Copy link
Member

@endigma endigma left a comment

Choose a reason for hiding this comment

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

cc @Noroth for review on the function of this, I'm just looking at pure code review

@clayne11 clayne11 force-pushed the curtis.layne/proto-lock-fix branch 2 times, most recently from c78fa0a to 54a0385 Compare July 8, 2025 20:28
Copy link

@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
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 93b4db0 and 54a0385.

📒 Files selected for processing (1)
  • cli/src/commands/grpc-service/commands/generate.ts (6 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
cli/src/commands/grpc-service/commands/generate.ts (2)
cli/src/commands/router/commands/plugin/toolchain.ts (1)
  • generateProtoAndMapping (354-393)
protographic/src/index.ts (2)
  • compileGraphQLToMapping (15-31)
  • compileGraphQLToProto (52-78)
🪛 GitHub Check: build_test_node_matrix (22.x)
cli/src/commands/grpc-service/commands/generate.ts

[failure] 5-5:
Ora not found in 'ora'


[failure] 4-4:
node:fs/promises import should occur before import of @wundergraph/protographic

🪛 GitHub Check: build_test_node_matrix (20.x)
cli/src/commands/grpc-service/commands/generate.ts

[failure] 5-5:
Ora not found in 'ora'


[failure] 4-4:
node:fs/promises import should occur before import of @wundergraph/protographic

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Analyze (go)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (9)
cli/src/commands/grpc-service/commands/generate.ts (9)

10-16: Well-defined CLI options type.

The CLIOptions type is well-structured and clearly defines the expected command-line options with appropriate optional properties.


26-30: Excellent implementation of the new proto-lock option.

The new --proto-lock option is well-documented with clear help text explaining its purpose and default behavior. This addresses the PR objective of supporting custom proto lock file paths for build environments like Bazel.


42-42: Improved function signature with proper typing.

The function signature has been improved to use the properly typed CLIOptions instead of any, which enhances type safety and code maintainability.


53-63: Good conversion to async file operations.

The conversion from synchronous existsSync and lstatSync to the new async exists function is a good improvement that makes the code more consistent with the async/await pattern used throughout the file.


65-73: Clean refactoring to options object pattern.

The refactoring from multiple parameters to a single options object improves the function's API and makes it easier to extend in the future. The explicit parameter names make the code more readable.


94-102: Well-structured generation options type.

The GenerationOptions type is comprehensive and properly typed, including the Ora type for the spinner parameter.


107-115: Improved function signature with default parameter.

The destructured parameter approach with a default value for lockFile is clean and provides a good fallback behavior when no custom lock file is specified.


138-147: Simple and effective lock data fetching.

The fetchLockData function is well-implemented with proper error handling. It checks for file existence before attempting to read and parse the JSON, returning undefined gracefully if the file doesn't exist or is invalid.


149-157: Proper async replacement for existsSync.

The exists function is a good async replacement for existsSync using the recommended access approach. The error handling is appropriate, returning false when the file doesn't exist or isn't accessible.

@clayne11 clayne11 force-pushed the curtis.layne/proto-lock-fix branch from 50e23fe to fb29aa3 Compare July 9, 2025 16:10
@clayne11 clayne11 force-pushed the curtis.layne/proto-lock-fix branch 2 times, most recently from 35db936 to e46f660 Compare July 10, 2025 04:49
Copy link

@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: 0

🧹 Nitpick comments (1)
cli/src/commands/grpc-service/commands/generate.ts (1)

138-145: Fix the negated condition to follow linting rules.

The static analysis correctly identifies an issue with the negated condition. The logic can be simplified and made more readable.

Apply this diff to fix the linting issue:

-async function fetchLockData(lockFile: string): Promise<ProtoLock | undefined> {
-  if (!(await exists(lockFile))) {
-    return undefined;
-  }
-
-  const existingLockData = JSON.parse(await readFile(lockFile, 'utf8'));
-  return existingLockData != null ? existingLockData : undefined;
-}
+async function fetchLockData(lockFile: string): Promise<ProtoLock | undefined> {
+  if (await exists(lockFile)) {
+    const existingLockData = JSON.parse(await readFile(lockFile, 'utf8'));
+    return existingLockData || undefined;
+  }
+  
+  return undefined;
+}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between fb29aa3 and e46f660.

📒 Files selected for processing (1)
  • cli/src/commands/grpc-service/commands/generate.ts (6 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
cli/src/commands/grpc-service/commands/generate.ts (2)
cli/src/commands/router/commands/plugin/toolchain.ts (1)
  • generateProtoAndMapping (354-393)
protographic/src/index.ts (2)
  • compileGraphQLToMapping (15-31)
  • compileGraphQLToProto (52-78)
🪛 GitHub Check: build_test_node_matrix (22.x)
cli/src/commands/grpc-service/commands/generate.ts

[failure] 144-144:
Unexpected negated condition

🪛 GitHub Check: build_test_node_matrix (20.x)
cli/src/commands/grpc-service/commands/generate.ts

[failure] 144-144:
Unexpected negated condition

🪛 GitHub Actions: wgc CI
cli/src/commands/grpc-service/commands/generate.ts

[error] 144-144: ESLint: Unexpected negated condition (unicorn/no-negated-condition)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (go)
🔇 Additional comments (10)
cli/src/commands/grpc-service/commands/generate.ts (10)

1-6: LGTM! Import organization follows conventions.

The imports are now properly organized with Node.js built-ins first, then third-party packages, and the type import for Ora is correctly specified. This addresses the previous static analysis issues.


10-16: Well-defined CLI options type.

The CLIOptions type clearly defines all the command-line options including the new protoLock field. The optional fields are appropriately marked.


26-30: Excellent addition of the --proto-lock option.

The new option provides clear documentation and addresses the core requirement for supporting custom proto lock file paths in build environments like Bazel. The description clearly explains the default behavior.


42-42: Good refactoring to use typed options.

The function signature now uses the well-defined CLIOptions type instead of any, improving type safety.


53-63: Proper conversion to async filesystem operations.

The file existence and directory checks now use the async exists function and lstat, which is more appropriate for CLI operations that shouldn't block the event loop.


65-73: Clean refactoring to options object.

The function call now uses a clear options object instead of multiple positional parameters, making it more maintainable. The new lockFile parameter correctly passes the custom proto lock path.


94-102: Well-structured generation options type.

The GenerationOptions type provides clear documentation of all parameters needed for proto generation, including the new optional lockFile parameter.


107-115: Excellent function signature improvement.

The destructured parameters with default value for lockFile make the function more flexible and maintainable. The default fallback path maintains backward compatibility.


122-122: Simplified lock data loading.

The extraction of lock data fetching into a separate function improves code organization and readability.


147-155: Well-implemented async exists helper.

The function properly uses access with constants.R_OK as recommended, and correctly handles the promise rejection to return a boolean. The comment explaining why exists from node:fs is not recommended is helpful.

@clayne11 clayne11 force-pushed the curtis.layne/proto-lock-fix branch 2 times, most recently from cf11922 to 7ae4b1a Compare July 10, 2025 04:57
@clayne11 clayne11 requested a review from endigma July 10, 2025 04:58
Copy link
Member

@endigma endigma left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the cleanup of option types as well!

…te command

- Add --proto-lock/-l option to specify existing proto lock file path. This is necessary for environments like Bazel where input and output files must be at different paths. Making assumptions about paths in general with Bazel often leads to issues due to Bazel's sandboxing.
@clayne11 clayne11 force-pushed the curtis.layne/proto-lock-fix branch from 7ae4b1a to 3464a4e Compare July 11, 2025 19:59
@clayne11 clayne11 requested a review from jensneuse as a code owner July 11, 2025 19:59
@StarpTech StarpTech merged commit cc2a400 into wundergraph:main Jul 11, 2025
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants