react_on_rails 16.2.0.test.6 → 16.2.0.test.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 96c65c2ad30fb286eb0f181994d7201f57a386c0370363f6d3356c7d2e9a1317
4
- data.tar.gz: 83f9308811c6f328296ad9a68232a7b7fd104ff46857ea239c621cedc7e285f8
3
+ metadata.gz: 3f7e9fd77765f52ade236e021ec85676e820ec0a3579698d97dffc9351fc9f9d
4
+ data.tar.gz: 818fca7c6a6ea3571972b7a80af2c39c8551a0ee96c9f26a156585bdfcfda61d
5
5
  SHA512:
6
- metadata.gz: 796d8a27960b07fe2234e19be037ccca56dd85d5aebe9153d59fd26a4a560c5f504d55e8f3984eee545fc5deb159154abe019eced470da28c037352d45c19af9
7
- data.tar.gz: 9ed658b9e921a68ab1dad98d01a9197b3c15b96bd634f4973f781682243f2b7da641c0efb8372bcae52a1976676f209b9d41e37ee70daadb40b9bd691b3cfe0f
6
+ metadata.gz: b74d821039717f5396a474b0b580536321fbe3c8f1d63ca6bdb209a31232ce2e2b8dc104a57a18937ba11ddd4738e3e538c55e97549257c7f1535449cc244329
7
+ data.tar.gz: ab07b316a31ca4ba7e20ffa9b4c8d15b0614217ee2685b047f2e88756c98c15486d46bee0c4560821d46c6579a1d2f2cd736e8e73be414f5742e8db41d5fae3f
data/.rubocop.yml CHANGED
@@ -1,36 +1,16 @@
1
- # This is the configuration used to check the rubocop source code.
2
- # Check out: https://github.com/bbatsov/rubocop
3
- require:
4
- - rubocop-performance
5
- - rubocop-rspec
1
+ # Inherits from root config
2
+ inherit_from: ../.rubocop.yml
3
+
4
+ # Merge Exclude arrays with parent instead of replacing them
5
+ inherit_mode:
6
+ merge:
7
+ - Exclude
6
8
 
7
9
  AllCops:
8
- NewCops: enable
9
- DisplayCopNames: true
10
- TargetRubyVersion: 3.0.0
11
10
  SuggestExtensions: false
12
11
 
13
- Include:
14
- - '**/Rakefile'
15
- - '**/config.ru'
16
- - 'Gemfile'
17
- - '**/*.rb'
18
- - '**/*.rake'
19
-
20
12
  Exclude:
21
- - '**/*.js'
22
- - '**/node_modules/**/*'
23
- - '**/public/**/*'
24
- - '**/tmp/**/*'
25
- - 'coverage/**/*'
26
- - 'gen-examples/examples/**/*'
27
- - 'node_modules/**/*'
28
- - '../react_on_rails_pro/**/*' # Exclude pro package (has its own linting)
29
13
  - 'spec/dummy/bin/*'
30
- - 'spec/fixtures/**/*'
31
- - 'spec/react_on_rails/dummy-for-generators/**/*'
32
- - 'tmp/**/*'
33
- - 'vendor/**/*'
34
14
 
35
15
  Naming/FileName:
36
16
  Exclude:
@@ -38,24 +18,6 @@ Naming/FileName:
38
18
  - '**/Rakefile'
39
19
  - '**/Steepfile'
40
20
 
41
- Layout/LineLength:
42
- Max: 120
43
-
44
- Style/StringLiterals:
45
- EnforcedStyle: double_quotes
46
-
47
- Style/Documentation:
48
- Enabled: false
49
-
50
- Style/HashEachMethods:
51
- Enabled: true
52
-
53
- Style/HashTransformKeys:
54
- Enabled: true
55
-
56
- Style/HashTransformValues:
57
- Enabled: true
58
-
59
21
  Lint/AssignmentInCondition:
60
22
  Exclude:
61
23
  - 'spec/dummy/bin/spring'
@@ -66,33 +28,19 @@ Lint/SuppressedException:
66
28
  - 'spec/dummy/bin/rake'
67
29
 
68
30
  Metrics/AbcSize:
69
- Max: 28
70
31
  Exclude:
71
32
  - 'lib/generators/react_on_rails/install_generator.rb' # Generator setup methods require comprehensive error handling
72
33
 
73
- Metrics/CyclomaticComplexity:
74
- Max: 7
75
-
76
- Metrics/PerceivedComplexity:
77
- Max: 10
78
-
79
34
  Metrics/ClassLength:
80
- Max: 150
81
35
  Exclude:
82
36
  - 'lib/generators/react_on_rails/base_generator.rb' # Generator complexity justified
83
37
  - 'lib/react_on_rails/dev/server_manager.rb' # Dev tool with comprehensive help system
84
38
 
85
- Metrics/ParameterLists:
86
- Max: 5
87
- CountKeywordArgs: false
88
-
89
39
  Metrics/MethodLength:
90
- Max: 41
91
40
  Exclude:
92
41
  - 'lib/generators/react_on_rails/install_generator.rb' # Generator setup methods require comprehensive error handling
93
42
 
94
43
  Metrics/ModuleLength:
95
- Max: 180
96
44
  Exclude:
97
45
  - 'spec/react_on_rails/engine_spec.rb' # Comprehensive engine tests require many examples
98
46
 
@@ -107,18 +55,6 @@ RSpec/AnyInstance:
107
55
  - 'spec/react_on_rails/binstubs/dev_static_spec.rb'
108
56
  - 'spec/react_on_rails/dev/**/*_spec.rb' # Dev module tests require system mocking
109
57
 
110
- RSpec/DescribeClass:
111
- Enabled: false
112
-
113
- RSpec/ExampleLength:
114
- Enabled: false
115
-
116
- RSpec/MessageSpies:
117
- Enabled: false
118
-
119
- RSpec/NestedGroups:
120
- Max: 4
121
-
122
58
  RSpec/BeforeAfterAll:
123
59
  Exclude:
124
60
  - 'spec/react_on_rails/generators/dev_tests_generator_spec.rb'
@@ -127,19 +63,10 @@ RSpec/BeforeAfterAll:
127
63
  - 'spec/react_on_rails/binstubs/dev_static_spec.rb'
128
64
  - 'spec/react_on_rails/dev/**/*_spec.rb' # Dev module tests require global setup
129
65
 
130
- RSpec/MessageChain:
131
- Enabled: false
132
-
133
- RSpec/MultipleExpectations:
134
- Enabled: false
135
-
136
66
  RSpec/MultipleDescribes:
137
67
  Exclude:
138
68
  - 'spec/dummy/spec/system/integration_spec.rb'
139
69
 
140
- RSpec/MultipleMemoizedHelpers:
141
- Max: 12
142
-
143
70
  Style/GlobalVars:
144
71
  Exclude:
145
72
  - 'spec/dummy/config/environments/development.rb'
@@ -156,4 +83,3 @@ RSpec/InstanceVariable:
156
83
  RSpec/StubbedMock:
157
84
  Exclude:
158
85
  - 'spec/react_on_rails/dev/**/*_spec.rb' # Dev module tests use mixed stub/mock patterns
159
-
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ eval_gemfile File.expand_path("../Gemfile.shared_dev_dependencies", __dir__)
4
+
3
5
  gem "shakapacker", "9.4.0"
4
6
  gem "bootsnap", require: false
5
7
  gem "rails", "~> 7.1"
@@ -35,9 +37,6 @@ group :development, :test do
35
37
  gem "pry-rescue"
36
38
  gem "rbs", require: false
37
39
  gem "steep", require: false
38
- gem "rubocop", "1.61.0", require: false
39
- gem "rubocop-performance", "~>1.20.0", require: false
40
- gem "rubocop-rspec", "~>2.26", require: false
41
40
  gem "spring", "~> 4.0"
42
41
  gem "lefthook", require: false
43
42
  # Added for Ruby 3.5+ compatibility to silence warnings
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- react_on_rails (16.2.0.test.6)
4
+ react_on_rails (16.2.0.test.7)
5
5
  addressable
6
6
  connection_pool
7
7
  execjs (~> 2.5)
@@ -31,7 +31,8 @@ module ReactOnRails
31
31
 
32
32
  def add_test_related_gems_to_gemfile
33
33
  gem("rspec-rails", group: :test)
34
- gem("chromedriver-helper", group: :test)
34
+ # NOTE: chromedriver-helper was deprecated in 2019. Modern selenium-webdriver (4.x)
35
+ # and GitHub Actions have built-in driver management, so no driver helper is needed.
35
36
  gem("coveralls", require: false)
36
37
  end
37
38
 
@@ -124,4 +124,75 @@ module GeneratorHelper
124
124
  true
125
125
  end
126
126
  end
127
+
128
+ # Check if SWC is configured as the JavaScript transpiler in shakapacker.yml
129
+ #
130
+ # @return [Boolean] true if SWC is configured or should be used by default
131
+ #
132
+ # Detection logic:
133
+ # 1. If shakapacker.yml exists and specifies javascript_transpiler: parse it
134
+ # 2. For Shakapacker 9.3.0+, SWC is the default if not specified
135
+ # 3. Returns true for fresh installations (SWC is recommended default)
136
+ #
137
+ # @note This method is used to determine whether to install SWC dependencies
138
+ # (@swc/core, swc-loader) instead of Babel dependencies during generation.
139
+ #
140
+ # @note Caching: The result is memoized for the lifetime of the generator instance.
141
+ # If shakapacker.yml changes during generator execution (unlikely), the cached
142
+ # value will not update. This is acceptable since generators run quickly.
143
+ def using_swc?
144
+ return @using_swc if defined?(@using_swc)
145
+
146
+ @using_swc = detect_swc_configuration
147
+ end
148
+
149
+ private
150
+
151
+ def detect_swc_configuration
152
+ shakapacker_yml_path = File.join(destination_root, "config/shakapacker.yml")
153
+
154
+ if File.exist?(shakapacker_yml_path)
155
+ config = parse_shakapacker_yml(shakapacker_yml_path)
156
+ transpiler = config.dig("default", "javascript_transpiler")
157
+
158
+ # Explicit configuration takes precedence
159
+ return transpiler == "swc" if transpiler
160
+
161
+ # For Shakapacker 9.3.0+, SWC is the default
162
+ return shakapacker_version_9_3_or_higher?
163
+ end
164
+
165
+ # Fresh install: SWC is recommended default for Shakapacker 9.3.0+
166
+ shakapacker_version_9_3_or_higher?
167
+ end
168
+
169
+ def parse_shakapacker_yml(path)
170
+ require "yaml"
171
+ # Use safe_load_file for security (defense-in-depth, even though this is user's own config)
172
+ # permitted_classes: [Symbol] allows symbol keys which shakapacker.yml may use
173
+ # aliases: true allows YAML anchors (&default, *default) commonly used in Rails configs
174
+ YAML.safe_load_file(path, permitted_classes: [Symbol], aliases: true)
175
+ rescue ArgumentError
176
+ # Older Psych versions don't support all parameters - try without aliases
177
+ begin
178
+ YAML.safe_load_file(path, permitted_classes: [Symbol])
179
+ rescue ArgumentError
180
+ # Very old Psych - fall back to safe_load with File.read
181
+ YAML.safe_load(File.read(path), permitted_classes: [Symbol]) # rubocop:disable Style/YAMLFileRead
182
+ end
183
+ rescue StandardError
184
+ # If we can't parse the file, return empty config
185
+ {}
186
+ end
187
+
188
+ # Check if Shakapacker 9.3.0 or higher is available
189
+ # This version made SWC the default JavaScript transpiler
190
+ def shakapacker_version_9_3_or_higher?
191
+ return true unless defined?(ReactOnRails::PackerUtils)
192
+
193
+ ReactOnRails::PackerUtils.shakapacker_version_requirement_met?("9.3.0")
194
+ rescue StandardError
195
+ # If we can't determine version, assume latest (which uses SWC)
196
+ true
197
+ end
127
198
  end
@@ -99,6 +99,13 @@ module ReactOnRails
99
99
  @types/react-dom
100
100
  ].freeze
101
101
 
102
+ # SWC transpiler dependencies (for Shakapacker 9.3.0+ default transpiler)
103
+ # SWC is ~20x faster than Babel and is the default for new Shakapacker installations
104
+ SWC_DEPENDENCIES = %w[
105
+ @swc/core
106
+ swc-loader
107
+ ].freeze
108
+
102
109
  private
103
110
 
104
111
  def setup_js_dependencies
@@ -118,6 +125,8 @@ module ReactOnRails
118
125
  add_css_dependencies
119
126
  # Rspack dependencies are only added when --rspack flag is used
120
127
  add_rspack_dependencies if respond_to?(:options) && options&.rspack?
128
+ # SWC dependencies are only added when SWC is the configured transpiler
129
+ add_swc_dependencies if using_swc?
121
130
  # Dev dependencies vary based on bundler choice
122
131
  add_dev_dependencies
123
132
  end
@@ -232,6 +241,26 @@ module ReactOnRails
232
241
  MSG
233
242
  end
234
243
 
244
+ def add_swc_dependencies
245
+ puts "Installing SWC transpiler dependencies (20x faster than Babel)..."
246
+ return if add_packages(SWC_DEPENDENCIES, dev: true)
247
+
248
+ GeneratorMessages.add_warning(<<~MSG.strip)
249
+ ⚠️ Failed to add SWC dependencies.
250
+
251
+ SWC is the default JavaScript transpiler for Shakapacker 9.3.0+.
252
+ You can install them manually by running:
253
+ npm install --save-dev #{SWC_DEPENDENCIES.join(' ')}
254
+ MSG
255
+ rescue StandardError => e
256
+ GeneratorMessages.add_warning(<<~MSG.strip)
257
+ ⚠️ Error adding SWC dependencies: #{e.message}
258
+
259
+ You can install them manually by running:
260
+ npm install --save-dev #{SWC_DEPENDENCIES.join(' ')}
261
+ MSG
262
+ end
263
+
235
264
  def add_typescript_dependencies
236
265
  puts "Installing TypeScript dependencies..."
237
266
  return if add_packages(TYPESCRIPT_DEPENDENCIES, dev: true)
@@ -61,7 +61,6 @@ class BundlerSwitcher
61
61
  puts "✅ Updated assets_bundler to '#{@target_bundler}'"
62
62
  end
63
63
 
64
- # rubocop:disable Metrics/CyclomaticComplexity
65
64
  def update_dependencies
66
65
  puts "📦 Updating package.json dependencies..."
67
66
 
@@ -86,9 +85,7 @@ class BundlerSwitcher
86
85
  puts "✅ Removed #{@target_bundler == 'rspack' ? 'webpack' : 'rspack'} dependencies"
87
86
  File.write(package_json_path, JSON.pretty_generate(package_json))
88
87
  end
89
- # rubocop:enable Metrics/CyclomaticComplexity
90
88
 
91
- # rubocop:disable Metrics/CyclomaticComplexity
92
89
  def install_dependencies
93
90
  puts "📥 Installing #{@target_bundler} dependencies..."
94
91
 
@@ -123,7 +120,6 @@ class BundlerSwitcher
123
120
 
124
121
  puts "✅ Installed #{@target_bundler} dependencies"
125
122
  end
126
- # rubocop:enable Metrics/CyclomaticComplexity
127
123
 
128
124
  def detect_package_manager
129
125
  return "yarn" if File.exist?("yarn.lock")
@@ -468,7 +468,6 @@ module ReactOnRails
468
468
  check_npm_wildcards
469
469
  end
470
470
 
471
- # rubocop:disable Metrics/CyclomaticComplexity
472
471
  def check_gem_wildcards
473
472
  gemfile_path = ENV["BUNDLE_GEMFILE"] || "Gemfile"
474
473
  return unless File.exist?(gemfile_path)
@@ -490,9 +489,7 @@ module ReactOnRails
490
489
  # Ignore errors reading Gemfile
491
490
  end
492
491
  end
493
- # rubocop:enable Metrics/CyclomaticComplexity
494
492
 
495
- # rubocop:disable Metrics/CyclomaticComplexity
496
493
  def check_npm_wildcards
497
494
  return unless File.exist?("package.json")
498
495
 
@@ -514,7 +511,6 @@ module ReactOnRails
514
511
  # Ignore other errors
515
512
  end
516
513
  end
517
- # rubocop:enable Metrics/CyclomaticComplexity
518
514
 
519
515
  def check_key_configuration_files
520
516
  files_to_check = {
@@ -538,7 +534,6 @@ module ReactOnRails
538
534
  check_server_rendering_engine
539
535
  end
540
536
 
541
- # rubocop:disable Metrics/CyclomaticComplexity
542
537
  def check_layout_files
543
538
  layout_files = Dir.glob("app/views/layouts/**/*.erb")
544
539
  return if layout_files.empty?
@@ -565,7 +560,6 @@ module ReactOnRails
565
560
  end
566
561
  end
567
562
  end
568
- # rubocop:enable Metrics/CyclomaticComplexity
569
563
 
570
564
  # rubocop:disable Metrics/CyclomaticComplexity
571
565
  def check_server_rendering_engine
@@ -603,7 +597,6 @@ module ReactOnRails
603
597
  end
604
598
  # rubocop:enable Metrics/CyclomaticComplexity
605
599
 
606
- # rubocop:disable Metrics/CyclomaticComplexity
607
600
  def check_shakapacker_configuration_details
608
601
  return unless File.exist?("config/shakapacker.yml")
609
602
 
@@ -632,7 +625,6 @@ module ReactOnRails
632
625
  checker.add_warning(" ⚠️ Could not run 'rake shakapacker:info': #{e.message}")
633
626
  end
634
627
  end
635
- # rubocop:enable Metrics/CyclomaticComplexity
636
628
 
637
629
  def check_react_on_rails_configuration_details
638
630
  check_react_on_rails_initializer
@@ -5,7 +5,9 @@ require "English"
5
5
  module ReactOnRails
6
6
  module GitUtils
7
7
  def self.uncommitted_changes?(message_handler, git_installed: true)
8
- return false if ENV["COVERAGE"] == "true"
8
+ # Skip check in CI environments - CI often makes temporary modifications
9
+ # (e.g., script/convert for minimum version testing) before running generators
10
+ return false if ENV["CI"] == "true" || ENV["COVERAGE"] == "true"
9
11
 
10
12
  status = `git status --porcelain`
11
13
  return false if git_installed && status&.empty?
@@ -9,11 +9,10 @@ module ReactOnRails
9
9
  class RubyEmbeddedJavaScript
10
10
  class << self
11
11
  def reset_pool
12
- options = {
12
+ @js_context_pool = ConnectionPool.new(
13
13
  size: ReactOnRails.configuration.server_renderer_pool_size,
14
14
  timeout: ReactOnRails.configuration.server_renderer_timeout
15
- }
16
- @js_context_pool = ConnectionPool.new(options) { create_js_context }
15
+ ) { create_js_context }
17
16
  end
18
17
 
19
18
  def reset_pool_if_server_bundle_was_modified
@@ -50,7 +49,6 @@ module ReactOnRails
50
49
  # Note, js_code does not have to be based on React.
51
50
  # js_code MUST RETURN json stringify Object
52
51
  # Calling code will probably call 'html_safe' on return value before rendering to the view.
53
- # rubocop:disable Metrics/CyclomaticComplexity
54
52
  def exec_server_render_js(js_code, render_options, js_evaluator = nil)
55
53
  js_evaluator ||= self
56
54
  if render_options.trace
@@ -87,7 +85,6 @@ module ReactOnRails
87
85
  # We need to parse each chunk and replay the console messages.
88
86
  result.transform { |chunk| parse_result_and_replay_console_messages(chunk, render_options) }
89
87
  end
90
- # rubocop:enable Metrics/CyclomaticComplexity
91
88
 
92
89
  def trace_js_code_used(msg, js_code, file_name = "tmp/server-generated.js", force: false)
93
90
  return unless ReactOnRails.configuration.trace || force
@@ -203,7 +203,7 @@ module ReactOnRails
203
203
  add_warning("⚠️ Could not parse package.json")
204
204
  end
205
205
 
206
- def check_package_version_sync # rubocop:disable Metrics/CyclomaticComplexity
206
+ def check_package_version_sync
207
207
  return unless File.exist?("package.json")
208
208
 
209
209
  begin
@@ -540,7 +540,6 @@ module ReactOnRails
540
540
  MSG
541
541
  end
542
542
 
543
- # rubocop:disable Metrics/CyclomaticComplexity
544
543
  def check_gemfile_version_patterns
545
544
  gemfile_path = ENV["BUNDLE_GEMFILE"] || "Gemfile"
546
545
  return unless File.exist?(gemfile_path)
@@ -571,9 +570,7 @@ module ReactOnRails
571
570
  # Ignore errors reading Gemfile
572
571
  end
573
572
  end
574
- # rubocop:enable Metrics/CyclomaticComplexity
575
573
 
576
- # rubocop:disable Metrics/CyclomaticComplexity
577
574
  def report_dependency_versions(package_json)
578
575
  all_deps = package_json["dependencies"]&.merge(package_json["devDependencies"] || {}) || {}
579
576
 
@@ -590,7 +587,6 @@ module ReactOnRails
590
587
  add_success("✅ React DOM #{react_dom_version}")
591
588
  end
592
589
  end
593
- # rubocop:enable Metrics/CyclomaticComplexity
594
590
 
595
591
  def report_shakapacker_version
596
592
  return unless File.exist?("Gemfile.lock")
@@ -98,9 +98,12 @@ module ReactOnRails
98
98
  exitstatus: #{status.exitstatus}#{stdout_msg}#{stderr_msg}
99
99
  MSG
100
100
 
101
- puts wrap_message(msg)
102
- puts ""
103
- puts default_troubleshooting_section
101
+ # Use warn to ensure output is visible in CI logs (goes to stderr)
102
+ # and flush immediately before calling exit!
103
+ warn wrap_message(msg)
104
+ warn ""
105
+ warn default_troubleshooting_section
106
+ $stderr.flush
104
107
 
105
108
  # Rspec catches exit without! in the exit callbacks
106
109
  exit!(1)
@@ -467,7 +470,6 @@ module ReactOnRails
467
470
  #
468
471
  # @example Absolute paths outside Rails.root (edge case)
469
472
  # normalize_to_relative_path("/other/path/bundles") # => "/other/path/bundles"
470
- # rubocop:disable Metrics/CyclomaticComplexity
471
473
  def self.normalize_to_relative_path(path)
472
474
  return nil if path.nil?
473
475
 
@@ -495,7 +497,6 @@ module ReactOnRails
495
497
  path_str
496
498
  end
497
499
  end
498
- # rubocop:enable Metrics/CyclomaticComplexity
499
500
 
500
501
  def self.default_troubleshooting_section
501
502
  <<~DEFAULT
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ReactOnRails
4
- VERSION = "16.2.0.test.6"
4
+ VERSION = "16.2.0.test.7"
5
5
  end
@@ -338,7 +338,6 @@ module ReactOnRails
338
338
  private
339
339
 
340
340
  # Resolve version from lockfiles if available, otherwise use package.json version
341
- # rubocop:disable Metrics/CyclomaticComplexity
342
341
  def resolve_version(package_json_version, package_name)
343
342
  # If package.json specifies a local path or URL, don't try to resolve from lockfiles
344
343
  # Lockfiles may contain placeholder versions like "0.0.0" for local links
@@ -359,7 +358,6 @@ module ReactOnRails
359
358
  # Fall back to package.json version
360
359
  package_json_version
361
360
  end
362
- # rubocop:enable Metrics/CyclomaticComplexity
363
361
 
364
362
  # Check if a version string represents a local path or URL
365
363
  def local_path_or_url_version?(version)
@@ -14,12 +14,49 @@ module ReactOnRails
14
14
  @all ||= { shakapacker_examples: [] }
15
15
  end
16
16
 
17
- attr_reader :packer_type, :name, :generator_options
17
+ # Supported React versions for compatibility testing
18
+ # Keys are major version strings, values are specific version to pin to (nil = latest)
19
+ REACT_VERSIONS = {
20
+ "16" => "16.14.0",
21
+ "17" => "17.0.2",
22
+ "18" => "18.0.0",
23
+ "19" => nil # nil means use latest (default)
24
+ }.freeze
25
+
26
+ # Supported React major versions (we test with latest patch of each)
27
+ MINIMUM_SUPPORTED_REACT_MAJOR_VERSION = "16"
28
+ LATEST_REACT_MAJOR_VERSION = "19"
29
+
30
+ # Minimum Shakapacker version for compatibility testing
31
+ MINIMUM_SHAKAPACKER_VERSION = "8.2.0"
32
+
33
+ attr_reader :packer_type, :name, :generator_options, :react_version
34
+
35
+ # Returns true if this example uses a pinned (non-latest) React version
36
+ def pinned_react_version?
37
+ !react_version.nil?
38
+ end
39
+
40
+ # Returns the actual React version string to use
41
+ def react_version_string
42
+ return nil unless react_version
43
+
44
+ REACT_VERSIONS[react_version.to_s] || react_version
45
+ end
18
46
 
19
- def initialize(packer_type: nil, name: nil, generator_options: nil)
47
+ def initialize(packer_type: nil, name: nil, generator_options: nil, react_version: nil)
20
48
  @packer_type = packer_type
21
49
  @name = name
22
50
  @generator_options = generator_options
51
+ @react_version = react_version
52
+
53
+ # Validate react_version is a known version to catch configuration errors early
54
+ if @react_version && !REACT_VERSIONS.key?(@react_version.to_s)
55
+ valid_versions = REACT_VERSIONS.keys.join(", ")
56
+ raise ArgumentError, "Invalid react_version '#{@react_version}' for example '#{name}'. " \
57
+ "Valid versions: #{valid_versions}"
58
+ end
59
+
23
60
  self.class.all[packer_type.to_sym] << self
24
61
  end
25
62
 
@@ -1,4 +1,23 @@
1
+ # Example Type Configuration for React on Rails Generator Tests
2
+ #
3
+ # CI Test Coverage:
4
+ # -----------------
5
+ # - Latest CI (all PRs): Runs shakapacker_examples_latest (React 19, Shakapacker 9.x)
6
+ # Examples: basic, basic-server-rendering, redux, redux-server-rendering
7
+ #
8
+ # - Pinned CI (master): Runs shakapacker_examples_pinned (React 16, 17, 18 with Shakapacker 8.2.0)
9
+ # Examples: basic-react16, basic-server-rendering-react16,
10
+ # basic-react17, basic-server-rendering-react17,
11
+ # basic-react18, basic-server-rendering-react18
12
+ #
13
+ # Terminology:
14
+ # - "Latest" = Current React version (19) with latest Shakapacker (9.x)
15
+ # - "Pinned" = Specific older React versions (16, 17, 18) for backward compatibility testing
16
+ #
17
+ # Note: We support React 16+ but test with latest patch of each major version.
18
+
1
19
  example_type_data:
20
+ # Latest versions (React 19, Shakapacker 9.x)
2
21
  - name: basic
3
22
  generator_options: ''
4
23
  - name: basic-server-rendering
@@ -7,3 +26,27 @@ example_type_data:
7
26
  generator_options: --redux
8
27
  - name: redux-server-rendering
9
28
  generator_options: --redux --example-server-rendering
29
+
30
+ # React 18 compatibility tests (uses Root API introduced in React 18)
31
+ - name: basic-react18
32
+ generator_options: ''
33
+ react_version: '18'
34
+ - name: basic-server-rendering-react18
35
+ generator_options: --example-server-rendering
36
+ react_version: '18'
37
+
38
+ # React 17 compatibility tests (legacy render/hydrate API)
39
+ - name: basic-react17
40
+ generator_options: ''
41
+ react_version: '17'
42
+ - name: basic-server-rendering-react17
43
+ generator_options: --example-server-rendering
44
+ react_version: '17'
45
+
46
+ # React 16 compatibility tests (oldest supported legacy API)
47
+ - name: basic-react16
48
+ generator_options: ''
49
+ react_version: '16'
50
+ - name: basic-server-rendering-react16
51
+ generator_options: --example-server-rendering
52
+ react_version: '16'
@@ -82,7 +82,10 @@ namespace :run_rspec do
82
82
  puts "Creating #{example_type.rspec_task_name} task"
83
83
  desc "Runs RSpec for #{example_type.name_pretty} only"
84
84
  task example_type.rspec_task_name_short => example_type.gen_task_name do
85
- run_tests_in(File.join(examples_dir, example_type.name)) # have to use relative path
85
+ # Use unbundled mode for pinned React version examples to ensure the example app's
86
+ # Gemfile and gem versions are used, not the parent workspace's bundle
87
+ run_tests_in(File.join(examples_dir, example_type.name),
88
+ unbundled: example_type.pinned_react_version?)
86
89
  end
87
90
  end
88
91
 
@@ -91,6 +94,52 @@ namespace :run_rspec do
91
94
  ExampleType.all[:shakapacker_examples].each { |example_type| Rake::Task[example_type.rspec_task_name].invoke }
92
95
  end
93
96
 
97
+ # Helper methods for filtering examples by React version
98
+ def latest_examples
99
+ ExampleType.all[:shakapacker_examples].reject(&:pinned_react_version?)
100
+ end
101
+
102
+ def react18_examples
103
+ ExampleType.all[:shakapacker_examples].select { |e| e.react_version == "18" }
104
+ end
105
+
106
+ def react17_examples
107
+ ExampleType.all[:shakapacker_examples].select { |e| e.react_version == "17" }
108
+ end
109
+
110
+ def react16_examples
111
+ ExampleType.all[:shakapacker_examples].select { |e| e.react_version == "16" }
112
+ end
113
+
114
+ def pinned_version_examples
115
+ ExampleType.all[:shakapacker_examples].select(&:pinned_react_version?)
116
+ end
117
+
118
+ desc "Runs Rspec for latest version example apps only (React 19, Shakapacker 9.x)"
119
+ task shakapacker_examples_latest: latest_examples.map(&:gen_task_name) do
120
+ latest_examples.each { |example_type| Rake::Task[example_type.rspec_task_name].invoke }
121
+ end
122
+
123
+ desc "Runs Rspec for React 18 example apps only (Shakapacker 8.2.0)"
124
+ task shakapacker_examples_react18: react18_examples.map(&:gen_task_name) do
125
+ react18_examples.each { |example_type| Rake::Task[example_type.rspec_task_name].invoke }
126
+ end
127
+
128
+ desc "Runs Rspec for React 17 example apps only (legacy render API)"
129
+ task shakapacker_examples_react17: react17_examples.map(&:gen_task_name) do
130
+ react17_examples.each { |example_type| Rake::Task[example_type.rspec_task_name].invoke }
131
+ end
132
+
133
+ desc "Runs Rspec for React 16 example apps only (oldest supported legacy API)"
134
+ task shakapacker_examples_react16: react16_examples.map(&:gen_task_name) do
135
+ react16_examples.each { |example_type| Rake::Task[example_type.rspec_task_name].invoke }
136
+ end
137
+
138
+ desc "Runs Rspec for all pinned version example apps (React 16, 17, and 18)"
139
+ task shakapacker_examples_pinned: pinned_version_examples.map(&:gen_task_name) do
140
+ pinned_version_examples.each { |example_type| Rake::Task[example_type.rspec_task_name].invoke }
141
+ end
142
+
94
143
  Coveralls::RakeTask.new if ENV["USE_COVERALLS"] == "TRUE"
95
144
 
96
145
  desc "run all tests no examples"
@@ -139,11 +188,23 @@ end
139
188
  # If string is passed and it's not absolute, it's converted relative to root of the gem.
140
189
  # TEST_ENV_COMMAND_NAME is used to make SimpleCov.command_name unique in order to
141
190
  # prevent a name collision. Defaults to the given directory's name.
191
+ # Options:
192
+ # :command_name - name for SimpleCov (default: dir basename)
193
+ # :rspec_args - additional rspec arguments (default: "")
194
+ # :env_vars - additional environment variables (default: "")
195
+ # :unbundled - run with unbundled_sh_in_dir for Bundler isolation (default: false)
196
+ # This is required for pinned version examples because they have different
197
+ # gem versions (e.g., Shakapacker 8.2.0) pinned in their Gemfile than the
198
+ # parent workspace (Shakapacker 9.x). Without bundle isolation, Bundler
199
+ # would inherit the parent's gem resolution and use the wrong versions.
200
+ # Latest version examples don't need this because they use the same versions
201
+ # as the parent workspace.
142
202
  def run_tests_in(dir, options = {})
143
203
  path = calc_path(dir)
144
204
 
145
205
  command_name = options.fetch(:command_name, path.basename)
146
206
  rspec_args = options.fetch(:rspec_args, "")
207
+ unbundled = options.fetch(:unbundled, false)
147
208
 
148
209
  # Build environment variables as an array for proper spacing
149
210
  env_tokens = []
@@ -152,5 +213,11 @@ def run_tests_in(dir, options = {})
152
213
  env_tokens << "COVERAGE=true" if ENV["USE_COVERALLS"]
153
214
 
154
215
  env_vars = env_tokens.join(" ")
155
- sh_in_dir(path.realpath, "#{env_vars} bundle exec rspec #{rspec_args}")
216
+ command = "#{env_vars} bundle exec rspec #{rspec_args}"
217
+
218
+ if unbundled
219
+ unbundled_sh_in_dir(path.realpath, command)
220
+ else
221
+ sh_in_dir(path.realpath, command)
222
+ end
156
223
  end
@@ -8,6 +8,7 @@
8
8
  require "yaml"
9
9
  require "rails/version"
10
10
  require "pathname"
11
+ require "json"
11
12
 
12
13
  require_relative "example_type"
13
14
  require_relative "task_helpers"
@@ -15,8 +16,89 @@ require_relative "task_helpers"
15
16
  namespace :shakapacker_examples do # rubocop:disable Metrics/BlockLength
16
17
  include ReactOnRails::TaskHelpers
17
18
 
19
+ # Updates React-related dependencies to a specific version
20
+ def update_react_dependencies(deps, react_version)
21
+ return unless deps
22
+
23
+ deps["react"] = react_version
24
+ deps["react-dom"] = react_version
25
+ end
26
+
27
+ # Updates Shakapacker to minimum supported version in either dependencies or devDependencies
28
+ def update_shakapacker_dependency(deps, dev_deps)
29
+ if dev_deps&.key?("shakapacker")
30
+ dev_deps["shakapacker"] = ExampleType::MINIMUM_SHAKAPACKER_VERSION
31
+ elsif deps&.key?("shakapacker")
32
+ deps["shakapacker"] = ExampleType::MINIMUM_SHAKAPACKER_VERSION
33
+ end
34
+ end
35
+
36
+ # Updates dependencies in package.json to use specific React version
37
+ def update_package_json_for_react_version(package_json_path, react_version)
38
+ return unless File.exist?(package_json_path)
39
+
40
+ begin
41
+ package_json = JSON.parse(File.read(package_json_path))
42
+ rescue JSON::ParserError => e
43
+ puts " ERROR: Failed to parse #{package_json_path}: #{e.message}"
44
+ raise
45
+ end
46
+
47
+ deps = package_json["dependencies"]
48
+ dev_deps = package_json["devDependencies"]
49
+
50
+ update_react_dependencies(deps, react_version)
51
+ # Shakapacker 8.2.0 requires webpack-assets-manifest ^5.x (v6.x uses ESM and breaks)
52
+ # Always add this explicitly since the transitive dependency from shakapacker may be v6.x
53
+ dev_deps["webpack-assets-manifest"] = "^5.0.6" if dev_deps
54
+ # Shakapacker 8.2.0 requires babel-loader to be explicitly installed as a devDependency
55
+ # (in 9.x this requirement was relaxed or the package structure changed)
56
+ dev_deps["babel-loader"] = "^9.1.3" if dev_deps
57
+ # @babel/plugin-transform-runtime is required by the default babel config but not
58
+ # automatically included as a dependency in older Shakapacker versions
59
+ dev_deps["@babel/plugin-transform-runtime"] = "^7.24.0" if dev_deps
60
+ update_shakapacker_dependency(deps, dev_deps)
61
+
62
+ # Add npm overrides to force specific React version, preventing yalc-linked
63
+ # react-on-rails from pulling in React 19 as a transitive dependency
64
+ package_json["overrides"] = {
65
+ "react" => react_version,
66
+ "react-dom" => react_version
67
+ }
68
+
69
+ File.write(package_json_path, "#{JSON.pretty_generate(package_json)}\n")
70
+ end
71
+
72
+ # Updates Gemfile to pin shakapacker to minimum version
73
+ # (must match the npm package version exactly)
74
+ def update_gemfile_versions(gemfile_path)
75
+ return unless File.exist?(gemfile_path)
76
+
77
+ gemfile_content = File.read(gemfile_path)
78
+ # Replace any shakapacker gem line with exact version pin
79
+ # Handle both single-line: gem 'shakapacker', '>= 8.2.0'
80
+ # And multi-line declarations:
81
+ # gem 'shakapacker',
82
+ # '>= 8.2.0'
83
+ gemfile_content = gemfile_content.gsub(
84
+ /gem ['"]shakapacker['"][^\n]*(?:\n\s+[^g\n][^\n]*)*$/m,
85
+ "gem 'shakapacker', '#{ExampleType::MINIMUM_SHAKAPACKER_VERSION}'"
86
+ )
87
+ File.write(gemfile_path, gemfile_content)
88
+ end
89
+
90
+ # Updates package.json and Gemfile to use specific React version for compatibility testing
91
+ def apply_react_version(dir, react_version)
92
+ update_package_json_for_react_version(File.join(dir, "package.json"), react_version)
93
+ update_gemfile_versions(File.join(dir, "Gemfile"))
94
+
95
+ puts " Updated package.json for compatibility testing:"
96
+ puts " React: #{react_version}"
97
+ puts " Shakapacker: #{ExampleType::MINIMUM_SHAKAPACKER_VERSION}"
98
+ end
99
+
18
100
  # Define tasks for each example type
19
- ExampleType.all[:shakapacker_examples].each do |example_type|
101
+ ExampleType.all[:shakapacker_examples].each do |example_type| # rubocop:disable Metrics/BlockLength
20
102
  relative_gem_root = Pathname(gem_root).relative_path_from(Pathname(example_type.dir))
21
103
  # CLOBBER
22
104
  desc "Clobbers (deletes) #{example_type.name_pretty}"
@@ -46,10 +128,31 @@ namespace :shakapacker_examples do # rubocop:disable Metrics/BlockLength
46
128
  "REACT_ON_RAILS_SKIP_VALIDATION=true #{cmd}"
47
129
  end
48
130
  sh_in_dir(example_type.dir, generator_commands)
49
- sh_in_dir(example_type.dir, "npm install")
131
+ # Re-run bundle install since dev_tests generator adds rspec-rails and coveralls to Gemfile
132
+ bundle_install_in(example_type.dir)
133
+
134
+ # Apply specific React version for compatibility testing examples
135
+ if example_type.pinned_react_version?
136
+ apply_react_version(example_type.dir, example_type.react_version_string)
137
+ # Re-run bundle install since Gemfile was updated with pinned shakapacker version
138
+ bundle_install_in(example_type.dir)
139
+ # Run npm install BEFORE shakapacker:binstubs to ensure the npm shakapacker version
140
+ # matches the gem version. The binstubs task loads the Rails environment which
141
+ # validates version matching between gem and npm package.
142
+ # Use --legacy-peer-deps to avoid peer dependency conflicts when yalc-linked
143
+ # react-on-rails expects newer React versions
144
+ sh_in_dir(example_type.dir, "npm install --legacy-peer-deps")
145
+ # Regenerate Shakapacker binstubs after downgrading from 9.x to 8.2.x
146
+ # The binstub format may differ between major versions
147
+ unbundled_sh_in_dir(example_type.dir, "bundle exec rake shakapacker:binstubs")
148
+ else
149
+ sh_in_dir(example_type.dir, "npm install")
150
+ end
50
151
  # Generate the component packs after running the generator to ensure all
51
- # auto-bundled components have corresponding pack files created
52
- sh_in_dir(example_type.dir, "bundle exec rake react_on_rails:generate_packs")
152
+ # auto-bundled components have corresponding pack files created.
153
+ # Use unbundled_sh_in_dir to ensure we're using the generated app's Gemfile
154
+ # and gem versions, not the parent workspace's bundle context.
155
+ unbundled_sh_in_dir(example_type.dir, "bundle exec rake react_on_rails:generate_packs")
53
156
  end
54
157
  end
55
158
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: react_on_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 16.2.0.test.6
4
+ version: 16.2.0.test.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Gordon
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-12-07 00:00:00.000000000 Z
11
+ date: 2025-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable