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

Enable use as a Git dependency #1664

Merged
merged 2 commits into from
Dec 23, 2024
Merged

Enable use as a Git dependency #1664

merged 2 commits into from
Dec 23, 2024

Conversation

alexeyr-ci
Copy link
Collaborator

@alexeyr-ci alexeyr-ci commented Dec 19, 2024

Summary

When I tried to use a Git branch of the Node Renderer in Popmenu, it failed because the package isn't built after downloading. This PR fixes the issue. It should work for all package managers consuming this package:

  • npm runs both prepare and prepack (and I think prepack is the more recommended) for Git dependencies;
  • Yarn v1 runs only prepare
  • Yarn v2+ runs only prepack
  • pnpm doesn't document it anywhere I could find, but probably still runs one of them.

Pull Request checklist

  • [ ] Add/update test to cover these changes
  • [ ] Update documentation
  • Update CHANGELOG file

This change is Reviewable

Summary by CodeRabbit

  • New Features

    • Added streaming server rendering support, enhancing performance for server-rendered components.
    • Introduced console log replay capabilities during server rendering for improved debugging.
    • Added support for using the package as a git: dependency.
  • Bug Fixes

    • Updated version checking logic to prevent breaking changes and provide clearer error messages.
  • Documentation

    • Updated CHANGELOG.md with recent changes and enhancements.
  • Chores

    • Introduced new build scripts to streamline project packaging.

Copy link
Contributor

coderabbitai bot commented Dec 19, 2024

Walkthrough

This pull request introduces several enhancements to the React on Rails project, focusing on version checking, package management, and server-side rendering capabilities. The changes include updating the version checking logic, adding support for Git dependencies, introducing streaming server rendering with React 18's renderToPipeableStream, and improving console log replay during server rendering. The modifications aim to provide more flexible package version handling and advanced rendering techniques.

Changes

File Change Summary
CHANGELOG.md - Corrected registerStore to registerStoreGenerators
- Added streaming server rendering support
- Introduced console log replay during server rendering
- Changed version checker to use configuration.node_modules_location
- Updated error handling to use Rails.Logger warnings
package-scripts.yml - Added new build section with prepack script for pre-packaging build checks
package.json - Added prepack and prepare scripts executing nps build.prepack
lib/react_on_rails/version_checker.rb - Updated version checking logic
- Renamed relative_path? to local_path_or_url?
- Enhanced error messaging for version parsing
spec/react_on_rails/fixtures/ - Added git_package.json
- Added semver_range_package.json
spec/react_on_rails/version_checker_spec.rb - Updated test cases for version checking
- Added tests for Git URL and semver range scenarios

Possibly Related PRs

Suggested Reviewers

  • justin808
  • Judahmeek

Poem

🐰 Streaming React, oh what a delight!
Versions checked with rabbit-like might
Logs captured, components flow free
Server rendering's new jubilee
CodeRabbit hops with pure glee! 🚀

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


📜 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 8d2f7a6 and 9d359d8.

⛔ Files ignored due to path filters (1)
  • Gemfile.lock is excluded by !**/*.lock
📒 Files selected for processing (4)
  • lib/react_on_rails/version_checker.rb (2 hunks)
  • spec/react_on_rails/fixtures/git_package.json (1 hunks)
  • spec/react_on_rails/fixtures/semver_range_package.json (1 hunks)
  • spec/react_on_rails/version_checker_spec.rb (8 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • spec/react_on_rails/fixtures/semver_range_package.json
  • spec/react_on_rails/fixtures/git_package.json
🔇 Additional comments (9)
lib/react_on_rails/version_checker.rb (5)

84-96: LGTM: Improved caching of raw version value

The addition of proper memoization using defined?(@raw) is a good improvement that prevents redundant JSON parsing.


100-104: LGTM: Enhanced semver wildcard detection

The improved version checking now correctly handles all npm version expressions, with clear documentation reference. This change supports the PR's objective of enabling Git dependencies.


106-110: LGTM: Fixed npm scoped packages handling

The renamed method with improved logic now correctly handles npm scoped packages (e.g., @scope/package) while still detecting local paths and URLs. This addresses the issue raised in previous reviews.


114-118: LGTM: Improved error messaging

The error message is now more specific about version requirements, which will help developers understand and fix version-related issues faster.


23-23: LGTM: Updated method call for consistency

The method call has been updated to match the renamed method, maintaining code consistency.

spec/react_on_rails/version_checker_spec.rb (4)

95-95: LGTM: Updated test doubles to match implementation

The test doubles have been properly updated to reflect the renamed method, maintaining test consistency with the implementation.

Also applies to: 119-124


172-176: LGTM: Added test coverage for version ranges

Good addition of test coverage for version range expressions, ensuring the enhanced semver wildcard detection works correctly.


186-187: LGTM: Updated test method names for consistency

All test cases have been consistently updated to use the new method name, maintaining code clarity.

Also applies to: 202-203, 218-219, 234-235, 250-252


259-268: LGTM: Added test coverage for Git dependencies

Excellent addition of test coverage for Git URL handling, which directly supports the PR's objective of enabling Git dependencies.


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

@alexeyr-ci alexeyr-ci force-pushed the alexeyr/prepack-script branch from 58df136 to 722b351 Compare December 19, 2024 14:23
Copy link
Collaborator

@AbanoubGhadban AbanoubGhadban left a comment

Choose a reason for hiding this comment

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

LGTM

@alexeyr-ci alexeyr-ci changed the title Enable use as a Git dependency [WIP (do not merge yet)] Enable use as a Git dependency Dec 19, 2024
@alexeyr-ci alexeyr-ci force-pushed the alexeyr/prepack-script branch 2 times, most recently from ef8be23 to 5b811d7 Compare December 20, 2024 09:17
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: 0

🧹 Nitpick comments (1)
package-scripts.yml (1)

17-29: Documentation needed for Git dependency usage.

Since this change enables using the package as a Git dependency, please update the documentation to include:

  1. Instructions for installing the package as a Git dependency
  2. Any prerequisites or considerations when using Git dependencies
  3. Troubleshooting steps for common build issues

Would you like me to help draft the documentation updates?

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ef8be23 and 5b811d7.

📒 Files selected for processing (3)
  • CHANGELOG.md (1 hunks)
  • package-scripts.yml (1 hunks)
  • package.json (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • package.json
  • CHANGELOG.md
🔇 Additional comments (1)
package-scripts.yml (1)

17-29: The prepack script implementation looks good but could be improved.

The script successfully addresses the Git dependency issue by ensuring the package is built during npm pack or npm publish. However, there are some potential improvements:

Consider these enhancements:

 build:
   prepack:
     description: Build the project in the prepack script.
     # 1. If the project is already built, do nothing;
     # 2. Build the project but ignore TypeScript errors from missing devDependencies;
     # 3. Check if the project is built now;
     # 4. If it failed, print an error message (still follow https://docs.npmjs.com/cli/v8/using-npm/scripts#best-practices).
     script: >
       [ -f node_package/lib/ReactOnRails.js ] ||
-        (nps build >/dev/null 2>&1 || true) &&
+        (nps build >/dev/null 2>build-error.log || (cat build-error.log && false)) &&
         [ -f node_package/lib/ReactOnRails.js ] ||
-        { echo 'Building react-on-rails seems to have failed!'; }
+        { echo 'Building react-on-rails failed! Please check build-error.log for details or run `nps build` manually.'; exit 1; }

This change:

  1. Captures build errors in a log file for debugging
  2. Returns a non-zero exit code on failure
  3. Provides more helpful error message with debugging instructions

Let's verify the build process works correctly:

@alexeyr-ci alexeyr-ci force-pushed the alexeyr/prepack-script branch from 5b811d7 to 212e25b Compare December 20, 2024 09:21
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: 0

🧹 Nitpick comments (1)
CHANGELOG.md (1)

26-26: Verify the changelog entry matches the PR objective

The changelog entry "Enable use as a git: dependency" aligns with the PR objective but could be more descriptive about the actual changes made to enable this functionality. Consider expanding the entry to mention that it fixes the package build issue after downloading.

Suggested improvement:

- Enable use as a `git:` dependency. [PR 1664](https://github.com/shakacode/react_on_rails/pull/1664) by [alexeyr-ci](https://github.com/alexeyr-ci).
+ Enable use as a `git:` dependency by ensuring package is built after downloading. [PR 1664](https://github.com/shakacode/react_on_rails/pull/1664) by [alexeyr-ci](https://github.com/alexeyr-ci).
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5b811d7 and 212e25b.

📒 Files selected for processing (3)
  • CHANGELOG.md (1 hunks)
  • package-scripts.yml (1 hunks)
  • package.json (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • package.json
  • package-scripts.yml

@alexeyr-ci alexeyr-ci changed the title [WIP (do not merge yet)] Enable use as a Git dependency Enable use as a Git dependency Dec 22, 2024
@alexeyr-ci alexeyr-ci force-pushed the alexeyr/prepack-script branch from 9b68f41 to eac7ea0 Compare December 23, 2024 09:24
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: 0

🧹 Nitpick comments (1)
package-scripts.yml (1)

17-31: LGTM! Robust implementation for Git dependency support.

The implementation properly handles the build process when used as a Git dependency by:

  1. Checking if the project is already built
  2. Attempting to build if necessary
  3. Verifying the build succeeded
  4. Providing a clear error message on failure

Consider making the error message more specific:

-          { echo 'Building react-on-rails seems to have failed!'; }
+          { echo 'Building react-on-rails failed! Please ensure all dependencies are installed.'; }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 212e25b and eac7ea0.

📒 Files selected for processing (4)
  • .npmignore (0 hunks)
  • CHANGELOG.md (1 hunks)
  • package-scripts.yml (1 hunks)
  • package.json (1 hunks)
💤 Files with no reviewable changes (1)
  • .npmignore
🚧 Files skipped from review as they are similar to previous changes (1)
  • package.json
🔇 Additional comments (1)
CHANGELOG.md (1)

26-26: LGTM! Well-documented changelog entry.

The changelog entry is properly formatted, placed in the correct section, and accurately describes the fix with appropriate PR reference and author credit.

@alexeyr-ci alexeyr-ci force-pushed the alexeyr/prepack-script branch from eac7ea0 to 4a535ed Compare December 23, 2024 09:40
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

🧹 Nitpick comments (1)
lib/react_on_rails/version_checker.rb (1)

23-23: Consider clarifying log behavior for local or Git dependencies
When the code detects a local path or URL (for example, a Git URL), it cleanly bypasses the version comparison. This is logically correct to avoid false mismatch warnings, but you may want to log a message indicating that version checks are skipped for local/Git dependencies.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between eac7ea0 and 8d2f7a6.

⛔ Files ignored due to path filters (1)
  • Gemfile.lock is excluded by !**/*.lock
📒 Files selected for processing (4)
  • lib/react_on_rails/version_checker.rb (2 hunks)
  • spec/react_on_rails/fixtures/git_package.json (1 hunks)
  • spec/react_on_rails/fixtures/semver_range_package.json (1 hunks)
  • spec/react_on_rails/version_checker_spec.rb (8 hunks)
✅ Files skipped from review due to trivial changes (2)
  • spec/react_on_rails/fixtures/git_package.json
  • spec/react_on_rails/fixtures/semver_range_package.json
🔇 Additional comments (12)
lib/react_on_rails/version_checker.rb (3)

112-112: Skipping version parse for local paths or URLs
Returning early if the package is local or Git-based ensures that you do not incorrectly parse a path as a semantic version. This looks appropriate given the intended logic.


116-116: Improved error message clarity
Raising an error with a specific message for non-exact versions is a good practice. This helps developers quickly identify the root cause of version incompatibilities.


98-101: Verify semver wildcard detection with pre-release identifiers
Because the regex checks for a dash, pre-release versions like "1.2.3-beta" will match and return true, indicating a wildcard. Consider handling standard semver pre-release tags (e.g., beta, rc) differently if you intend them to be treated as exact versions.

spec/react_on_rails/version_checker_spec.rb (9)

95-95: Test coverage for local path scenario
Including a test that sets a relative path and asserts no log is produced is valuable for ensuring local paths do not trigger version mismatch warnings.


119-124: Renaming parameter to match updated method name
Using “local_path_or_url” in the double ensures consistency with the refactored “local_path_or_url?” method. This helps maintain clarity between the production code and tests.


171-176: Good coverage for semver range detection
Verifying that version ranges (e.g., '>=1.2.3 <2.0.0') trigger the wildcard path ensures the updated checks align with npm dependencies' many version specifications.


186-187: Ensuring exact versions are not flagged as local
This test clarifies that “0.0.2” remains a standard semver version, confirming no local path detection occurs in such cases.


202-203: Confirming caret version is not mistaken for a local path
Testing “^14.0.0.beta-2” ensures the slash-based detection is not triggered for caret or pre-release semver references.


218-219: Relative path detection
Verifies that “../../..” is recognized correctly as a local path, preventing version parsing that might lead to errors.


234-235: Absolute file URL detection
Ensuring “file:///...” is recognized as a local path or URL supports Git-style or local protocol usage for advanced installation scenarios.


250-252: Yalc path scenario
Checks that “file:.yalc/react-on-rails” is properly flagged as a local path, vital for workflows using yalc.


259-267: Git URL test
Validating that “git://github.com/shakacode/react-on-rails.git” is recognized as local_path_or_url? ensures the logic supports Git-based installs as required by the PR’s objective.

lib/react_on_rails/version_checker.rb Show resolved Hide resolved
@alexeyr-ci alexeyr-ci force-pushed the alexeyr/prepack-script branch from 8d2f7a6 to 9d359d8 Compare December 23, 2024 12:00
@alexeyr-ci alexeyr-ci merged commit 4339d30 into master Dec 23, 2024
11 checks passed
@alexeyr-ci alexeyr-ci deleted the alexeyr/prepack-script branch December 23, 2024 17:45
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.

3 participants