Skip to content

Commit 9ce3af8

Browse files
justin808claude
andcommitted
Use Shakapacker gem API for server bundle path detection
- Replace manual YAML parsing with proper Shakapacker.config API calls - Use Shakapacker.config.source_path and Shakapacker.config.source_entry_path - Gracefully fallback to defaults when Shakapacker gem is not available - Ensures accurate path detection that respects all Shakapacker configuration This fixes the issue where doctor was checking app/javascript/packs/server-bundle.js instead of the correct client/app/packs/server-bundle.js path from shakapacker.yml. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 173356b commit 9ce3af8

File tree

2 files changed

+15
-32
lines changed

2 files changed

+15
-32
lines changed

lib/react_on_rails/doctor.rb

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -247,34 +247,21 @@ def print_recommendations
247247
end
248248

249249
def determine_server_bundle_path
250-
# Try to read Shakapacker configuration
251-
shakapacker_config = read_shakapacker_config
252-
if shakapacker_config
253-
source_path = shakapacker_config["source_path"] || "app/javascript"
254-
source_entry_path = shakapacker_config["source_entry_path"] || "packs"
250+
# Try to use Shakapacker gem API to get configuration
251+
begin
252+
require "shakapacker"
253+
source_path = Shakapacker.config.source_path
254+
source_entry_path = Shakapacker.config.source_entry_path
255255
server_bundle_filename = get_server_bundle_filename
256256

257257
File.join(source_path, source_entry_path, server_bundle_filename)
258-
else
259-
# Fallback to default paths
258+
rescue LoadError, NameError, StandardError
259+
# Fallback to default paths if Shakapacker is not available or configured
260260
server_bundle_filename = get_server_bundle_filename
261261
"app/javascript/packs/#{server_bundle_filename}"
262262
end
263263
end
264264

265-
def read_shakapacker_config
266-
config_path = "config/shakapacker.yml"
267-
return nil unless File.exist?(config_path)
268-
269-
begin
270-
require "yaml"
271-
config = YAML.load_file(config_path)
272-
config["default"] || config
273-
rescue StandardError
274-
nil
275-
end
276-
end
277-
278265
def get_server_bundle_filename
279266
# Try to read from React on Rails initializer
280267
initializer_path = "config/initializers/react_on_rails.rb"

spec/lib/react_on_rails/doctor_spec.rb

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030
# Mock the new server bundle path methods
3131
allow(doctor).to receive(:determine_server_bundle_path).and_return("app/javascript/packs/server-bundle.js")
32-
allow(doctor).to receive(:read_shakapacker_config).and_return(nil)
3332
allow(doctor).to receive(:get_server_bundle_filename).and_return("server-bundle.js")
3433

3534
# Mock the checker to avoid actual system calls
@@ -83,28 +82,25 @@
8382
let(:doctor) { described_class.new }
8483

8584
describe "#determine_server_bundle_path" do
86-
context "when shakapacker.yml exists" do
87-
let(:shakapacker_config) do
88-
{
89-
"source_path" => "client/app",
90-
"source_entry_path" => "packs"
91-
}
92-
end
85+
context "when Shakapacker gem is available" do
86+
let(:shakapacker_config) { double(source_path: "client/app", source_entry_path: "packs") }
9387

9488
before do
95-
allow(doctor).to receive(:read_shakapacker_config).and_return(shakapacker_config)
89+
shakapacker_module = double("Shakapacker", config: shakapacker_config)
90+
stub_const("Shakapacker", shakapacker_module)
91+
allow(doctor).to receive(:require).with("shakapacker").and_return(true)
9692
allow(doctor).to receive(:get_server_bundle_filename).and_return("server-bundle.js")
9793
end
9894

99-
it "uses shakapacker configuration" do
95+
it "uses Shakapacker API configuration" do
10096
path = doctor.send(:determine_server_bundle_path)
10197
expect(path).to eq("client/app/packs/server-bundle.js")
10298
end
10399
end
104100

105-
context "when shakapacker.yml does not exist" do
101+
context "when Shakapacker gem is not available" do
106102
before do
107-
allow(doctor).to receive(:read_shakapacker_config).and_return(nil)
103+
allow(doctor).to receive(:require).with("shakapacker").and_raise(LoadError)
108104
allow(doctor).to receive(:get_server_bundle_filename).and_return("server-bundle.js")
109105
end
110106

0 commit comments

Comments
 (0)