Skip to content

Commit 060361f

Browse files
committed
Fix doctor version checks for pro package and dedupe wildcard errors
1 parent 68f1ce8 commit 060361f

2 files changed

Lines changed: 42 additions & 3 deletions

File tree

react_on_rails/lib/react_on_rails/doctor.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,8 @@ def check_environment
142142
end
143143

144144
def check_react_on_rails_versions
145-
# Use system_checker for comprehensive package validation instead of duplicating
145+
# SystemChecker already validates wildcard/version-pattern constraints.
146146
checker.check_react_on_rails_packages
147-
check_version_wildcards
148147
check_pro_package_consistency
149148
auto_fix_versions if fix
150149
end
@@ -565,8 +564,13 @@ def check_npm_wildcard_for(all_deps, package_name)
565564
return unless npm_version
566565

567566
if /[~^><*]/.match?(npm_version) || npm_version.include?(" ")
567+
gem_version = if package_name == "react-on-rails-pro"
568+
ReactOnRails::Utils.react_on_rails_pro_version
569+
else
570+
ReactOnRails::VERSION
571+
end
568572
install_cmd = ReactOnRails::Utils.package_manager_install_exact_command(
569-
package_name, ReactOnRails::VersionSyntaxConverter.new.rubygem_to_npm(ReactOnRails::VERSION)
573+
package_name, ReactOnRails::VersionSyntaxConverter.new.rubygem_to_npm(gem_version)
570574
)
571575
checker.add_error(<<~MSG.strip)
572576
🚫 package.json uses a non-exact version for #{package_name}: #{npm_version}

react_on_rails/spec/lib/react_on_rails/doctor_spec.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,41 @@
8484
end
8585
end
8686

87+
describe "#check_react_on_rails_versions" do
88+
let(:doctor) { described_class.new(verbose: false, fix: false) }
89+
let(:checker) { doctor.instance_variable_get(:@checker) }
90+
91+
before do
92+
allow(checker).to receive(:check_react_on_rails_packages)
93+
allow(doctor).to receive(:check_pro_package_consistency)
94+
end
95+
96+
it "relies on SystemChecker for version-pattern checks" do
97+
expect(checker).to receive(:check_react_on_rails_packages)
98+
expect(doctor).not_to receive(:check_version_wildcards)
99+
expect(doctor).to receive(:check_pro_package_consistency)
100+
101+
doctor.send(:check_react_on_rails_versions)
102+
end
103+
end
104+
105+
describe "#check_npm_wildcard_for" do
106+
let(:doctor) { described_class.new(verbose: false, fix: false) }
107+
108+
it "uses the Pro gem version in the install command for react-on-rails-pro" do
109+
allow(ReactOnRails::Utils).to receive(:react_on_rails_pro_version).and_return("16.4.1")
110+
expect(ReactOnRails::Utils).to receive(:package_manager_install_exact_command)
111+
.with("react-on-rails-pro", "16.4.1")
112+
.and_return("npm install [email protected]")
113+
114+
doctor.send(
115+
:check_npm_wildcard_for,
116+
{ "react-on-rails-pro" => "^16.4.0" },
117+
"react-on-rails-pro"
118+
)
119+
end
120+
end
121+
87122
describe "#check_react_on_rails_initializer" do
88123
let(:doctor) { described_class.new(verbose: false, fix: false) }
89124
let(:checker) { doctor.instance_variable_get(:@checker) }

0 commit comments

Comments
 (0)