Skip to content
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

Fix Version Checker's hard-coded path for package.json #1657

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Judahmeek
Copy link
Contributor

@Judahmeek Judahmeek commented Nov 21, 2024

Summary

Currently, the version checker is hard-coded to use client/package.json. If client/package.json doesn't exist, then the version checker silently fails.

This PR changes the version checker to match Shakapacker v8's requirements, which are that the package.json exists at the root of the project directory.

Alternately, we'll need to make the package.json path configurable.

Pull Request checklist

Remove this line after checking all the items here. If the item is not applicable to the PR, both check it out and wrap it by ~.

  • Add/update test to cover these changes
  • Update documentation
  • Update CHANGELOG file
    Add the CHANGELOG entry at the top of the file.

Other Information

Remove this paragraph and mention any other important and relevant information such as benchmarks.


This change is Reviewable

Summary by CodeRabbit

  • New Features

    • Introduced streaming server rendering support with a new helper for integrating streamed components.
    • Added a function for enhanced performance and progressive page loading using React 18's streaming capabilities.
    • Enabled console log replay during server rendering for better debugging.
    • Improved error handling during server rendering.
  • Bug Fixes

    • Corrected and renamed the ReactOnRails.registerStore method for clarity.
  • Chores

    • Updated the changelog to reflect new features and fixes.
    • Modified the path for the package.json used by the version checker.

Copy link
Contributor

coderabbitai bot commented Nov 21, 2024

Walkthrough

The pull request updates the CHANGELOG.md to document new features and fixes in the react_on_rails project. Key changes include the addition of streaming server rendering support, new helper methods for rendering, improved error handling, and updates to the console log replay process. The path for the package.json file used by the version checker has also been changed to point to the root directory. Additionally, a method in the ReactOnRails module has been renamed for clarity.

Changes

File Change Summary
CHANGELOG.md Updated to include new features such as streaming server rendering support, stream_react_component helper, and improved error handling.
lib/react_on_rails/version_checker.rb Updated NodePackageVersion class to change package.json path from /client to /.
lib/react_on_rails/*.rb Added methods: stream_react_component and streamServerRenderedReactComponent; renamed ReactOnRails.registerStore to ReactOnRails.registerStoreGenerators.

Possibly related PRs

Suggested reviewers

  • justin808
  • alexeyr-ci

🐰 In the land of code, changes bloom,
New streams of rendering, dispel the gloom.
With logs replayed, and errors tamed,
Our project grows, forever famed.
Hops of joy, let’s celebrate,
In the world of React, we innovate! 🥕


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:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • 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 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 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 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 and nitpick comments (2)
lib/react_on_rails/version_checker.rb (1)

77-77: LGTM! Consider making the path configurable in the future.

The change correctly aligns with Shakapacker v8 requirements by looking for package.json in the root directory. However, as mentioned in the PR objectives, consider making this path configurable to support different project structures.

Consider adding a configuration option in the future:

def self.package_json_path
  Rails.root.join(ReactOnRails.configuration.package_json_path || "package.json")
end
CHANGELOG.md (1)

21-24: LGTM with a minor suggestion.

The changelog entry correctly documents the package.json path change. Consider adding a note about why this change was necessary (to match Shakapacker v8 requirements) to provide more context for future readers.

- Changed the path of the package.json that the ReactOnRails' version checker attempts to use to be `/` instead of `/client`. [PR 1657](https://github.com/shakacode/react_on_rails/pull/1657) by [judahmeek](https://github.com/judahmeek).
+ Changed the path of the package.json that the ReactOnRails' version checker attempts to use to be `/` instead of `/client` to match Shakapacker v8 requirements. [PR 1657](https://github.com/shakacode/react_on_rails/pull/1657) by [judahmeek](https://github.com/judahmeek).
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between cebda5d and 19812b4.

📒 Files selected for processing (2)
  • CHANGELOG.md (1 hunks)
  • lib/react_on_rails/version_checker.rb (1 hunks)
🔇 Additional comments (4)
lib/react_on_rails/version_checker.rb (2)

77-77: Verify version checking still works with relative paths

The change preserves compatibility with relative paths through the relative_path? check. However, we should verify that version checking still works correctly with the new path.

✅ Verification successful

Let me check the test coverage to verify the version checking functionality.


Version checking is properly handled with relative paths

The test coverage and implementation confirm that version checking works correctly with the new path. Specifically:

  • The relative_path? check explicitly handles both relative paths (../) and file URLs
  • Test cases cover relative path scenarios, verifying that version checking is skipped appropriately
  • The change to use Rails.root.join doesn't affect the version checking logic as the path resolution remains consistent
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for test coverage of version checking
echo "Checking for version checker tests..."
rg -l "describe.*VersionChecker|test.*VersionChecker" --type ruby

# Look for any existing relative path usage
echo "Checking for relative path usage in package.json..."
rg -l "file://|\.\./" package.json || true

Length of output: 353


Script:

#!/bin/bash
# Check the version checker test content
echo "Examining version checker test cases..."
cat spec/react_on_rails/version_checker_spec.rb

# Check the actual version checker implementation
echo "Examining version checker implementation..."
cat lib/react_on_rails/version_checker.rb

Length of output: 10907


77-77: Verify impact on existing projects and update documentation

This change could break existing projects that still have package.json in the client/ directory. We should verify the impact and ensure documentation is updated.

CHANGELOG.md (2)

Line range hint 25-29: LGTM!

The "Added" section is well-structured with clear descriptions of new features, proper PR references, and author attributions.


Line range hint 1-20: LGTM!

The changelog follows the recommended format from keepachangelog.com and maintains consistent structure throughout. Version history and links are properly maintained.

@@ -74,7 +74,7 @@ def self.build
end

def self.package_json_path
Rails.root.join("client", "package.json")
Rails.root.join("package.json")
Copy link
Contributor

@coderabbitai coderabbitai bot Nov 21, 2024

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add explicit error handling for missing package.json

The current implementation will raise a generic file not found error if package.json is missing. Consider adding explicit error handling to guide users about the new path requirement.

 def self.package_json_path
-  Rails.root.join("package.json")
+  path = Rails.root.join("package.json")
+  unless File.exist?(path)
+    raise ReactOnRails::Error,
+          "Could not find package.json in Rails root directory. " \
+          "As per Shakapacker v8 requirements, package.json should be located at #{path}"
+  end
+  path
 end
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Rails.root.join("package.json")
def self.package_json_path
path = Rails.root.join("package.json")
unless File.exist?(path)
raise ReactOnRails::Error,
"Could not find package.json in Rails root directory. " \
"As per Shakapacker v8 requirements, package.json should be located at #{path}"
end
path
end

Copy link
Member

Choose a reason for hiding this comment

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

is there a way this code could be DRY'd up with Shakapacker someday?

Copy link
Member

Choose a reason for hiding this comment

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

are we making the one in the client directory not work?

Copy link
Contributor

Choose a reason for hiding this comment

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

@justin808, with this change, the version checker will no longer look for client/package.json and will instead check for package.json in the Rails root directory. This means that if package.json exists only in the client directory, the version checker will not find it, which could cause issues for setups relying on the previous path.

To address this, we might consider modifying the code to support both locations for backward compatibility or make the path configurable. Currently, this change aligns with Shakapacker v8 requirements, which expect package.json to be located at the root of the project.

Copy link
Contributor

Choose a reason for hiding this comment

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

@justin808, that's a great suggestion. Refactoring this code to share functionality with Shakapacker could help reduce duplication and improve maintainability. Would you like me to open a GitHub issue to track this potential enhancement?

@Judahmeek Judahmeek changed the title Set package.json path to match Shakapacker v8 requirements Fix Version Checker's hard-coded path for package.json Nov 21, 2024
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.

2 participants