-
-
Notifications
You must be signed in to change notification settings - Fork 632
Fix doctor false positives and stabilize default RSC starter #2478
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,6 +1,8 @@ | ||||||||||||||
| # frozen_string_literal: true | ||||||||||||||
|
|
||||||||||||||
| require "open3" | ||||||||||||||
| require "erb" | ||||||||||||||
| require "yaml" | ||||||||||||||
|
|
||||||||||||||
| module ReactOnRails | ||||||||||||||
| # SystemChecker provides validation methods for React on Rails setup | ||||||||||||||
|
|
@@ -186,17 +188,17 @@ def check_react_on_rails_npm_package | |||||||||||||
| return unless File.exist?(package_json_path) | ||||||||||||||
|
|
||||||||||||||
| package_json = JSON.parse(File.read(package_json_path)) | ||||||||||||||
| npm_version = package_json.dig("dependencies", "react-on-rails") || | ||||||||||||||
| package_json.dig("devDependencies", "react-on-rails") | ||||||||||||||
| package_name, npm_version = react_on_rails_npm_package_details(package_json) | ||||||||||||||
|
|
||||||||||||||
| if npm_version | ||||||||||||||
| add_success("✅ react-on-rails NPM package #{npm_version} is declared") | ||||||||||||||
| add_success("✅ #{package_name} NPM package #{npm_version} is declared") | ||||||||||||||
| else | ||||||||||||||
| add_warning(<<~MSG.strip) | ||||||||||||||
| ⚠️ react-on-rails NPM package not found in package.json. | ||||||||||||||
| ⚠️ Neither react-on-rails nor react-on-rails-pro NPM package was found in package.json. | ||||||||||||||
|
|
||||||||||||||
| Install it with: | ||||||||||||||
| npm install react-on-rails | ||||||||||||||
| Install one with: | ||||||||||||||
| npm install react-on-rails # Open source gem | ||||||||||||||
| npm install react-on-rails-pro # Pro gem | ||||||||||||||
| MSG | ||||||||||||||
| end | ||||||||||||||
| rescue JSON::ParserError | ||||||||||||||
|
|
@@ -208,8 +210,7 @@ def check_package_version_sync | |||||||||||||
|
|
||||||||||||||
| begin | ||||||||||||||
| package_json = JSON.parse(File.read("package.json")) | ||||||||||||||
| npm_version = package_json.dig("dependencies", "react-on-rails") || | ||||||||||||||
| package_json.dig("devDependencies", "react-on-rails") | ||||||||||||||
| package_name, npm_version = react_on_rails_npm_package_details(package_json) | ||||||||||||||
|
|
||||||||||||||
| return unless npm_version && defined?(ReactOnRails::VERSION) | ||||||||||||||
|
|
||||||||||||||
|
|
@@ -221,7 +222,7 @@ def check_package_version_sync | |||||||||||||
| gem_version = ReactOnRails::VERSION | ||||||||||||||
|
|
||||||||||||||
| if normalized_npm_version == gem_version | ||||||||||||||
| add_success("✅ React on Rails gem and NPM package versions match (#{gem_version})") | ||||||||||||||
| add_success("✅ React on Rails gem and #{package_name} NPM package versions match (#{gem_version})") | ||||||||||||||
| check_version_patterns(npm_version, gem_version) | ||||||||||||||
| else | ||||||||||||||
| # Check for major version differences | ||||||||||||||
|
|
@@ -232,7 +233,7 @@ def check_package_version_sync | |||||||||||||
| add_error(<<~MSG.strip) | ||||||||||||||
| 🚫 Major version mismatch detected: | ||||||||||||||
| • Gem version: #{gem_version} (major: #{gem_major}) | ||||||||||||||
| • NPM version: #{npm_version} (major: #{npm_major}) | ||||||||||||||
| • #{package_name} version: #{npm_version} (major: #{npm_major}) | ||||||||||||||
|
|
||||||||||||||
| Major version differences can cause serious compatibility issues. | ||||||||||||||
| Update both packages to use the same major version immediately. | ||||||||||||||
|
|
@@ -241,7 +242,7 @@ def check_package_version_sync | |||||||||||||
| add_warning(<<~MSG.strip) | ||||||||||||||
| ⚠️ Version mismatch detected: | ||||||||||||||
| • Gem version: #{gem_version} | ||||||||||||||
| • NPM version: #{npm_version} | ||||||||||||||
| • #{package_name} version: #{npm_version} | ||||||||||||||
|
|
||||||||||||||
| Consider updating to exact, fixed matching versions of gem and npm package for best compatibility. | ||||||||||||||
| MSG | ||||||||||||||
|
|
@@ -449,11 +450,55 @@ def normalize_config_content(content) | |||||||||||||
| end | ||||||||||||||
|
|
||||||||||||||
| def required_react_dependencies | ||||||||||||||
| { | ||||||||||||||
| deps = { | ||||||||||||||
| "react" => "React library", | ||||||||||||||
| "react-dom" => "React DOM library", | ||||||||||||||
| "@babel/preset-react" => "Babel React preset" | ||||||||||||||
| "react-dom" => "React DOM library" | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| deps["@babel/preset-react"] = "Babel React preset" if using_babel_transpiler? | ||||||||||||||
| deps | ||||||||||||||
| end | ||||||||||||||
|
|
||||||||||||||
| def react_on_rails_npm_package_details(package_json) | ||||||||||||||
| all_deps = package_json["dependencies"]&.merge(package_json["devDependencies"] || {}) || {} | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pre-existing: nil If This is a pre-existing pattern used throughout the file (7 occurrences), so not a regression from this PR, but worth noting since this method is now the single source of truth for Pro/OSS detection. A safer alternative would be: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Merge pattern loses devDependencies when dependencies key absentMedium Severity The |
||||||||||||||
| return ["react-on-rails-pro", all_deps["react-on-rails-pro"]] if all_deps["react-on-rails-pro"] | ||||||||||||||
| return ["react-on-rails", all_deps["react-on-rails"]] if all_deps["react-on-rails"] | ||||||||||||||
|
|
||||||||||||||
| [nil, nil] | ||||||||||||||
| end | ||||||||||||||
|
|
||||||||||||||
| def using_babel_transpiler? | ||||||||||||||
| transpiler = detected_javascript_transpiler | ||||||||||||||
| return true if transpiler.nil? | ||||||||||||||
|
|
||||||||||||||
| transpiler == "babel" | ||||||||||||||
| end | ||||||||||||||
|
|
||||||||||||||
| def detected_javascript_transpiler | ||||||||||||||
| config = parsed_shakapacker_config | ||||||||||||||
| return nil unless config | ||||||||||||||
|
|
||||||||||||||
| rails_env = ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development" | ||||||||||||||
| env_config = config[rails_env] || {} | ||||||||||||||
| default_config = config["default"] || {} | ||||||||||||||
| transpiler = env_config["javascript_transpiler"] || default_config["javascript_transpiler"] | ||||||||||||||
| normalize_transpiler_value(transpiler) | ||||||||||||||
| end | ||||||||||||||
|
|
||||||||||||||
| def parsed_shakapacker_config | ||||||||||||||
| shakapacker_config_path = "config/shakapacker.yml" | ||||||||||||||
| return nil unless File.exist?(shakapacker_config_path) | ||||||||||||||
|
|
||||||||||||||
| raw_content = File.read(shakapacker_config_path) | ||||||||||||||
| rendered_content = ERB.new(raw_content).result | ||||||||||||||
| YAML.safe_load(rendered_content, aliases: true) || {} | ||||||||||||||
| rescue StandardError | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The broad
Suggested change
Or at minimum log the error via |
||||||||||||||
| nil | ||||||||||||||
| end | ||||||||||||||
|
|
||||||||||||||
| def normalize_transpiler_value(transpiler) | ||||||||||||||
| normalized = transpiler.to_s.strip.downcase | ||||||||||||||
| normalized.empty? ? nil : normalized | ||||||||||||||
| end | ||||||||||||||
|
|
||||||||||||||
| def additional_build_dependencies | ||||||||||||||
|
|
||||||||||||||


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.
mergehere givesdevDependenciesprecedence overdependencieswhen the same package key exists in both. The original code checkeddependenciesfirst (higher precedence). To restore that behavior:This is a minor edge case (unlikely anyone has the same package in both sections), but the intent should be explicit.