Skip to content

Commit 831ce78

Browse files
committed
Avoid selecting unusable watch binstubs
1 parent 8bb6aa9 commit 831ce78

3 files changed

Lines changed: 17 additions & 4 deletions

File tree

react_on_rails/lib/generators/react_on_rails/generator_helper.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,12 +492,13 @@ def detect_react_version
492492
nil
493493
end
494494

495-
# Prefer Shakapacker's optional watcher binstub when the application has it. Older
495+
# Prefer Shakapacker's optional watcher binstub when the application has an executable copy. Older
496496
# supported Shakapacker installations can still run watch mode through the required
497497
# bin/shakapacker binstub, so React on Rails does not need to vendor a fallback watcher.
498498
def shakapacker_watch_command
499499
watch_binstub = File.join(destination_root, "bin/shakapacker-watch")
500-
executable = File.exist?(watch_binstub) ? "bin/shakapacker-watch" : "bin/shakapacker"
500+
watch_binstub_available = File.file?(watch_binstub) && File.executable?(watch_binstub)
501+
executable = watch_binstub_available ? "bin/shakapacker-watch" : "bin/shakapacker"
501502

502503
"#{executable} --watch"
503504
end

react_on_rails/spec/react_on_rails/generators/install_generator_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,15 +520,15 @@ def run_add_agent_files(options = {})
520520
run_generator_test_with_args(%w[], package_json: true) do
521521
simulate_preinstalled_shakapacker(source_path: "app/javascript", source_entry_path: "packs")
522522
simulate_existing_file("bin/shakapacker-watch", shakapacker_watch)
523-
File.chmod(0o640, File.join(destination_root, "bin/shakapacker-watch"))
523+
File.chmod(0o750, File.join(destination_root, "bin/shakapacker-watch"))
524524
end
525525
end
526526

527527
it "preserves Shakapacker's binstub under --force" do
528528
assert_file "bin/shakapacker-watch" do |content|
529529
expect(content).to eq(shakapacker_watch)
530530
end
531-
expect(File.stat(File.join(destination_root, "bin/shakapacker-watch")).mode & 0o777).to eq(0o640)
531+
expect(File.stat(File.join(destination_root, "bin/shakapacker-watch")).mode & 0o777).to eq(0o750)
532532
end
533533

534534
it "uses Shakapacker's binstub in generated Procfiles" do

react_on_rails/spec/react_on_rails/generators/rsc_generator_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,25 @@
2727

2828
it "uses Shakapacker's watch binstub when it is present" do
2929
simulate_existing_file("bin/shakapacker-watch", "#!/usr/bin/env sh\n")
30+
File.chmod(0o755, File.join(destination_root, "bin/shakapacker-watch"))
3031

3132
Dir.chdir(destination_root) { generator.send(:add_rsc_to_procfile) }
3233

3334
assert_file "Procfile.dev" do |content|
3435
expect(content).to include("rsc-bundle: RSC_BUNDLE_ONLY=true bin/shakapacker-watch --watch")
3536
end
3637
end
38+
39+
it "uses the standard Shakapacker command when the watch binstub is not executable" do
40+
simulate_existing_file("bin/shakapacker-watch", "#!/usr/bin/env sh\n")
41+
File.chmod(0o644, File.join(destination_root, "bin/shakapacker-watch"))
42+
43+
Dir.chdir(destination_root) { generator.send(:add_rsc_to_procfile) }
44+
45+
assert_file "Procfile.dev" do |content|
46+
expect(content).to include("rsc-bundle: RSC_BUNDLE_ONLY=true bin/shakapacker --watch")
47+
end
48+
end
3749
end
3850

3951
# Unit tests for prerequisite validation

0 commit comments

Comments
 (0)