Skip to content

Commit c0bbf57

Browse files
justin808claude
andcommitted
Remove --frozen-lockfile from dummy app install after yalc
The yalc workflow modifies yarn.lock when adding packages, so we cannot use --frozen-lockfile after yalc has run. Keep --ignore-scripts to skip the preinstall hook (since yalc already ran in the previous step). This allows the install to succeed after yalc has modified the lockfile. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 97b1c0f commit c0bbf57

File tree

7 files changed

+161
-21
lines changed

7 files changed

+161
-21
lines changed

.github/workflows/pro-integration-tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ jobs:
7575
yarn && yalc publish
7676
7777
- name: Install Node modules with Yarn for Pro dummy app
78-
run: cd spec/dummy && yarn install --frozen-lockfile --ignore-scripts --no-progress --no-emoji
78+
run: cd spec/dummy && yarn install --ignore-scripts --no-progress --no-emoji
7979

8080
- name: Install Ruby Gems for Pro dummy app
8181
run: |
@@ -195,7 +195,7 @@ jobs:
195195
yarn && yalc publish
196196
197197
- name: Install Node modules with Yarn for Pro dummy app
198-
run: cd spec/dummy && yarn install --frozen-lockfile --ignore-scripts --no-progress --no-emoji
198+
run: cd spec/dummy && yarn install --ignore-scripts --no-progress --no-emoji
199199

200200
- name: Ensure minimum required Chrome version
201201
run: |
@@ -387,7 +387,7 @@ jobs:
387387
yarn && yalc publish
388388
389389
- name: Install Node modules with Yarn for Pro dummy app
390-
run: cd spec/dummy && yarn install --frozen-lockfile --ignore-scripts --no-progress --no-emoji
390+
run: cd spec/dummy && yarn install --ignore-scripts --no-progress --no-emoji
391391

392392
- name: Ensure minimum required Chrome version
393393
run: |
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
# Shakapacker precompile hook
5+
# This script runs before Shakapacker compilation in both development and production.
6+
# See: https://github.com/shakacode/shakapacker/blob/main/docs/precompile_hook.md
7+
8+
require "fileutils"
9+
10+
# Build ReScript if needed
11+
def build_rescript_if_needed
12+
# Check for both old (bsconfig.json) and new (rescript.json) config files
13+
return unless File.exist?("bsconfig.json") || File.exist?("rescript.json")
14+
15+
puts "🔧 Building ReScript..."
16+
17+
# Try to find the ReScript build command
18+
if system("command -v yarn > /dev/null 2>&1")
19+
success = system("yarn build:rescript")
20+
elsif system("command -v npm > /dev/null 2>&1")
21+
success = system("npm run build:rescript")
22+
else
23+
warn "⚠️ Warning: Neither yarn nor npm found. Skipping ReScript build."
24+
return
25+
end
26+
27+
if success
28+
puts "✅ ReScript build completed successfully"
29+
else
30+
warn "❌ ReScript build failed"
31+
exit 1
32+
end
33+
end
34+
35+
# Generate React on Rails packs if needed
36+
def generate_packs_if_needed
37+
return unless File.exist?("config/initializers/react_on_rails.rb")
38+
39+
# Check if auto-pack generation is configured
40+
config_file = File.read("config/initializers/react_on_rails.rb")
41+
return unless config_file.include?("auto_load_bundle") || config_file.include?("components_subdirectory")
42+
43+
puts "📦 Generating React on Rails packs..."
44+
45+
# Check if bundle and rake task are available
46+
bundle_available = system("command -v bundle > /dev/null 2>&1")
47+
rake_task_exists = system("bundle exec rails -T | grep -q react_on_rails:generate_packs")
48+
return unless bundle_available && rake_task_exists
49+
50+
success = system("bundle exec rails react_on_rails:generate_packs")
51+
52+
if success
53+
puts "✅ Pack generation completed successfully"
54+
else
55+
warn "❌ Pack generation failed"
56+
exit 1
57+
end
58+
end
59+
60+
# Main execution
61+
begin
62+
build_rescript_if_needed
63+
generate_packs_if_needed
64+
65+
exit 0
66+
rescue StandardError => e
67+
warn "❌ Precompile hook failed: #{e.message}"
68+
warn e.backtrace.join("\n")
69+
exit 1
70+
end

lib/generators/react_on_rails/templates/base/base/config/shakapacker.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
default: &default
55
source_path: app/javascript
66

7+
# Hook to run before compilation (e.g., for ReScript builds, pack generation)
8+
# See: https://github.com/shakacode/shakapacker/blob/main/docs/precompile_hook.md
9+
precompile_hook: bin/shakapacker-precompile-hook
10+
711
# You can have a subdirectory of the source_path, like 'packs' (recommended).
812
# Alternatively, you can use '/' to use the whole source_path directory.
913
# Notice that this is a relative path to source_path

lib/react_on_rails/dev/pack_generator.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,23 @@ def generate(verbose: false)
2525
private
2626

2727
def run_pack_generation(silent: false)
28-
# If we're already inside a Bundler context (e.g., called from bin/dev),
28+
# If we're already inside a Bundler context AND Rails is available (e.g., called from bin/dev),
2929
# we can directly require and run the task. Otherwise, use bundle exec.
30-
if defined?(Bundler)
30+
if defined?(Bundler) && rails_available?
3131
run_rake_task_directly(silent: silent)
3232
else
3333
run_via_bundle_exec(silent: silent)
3434
end
3535
end
3636

37+
def rails_available?
38+
return false unless defined?(Rails)
39+
return false unless Rails.respond_to?(:application)
40+
return false if Rails.application.nil?
41+
42+
true
43+
end
44+
3745
def run_rake_task_directly(silent: false)
3846
require "rake"
3947

lib/react_on_rails/dev/server_manager.rb

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -416,34 +416,18 @@ def run_static_development(procfile, verbose: false, route: nil)
416416
route: route
417417
)
418418

419-
build_rescript_if_needed
420419
PackGenerator.generate(verbose: verbose)
421420
ProcessManager.ensure_procfile(procfile)
422421
ProcessManager.run_with_process_manager(procfile)
423422
end
424423

425424
def run_development(procfile, verbose: false, route: nil)
426425
print_procfile_info(procfile, route: route)
427-
build_rescript_if_needed
428426
PackGenerator.generate(verbose: verbose)
429427
ProcessManager.ensure_procfile(procfile)
430428
ProcessManager.run_with_process_manager(procfile)
431429
end
432430

433-
def build_rescript_if_needed
434-
# Check for both old (bsconfig.json) and new (rescript.json) config files
435-
return unless File.exist?("bsconfig.json") || File.exist?("rescript.json")
436-
437-
print "🔧 Building ReScript... "
438-
success = system("yarn build:rescript > /dev/null 2>&1")
439-
puts success ? "✅" : "❌"
440-
441-
return if success
442-
443-
puts "❌ ReScript build failed"
444-
exit 1
445-
end
446-
447431
def print_server_info(title, features, port = 3000, route: nil)
448432
puts title
449433
features.each { |feature| puts " - #{feature}" }
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
# Shakapacker precompile hook
5+
# This script runs before Shakapacker compilation in both development and production.
6+
# See: https://github.com/shakacode/shakapacker/blob/main/docs/precompile_hook.md
7+
8+
require "fileutils"
9+
10+
# Build ReScript if needed
11+
def build_rescript_if_needed
12+
# Check for both old (bsconfig.json) and new (rescript.json) config files
13+
return unless File.exist?("bsconfig.json") || File.exist?("rescript.json")
14+
15+
puts "🔧 Building ReScript..."
16+
17+
# Try to find the ReScript build command
18+
if system("command -v yarn > /dev/null 2>&1")
19+
success = system("yarn build:rescript")
20+
elsif system("command -v npm > /dev/null 2>&1")
21+
success = system("npm run build:rescript")
22+
else
23+
warn "⚠️ Warning: Neither yarn nor npm found. Skipping ReScript build."
24+
return
25+
end
26+
27+
if success
28+
puts "✅ ReScript build completed successfully"
29+
else
30+
warn "❌ ReScript build failed"
31+
exit 1
32+
end
33+
end
34+
35+
# Generate React on Rails packs if needed
36+
def generate_packs_if_needed
37+
return unless File.exist?("config/initializers/react_on_rails.rb")
38+
39+
# Check if auto-pack generation is configured
40+
config_file = File.read("config/initializers/react_on_rails.rb")
41+
return unless config_file.include?("auto_load_bundle") || config_file.include?("components_subdirectory")
42+
43+
puts "📦 Generating React on Rails packs..."
44+
45+
# Check if bundle and rake task are available
46+
bundle_available = system("command -v bundle > /dev/null 2>&1")
47+
rake_task_exists = system("bundle exec rails -T | grep -q react_on_rails:generate_packs")
48+
return unless bundle_available && rake_task_exists
49+
50+
success = system("bundle exec rails react_on_rails:generate_packs")
51+
52+
if success
53+
puts "✅ Pack generation completed successfully"
54+
else
55+
warn "❌ Pack generation failed"
56+
exit 1
57+
end
58+
end
59+
60+
# Main execution
61+
begin
62+
build_rescript_if_needed
63+
generate_packs_if_needed
64+
65+
exit 0
66+
rescue StandardError => e
67+
warn "❌ Precompile hook failed: #{e.message}"
68+
warn e.backtrace.join("\n")
69+
exit 1
70+
end

spec/dummy/config/shakapacker.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ default: &default
55
source_entry_path: packs
66
public_root_path: public
77

8+
# Hook to run before compilation (e.g., for ReScript builds, pack generation)
9+
# See: https://github.com/shakacode/shakapacker/blob/main/docs/precompile_hook.md
10+
precompile_hook: bin/shakapacker-precompile-hook
11+
812
cache_path: tmp/cache/shakapacker
913
webpack_compile_output: false
1014
ensure_consistent_versioning: true

0 commit comments

Comments
 (0)