Skip to content

Commit 5285de3

Browse files
committed
Complete removal of all packer_type references and restore documentation fix
- Remove packer_type method from PackerUtils - Replace all ReactOnRails::PackerUtils.packer_type calls with hardcoded 'shakapacker' - Update generator templates to use static values instead of ERB variables - Fix test mocking to use PackerUtils.precompile? instead of direct Shakapacker calls - Remove dynamic require statements in test files - Restore documentation fix for RuboCop command (lost in force push) This completes the simplification of the codebase by removing the dynamic packer_type abstraction since we now only support Shakapacker. Co-authored-by: Justin Gordon <[email protected]>
1 parent 8c32a63 commit 5285de3

File tree

10 files changed

+24
-41
lines changed

10 files changed

+24
-41
lines changed

docs/contributor-info/linters.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ If you haven't tried the autofix options for `eslint` and `rubocop`, you're seri
1010
2. **Rubocop:** Be sure to be in the correct directory where you have Ruby files, usually the top level of your Rails project.
1111

1212
```bash
13-
rubocop -a
13+
bundle exec rubocop -A
1414
```
1515

1616
3. **ESLint:** Be sure to be in the correct directory where you have JS files.

lib/generators/react_on_rails/base_generator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def copy_base_files
4141
base_templates = %w[config/initializers/react_on_rails.rb]
4242
base_files.each { |file| copy_file("#{base_path}#{file}", file) }
4343
base_templates.each do |file|
44-
template("#{base_path}/#{file}.tt", file, { packer_type: ReactOnRails::PackerUtils.packer_type })
44+
template("#{base_path}/#{file}.tt", file)
4545
end
4646
end
4747

lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb.tt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ ReactOnRails.configure do |config|
2424
# to automatically refresh your webpack assets on every test run.
2525
#
2626
# Alternately, you can remove the `ReactOnRails::TestHelper.configure_rspec_to_compile_assets`
27-
# and set the config/<%= config[:packer_type] %>.yml option for test to true.
28-
config.build_test_command = "RAILS_ENV=test bin/<%= config[:packer_type] %>"
27+
# and set the config/shakapacker.yml option for test to true.
28+
config.build_test_command = "RAILS_ENV=test bin/shakapacker"
2929

3030
################################################################################
3131
################################################################################

lib/react_on_rails/configuration.rb

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,8 @@ def adjust_precompile_task
251251
# We set it very big so that it is not used, and then clean just
252252
# removes files older than 1 hour.
253253
versions = 100_000
254-
puts "Invoking task #{ReactOnRails::PackerUtils.packer_type}:clean from React on Rails"
255-
Rake::Task["#{ReactOnRails::PackerUtils.packer_type}:clean"].invoke(versions)
254+
puts "Invoking task shakapacker:clean from React on Rails"
255+
Rake::Task["shakapacker:clean"].invoke(versions)
256256
}
257257

258258
if Rake::Task.task_defined?("assets:precompile")
@@ -275,14 +275,14 @@ def error_if_using_packer_and_generated_assets_dir_not_match_public_output_path
275275

276276
if File.expand_path(generated_assets_dir) == packer_public_output_path.to_s
277277
Rails.logger.warn("You specified generated_assets_dir in `config/initializers/react_on_rails.rb` " \
278-
"with #{ReactOnRails::PackerUtils.packer_type}. " \
278+
"with Shakapacker. " \
279279
"Remove this line from your configuration file.")
280280
else
281281
msg = <<~MSG
282-
Error configuring /config/initializers/react_on_rails.rb: You are using #{ReactOnRails::PackerUtils.packer_type}
282+
Error configuring /config/initializers/react_on_rails.rb: You are using Shakapacker
283283
and your specified value for generated_assets_dir = #{generated_assets_dir}
284284
that does not match the value for public_output_path specified in
285-
#{ReactOnRails::PackerUtils.packer_type}.yml = #{packer_public_output_path}. You should remove the configuration
285+
shakapacker.yml = #{packer_public_output_path}. You should remove the configuration
286286
value for "generated_assets_dir" from your config/initializers/react_on_rails.rb file.
287287
MSG
288288
raise ReactOnRails::Error, msg
@@ -314,11 +314,11 @@ def configure_generated_assets_dirs_deprecation
314314
if ReactOnRails::PackerUtils.using_packer?
315315
packer_public_output_path = ReactOnRails::PackerUtils.packer_public_output_path
316316
# rubocop:disable Layout/LineLength
317-
packer_name = ReactOnRails::PackerUtils.packer_type&.upcase_first
317+
packer_name = "Shakapacker"
318318

319319
Rails.logger.warn "Error configuring config/initializers/react_on_rails. Define neither the generated_assets_dirs nor " \
320320
"the generated_assets_dir when using #{packer_name}. This is defined by " \
321-
"public_output_path specified in #{ReactOnRails::PackerUtils.packer_type}.yml = #{packer_public_output_path}."
321+
"public_output_path specified in shakapacker.yml = #{packer_public_output_path}."
322322
# rubocop:enable Layout/LineLength
323323
return
324324
end
@@ -363,17 +363,16 @@ def raise_missing_components_subdirectory
363363
end
364364

365365
def compile_command_conflict_message
366-
packer_name = ReactOnRails::PackerUtils.packer_type.upcase_first
367-
packer_type = ReactOnRails::PackerUtils.packer_type
366+
packer_name = "Shakapacker"
368367
<<~MSG
369368
370369
React on Rails and #{packer_name} error in configuration!
371370
In order to use config/react_on_rails.rb config.build_production_command,
372-
you must edit config/#{packer_type}.yml to include this value in the default configuration:
373-
'#{packer_type}_precompile: false'
371+
you must edit config/shakapacker.yml to include this value in the default configuration:
372+
'shakapacker_precompile: false'
374373
375374
Alternatively, remove the config/react_on_rails.rb config.build_production_command and the
376-
default bin/#{packer_type} script will be used for assets:precompile.
375+
default bin/shakapacker script will be used for assets:precompile.
377376
378377
MSG
379378
end

lib/react_on_rails/packer_utils.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ def self.using_packer?
99
@using_packer = ReactOnRails::Utils.gem_available?("shakapacker")
1010
end
1111

12-
def self.packer_type
13-
using_packer? ? "shakapacker" : nil
14-
end
15-
1612
def self.packer
1713
return nil unless using_packer?
1814

@@ -120,7 +116,7 @@ def self.check_manifest_not_cached
120116
msg = <<-MSG.strip_heredoc
121117
ERROR: you have enabled cache_manifest in the #{Rails.env} env when using the
122118
ReactOnRails::TestHelper.configure_rspec_to_compile_assets helper
123-
To fix this: edit your config/#{packer_type}.yml file and set cache_manifest to false for test.
119+
To fix this: edit your config/shakapacker.yml file and set cache_manifest to false for test.
124120
MSG
125121
puts wrap_message(msg)
126122
exit!
@@ -141,7 +137,7 @@ def self.webpack_assets_status_checker
141137
def self.raise_nested_entries_disabled
142138
msg = <<~MSG
143139
**ERROR** ReactOnRails: `nested_entries` is configured to be disabled in shakapacker. Please update \
144-
config/#{packer_type}.yml to enable nested entries. for more information read
140+
config/shakapacker.yml to enable nested entries. for more information read
145141
https://www.shakacode.com/react-on-rails/docs/guides/file-system-based-automated-bundle-generation.md#enable-nested_entries-for-shakapacker
146142
MSG
147143

lib/react_on_rails/test_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def self.ensure_assets_compiled(webpack_assets_status_checker: nil,
8989
if ReactOnRails::PackerUtils.using_packer? &&
9090
ReactOnRails::Utils.using_packer_source_path_is_not_defined_and_custom_node_modules?
9191
msg = <<-MSG.strip_heredoc
92-
WARNING: Define config/#{ReactOnRails::PackerUtils.packer_type}.yml to include sourcePath to configure
92+
WARNING: Define config/shakapacker.yml to include sourcePath to configure
9393
the location of your JavaScript source for React on Rails.
9494
Default location of #{source_path} is used.
9595
MSG

lib/react_on_rails/test_helper/webpack_assets_compiler.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def compile_assets
1616
1717
React on Rails is aborting your test run
1818
19-
If you wish to use the config/#{ReactOnRails::PackerUtils.packer_type}.yml compile option for tests
19+
If you wish to use the config/shakapacker.yml compile option for tests
2020
them remove your call to the ReactOnRails test helper.
2121
MSG
2222
puts Rainbow(msg).red

spec/dummy/spec/rake/assets_precompile_rake_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
ReactOnRails.configure do |config|
1717
config.build_production_command = "RAILS_ENV=production NODE_ENV=production /
18-
bin/#{ReactOnRails::PackerUtils.packer_type}"
18+
bin/shakapacker"
1919
end
2020

2121
expect do

spec/react_on_rails/configuration_spec.rb

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# frozen_string_literal: true
22

33
require_relative "spec_helper"
4-
require ReactOnRails::PackerUtils.packer_type
54

65
# rubocop:disable Metrics/ModuleLength
76

@@ -78,9 +77,7 @@ module ReactOnRails
7877
describe ".build_production_command" do
7978
context "when using Shakapacker 8" do
8079
it "fails when \"shakapacker_precompile\" is truly and \"build_production_command\" is truly" do
81-
allow(ReactOnRails::PackerUtils).to receive(:using_packer?).and_return(true)
82-
allow(Shakapacker).to receive_message_chain("config.shakapacker_precompile?")
83-
.and_return(true)
80+
allow(ReactOnRails::PackerUtils).to receive_messages(using_packer?: true, precompile?: true)
8481
expect do
8582
ReactOnRails.configure do |config|
8683
config.build_production_command = "RAILS_ENV=production NODE_ENV=production bin/shakapacker"
@@ -89,9 +86,7 @@ module ReactOnRails
8986
end
9087

9188
it "doesn't fail when \"shakapacker_precompile\" is falsy and \"build_production_command\" is truly" do
92-
allow(ReactOnRails::PackerUtils).to receive(:using_packer?).and_return(true)
93-
allow(Shakapacker).to receive_message_chain("config.shakapacker_precompile?")
94-
.and_return(false)
89+
allow(ReactOnRails::PackerUtils).to receive_messages(using_packer?: true, precompile?: false)
9590
expect do
9691
ReactOnRails.configure do |config|
9792
config.build_production_command = "RAILS_ENV=production NODE_ENV=production bin/shakapacker"
@@ -100,18 +95,14 @@ module ReactOnRails
10095
end
10196

10297
it "doesn't fail when \"shakapacker_precompile\" is truly and \"build_production_command\" is falsy" do
103-
allow(ReactOnRails::PackerUtils).to receive(:using_packer?).and_return(true)
104-
allow(Shakapacker).to receive_message_chain("config.shakapacker_precompile?")
105-
.and_return(true)
98+
allow(ReactOnRails::PackerUtils).to receive_messages(using_packer?: true, precompile?: true)
10699
expect do
107100
ReactOnRails.configure {} # rubocop:disable-line Lint/EmptyBlock
108101
end.not_to raise_error
109102
end
110103

111104
it "doesn't fail when \"shakapacker_precompile\" is falsy and \"build_production_command\" is falsy" do
112-
allow(ReactOnRails::PackerUtils).to receive(:using_packer?).and_return(true)
113-
allow(Shakapacker).to receive_message_chain("config.shakapacker_precompile?")
114-
.and_return(false)
105+
allow(ReactOnRails::PackerUtils).to receive_messages(using_packer?: true, precompile?: false)
115106
expect do
116107
ReactOnRails.configure {} # rubocop:disable-line Lint/EmptyBlock
117108
end.not_to raise_error

spec/react_on_rails/utils_spec.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# frozen_string_literal: true
22

33
require_relative "spec_helper"
4-
require ReactOnRails::PackerUtils.packer_type
54

65
# rubocop:disable Metrics/ModuleLength, Metrics/BlockLength
76
module ReactOnRails
@@ -30,7 +29,6 @@ module ReactOnRails
3029

3130
# We don't need to mock anything here because the shakapacker gem is already installed and will be used by default
3231
it "uses shakapacker" do
33-
expect(ReactOnRails::PackerUtils.packer_type).to eq("shakapacker")
3432
expect(ReactOnRails::PackerUtils.packer).to eq(::Shakapacker)
3533
end
3634
end
@@ -44,7 +42,6 @@ module ReactOnRails
4442

4543
it "does not use packer" do
4644
expect(ReactOnRails::PackerUtils.using_packer?).to be(false)
47-
expect(ReactOnRails::PackerUtils.packer_type).to be_nil
4845
expect(ReactOnRails::PackerUtils.packer).to be_nil
4946
end
5047
end

0 commit comments

Comments
 (0)