-
-
Notifications
You must be signed in to change notification settings - Fork 631
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
base: master
Are you sure you want to change the base?
Conversation
WalkthroughThe pull request updates the Changes
Possibly related PRs
Suggested reviewers
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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") endCHANGELOG.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
📒 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") |
There was a problem hiding this comment.
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.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
Summary
Currently, the version checker is hard-coded to use
client/package.json
. Ifclient/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 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
Summary by CodeRabbit
New Features
Bug Fixes
ReactOnRails.registerStore
method for clarity.Chores
package.json
used by the version checker.