Skip to content

Commit f2099d7

Browse files
committed
Replace Webpacker with Shakapacker
1 parent e1c1b2d commit f2099d7

File tree

6 files changed

+68
-90
lines changed

6 files changed

+68
-90
lines changed

lib/react_on_rails/configuration.rb

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -256,27 +256,23 @@ def raise_missing_components_subdirectory
256256
end
257257

258258
def shakapacker_precompile?
259-
return Webpacker.config.webpacker_precompile? if ReactOnRails::WebpackerUtils.using_shakapacker_6?
260-
261259
Shakapacker.config.shakapacker_precompile?
262260
end
263261

264262
def shakapacker_clean_task
265-
ReactOnRails::WebpackerUtils.using_shakapacker_6? ? "webpacker:clean" : "shakapacker:clean"
263+
"shakapacker:clean"
266264
end
267265

268266
def compile_command_conflict_message
269-
packer = ReactOnRails::WebpackerUtils.using_shakapacker_6? ? "webpacker" : "shakapacker"
270-
271267
<<~MSG
272268
273269
React on Rails and Shakapacker error in configuration!
274270
In order to use config/react_on_rails.rb config.build_production_command,
275-
you must edit config/#{packer}.yml to include this value in the default configuration:
276-
'#{packer}_precompile: false'
271+
you must edit config/shakapacker.yml to include this value in the default configuration:
272+
'shakapacker_precompile: false'
277273
278274
Alternatively, remove the config/react_on_rails.rb config.build_production_command and the
279-
default bin/#{packer} script will be used for assets:precompile.
275+
default bin/shakapacker script will be used for assets:precompile.
280276
281277
MSG
282278
end

lib/react_on_rails/utils.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def self.server_bundle_js_file_path
8282
@server_bundle_path = if ReactOnRails::WebpackerUtils.using_webpacker?
8383
begin
8484
bundle_js_file_path(bundle_name)
85-
rescue Webpacker::Manifest::MissingEntryError
85+
rescue Shakapacker::Manifest::MissingEntryError
8686
File.expand_path(
8787
File.join(ReactOnRails::WebpackerUtils.webpacker_public_output_path,
8888
bundle_name)

lib/react_on_rails/webpacker_utils.rb

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@ module WebpackerUtils
55
def self.using_webpacker?
66
return @using_webpacker if defined?(@using_webpacker)
77

8-
@using_webpacker = ReactOnRails::Utils.gem_available?("webpacker") ||
9-
ReactOnRails::Utils.gem_available?("shakapacker")
8+
@using_webpacker = ReactOnRails::Utils.gem_available?("shakapacker")
109
end
1110

1211
def self.dev_server_running?
1312
return false unless using_webpacker?
1413

15-
Webpacker.dev_server.running?
14+
Shakapacker.dev_server.running?
1615
end
1716

1817
def self.shakapacker_version
@@ -41,51 +40,51 @@ def self.bundle_js_uri_from_webpacker(bundle_name)
4140
# [2] (pry) ReactOnRails::WebpackerUtils: 0> Webpacker.manifest.lookup("app-bundle.js")
4241
# "/webpack/development/app-bundle-c1d2b6ab73dffa7d9c0e.js"
4342
# Next line will throw if the file or manifest does not exist
44-
hashed_bundle_name = Webpacker.manifest.lookup!(bundle_name)
43+
hashed_bundle_name = Shakapacker.manifest.lookup!(bundle_name)
4544

4645
# Support for hashing the server-bundle and having that built
4746
# the webpack-dev-server is provided by the config value
4847
# "same_bundle_for_client_and_server" where a value of true
4948
# would mean that the bundle is created by the webpack-dev-server
5049
is_server_bundle = bundle_name == ReactOnRails.configuration.server_bundle_js_file
5150

52-
if Webpacker.dev_server.running? && (!is_server_bundle ||
51+
if Shakapacker.dev_server.running? && (!is_server_bundle ||
5352
ReactOnRails.configuration.same_bundle_for_client_and_server)
54-
"#{Webpacker.dev_server.protocol}://#{Webpacker.dev_server.host_with_port}#{hashed_bundle_name}"
53+
"#{Shakapacker.dev_server.protocol}://#{Shakapacker.dev_server.host_with_port}#{hashed_bundle_name}"
5554
else
5655
File.expand_path(File.join("public", hashed_bundle_name)).to_s
5756
end
5857
end
5958

6059
def self.webpacker_source_path
61-
Webpacker.config.source_path
60+
Shakapacker.config.source_path
6261
end
6362

6463
def self.webpacker_source_entry_path
65-
Webpacker.config.source_entry_path
64+
Shakapacker.config.source_entry_path
6665
end
6766

6867
def self.nested_entries?
69-
Webpacker.config.nested_entries?
68+
Shakapacker.config.nested_entries?
7069
end
7170

7271
def self.webpacker_public_output_path
73-
# Webpacker has the full absolute path of webpacker output files in a Pathname
74-
Webpacker.config.public_output_path.to_s
72+
# Shakapacker has the full absolute path of webpacker output files in a Pathname
73+
Shakapacker.config.public_output_path.to_s
7574
end
7675

7776
def self.manifest_exists?
78-
Webpacker.config.public_manifest_path.exist?
77+
Shakapacker.config.public_manifest_path.exist?
7978
end
8079

8180
def self.webpacker_source_path_explicit?
82-
# WARNING: Calling private method `data` on Webpacker::Configuration, lib/webpacker/configuration.rb
83-
config_webpacker_yml = Webpacker.config.send(:data)
81+
# WARNING: Calling private method `data` on Shakapacker::Configuration, lib/webpacker/configuration.rb
82+
config_webpacker_yml = Shakapacker.config.send(:data)
8483
config_webpacker_yml[:source_path].present?
8584
end
8685

8786
def self.check_manifest_not_cached
88-
return unless using_webpacker? && Webpacker.config.cache_manifest?
87+
return unless using_webpacker? && Shakapacker.config.cache_manifest?
8988

9089
msg = <<-MSG.strip_heredoc
9190
ERROR: you have enabled cache_manifest in the #{Rails.env} env when using the
@@ -141,11 +140,5 @@ def self.raise_shakapacker_not_installed
141140
def self.semver_to_string(ary)
142141
"#{ary[0]}.#{ary[1]}.#{ary[2]}"
143142
end
144-
145-
def self.using_shakapacker_6?
146-
shakapacker_major_version = shakapacker_version_as_array[0]
147-
148-
shakapacker_major_version == 6
149-
end
150143
end
151144
end

spec/react_on_rails/configuration_spec.rb

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module ReactOnRails
2727

2828
before do
2929
allow(Rails).to receive(:root).and_return(File.expand_path("."))
30-
allow(Webpacker).to receive_message_chain("config.public_output_path")
30+
allow(Shakapacker).to receive_message_chain("config.public_output_path")
3131
.and_return(webpacker_public_output_path)
3232
end
3333

@@ -75,70 +75,59 @@ module ReactOnRails
7575
end
7676

7777
describe ".build_production_command" do
78-
context "when using Shakapacker 6" do
78+
context "when using Shakapacker 7" do
7979
before do
8080
allow(ReactOnRails::WebpackerUtils)
8181
.to receive("shakapacker_version")
82-
.and_return("6.0.0")
82+
.and_return("7.0.0")
8383
end
8484

85-
it "fails when \"webpacker_precompile\" is truly and \"build_production_command\" is truly" do
86-
allow(Webpacker).to receive_message_chain("config.webpacker_precompile?")
85+
it "fails when \"shakapacker_precompile\" is truly and \"build_production_command\" is truly" do
86+
allow(Shakapacker).to receive_message_chain("config.shakapacker_precompile?")
8787
.and_return(true)
8888
expect do
8989
ReactOnRails.configure do |config|
90-
config.build_production_command = "RAILS_ENV=production NODE_ENV=production bin/webpacker"
90+
config.build_production_command = "RAILS_ENV=production NODE_ENV=production bin/shakapacker"
9191
end
92-
end.to raise_error(ReactOnRails::Error, /webpacker_precompile: false/)
92+
end.to raise_error(ReactOnRails::Error, /shakapacker_precompile: false/)
9393
end
9494

95-
it "doesn't fail when \"webpacker_precompile\" is falsy and \"build_production_command\" is truly" do
96-
allow(Webpacker).to receive_message_chain("config.webpacker_precompile?")
95+
it "doesn't fail when \"shakapacker_precompile\" is falsy and \"build_production_command\" is truly" do
96+
allow(Shakapacker).to receive_message_chain("config.shakapacker_precompile?")
9797
.and_return(false)
9898
expect do
9999
ReactOnRails.configure do |config|
100-
config.build_production_command = "RAILS_ENV=production NODE_ENV=production bin/webpacker"
100+
config.build_production_command = "RAILS_ENV=production NODE_ENV=production bin/shakapacker"
101101
end
102102
end.not_to raise_error
103103
end
104104

105-
it "doesn't fail when \"webpacker_precompile\" is truly and \"build_production_command\" is falsy" do
106-
allow(Webpacker).to receive_message_chain("config.webpacker_precompile?")
105+
it "doesn't fail when \"shakapacker_precompile\" is truly and \"build_production_command\" is falsy" do
106+
allow(Shakapacker).to receive_message_chain("config.shakapacker_precompile?")
107107
.and_return(true)
108108
expect do
109109
ReactOnRails.configure {} # rubocop:disable-line Lint/EmptyBlock
110110
end.not_to raise_error
111111
end
112112

113-
it "doesn't fail when \"webpacker_precompile\" is falsy and \"build_production_command\" is falsy" do
114-
allow(Webpacker).to receive_message_chain("config.webpacker_precompile?")
113+
it "doesn't fail when \"shakapacker_precompile\" is falsy and \"build_production_command\" is falsy" do
114+
allow(Shakapacker).to receive_message_chain("config.shakapacker_precompile?")
115115
.and_return(false)
116116
expect do
117117
ReactOnRails.configure {} # rubocop:disable-line Lint/EmptyBlock
118118
end.not_to raise_error
119119
end
120120
end
121121

122-
context "when using Shakapacker 7" do
122+
context "when using Shakapacker 8" do
123123
before do
124124
allow(ReactOnRails::WebpackerUtils)
125125
.to receive("shakapacker_version")
126-
.and_return("7.0.0")
127-
end
128-
129-
it "doesn't show deprecation message for webpacker_precompile?" do
130-
allow(Webpacker).to receive_message_chain("config.shakapacker_precompile?")
131-
.and_return(false)
132-
133-
expect do
134-
ReactOnRails.configure do |config|
135-
config.build_production_command = "RAILS_ENV=production NODE_ENV=production bin/shakapacker"
136-
end
137-
end.not_to output(/Consider using `shakapacker_precompile?`/).to_stdout
126+
.and_return("8.0.0")
138127
end
139128

140129
it "fails when \"shakapacker_precompile\" is truly and \"build_production_command\" is truly" do
141-
allow(Webpacker).to receive_message_chain("config.shakapacker_precompile?")
130+
allow(Shakapacker).to receive_message_chain("config.shakapacker_precompile?")
142131
.and_return(true)
143132
expect do
144133
ReactOnRails.configure do |config|
@@ -148,7 +137,7 @@ module ReactOnRails
148137
end
149138

150139
it "doesn't fail when \"shakapacker_precompile\" is falsy and \"build_production_command\" is truly" do
151-
allow(Webpacker).to receive_message_chain("config.shakapacker_precompile?")
140+
allow(Shakapacker).to receive_message_chain("config.shakapacker_precompile?")
152141
.and_return(false)
153142
expect do
154143
ReactOnRails.configure do |config|
@@ -158,15 +147,15 @@ module ReactOnRails
158147
end
159148

160149
it "doesn't fail when \"shakapacker_precompile\" is truly and \"build_production_command\" is falsy" do
161-
allow(Webpacker).to receive_message_chain("config.shakapacker_precompile?")
150+
allow(Shakapacker).to receive_message_chain("config.shakapacker_precompile?")
162151
.and_return(true)
163152
expect do
164153
ReactOnRails.configure {} # rubocop:disable-line Lint/EmptyBlock
165154
end.not_to raise_error
166155
end
167156

168157
it "doesn't fail when \"shakapacker_precompile\" is falsy and \"build_production_command\" is falsy" do
169-
allow(Webpacker).to receive_message_chain("config.shakapacker_precompile?")
158+
allow(Shakapacker).to receive_message_chain("config.shakapacker_precompile?")
170159
.and_return(false)
171160
expect do
172161
ReactOnRails.configure {} # rubocop:disable-line Lint/EmptyBlock

spec/react_on_rails/test_helper/webpack_assets_status_checker_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
.and_return(File.join(generated_assets_full_path, "manifest.json"))
7575
allow(ReactOnRails::Utils).to receive(:bundle_js_file_path)
7676
.with("server-bundle.js")
77-
.and_raise(Webpacker::Manifest::MissingEntryError)
77+
.and_raise(Shakapacker::Manifest::MissingEntryError)
7878
touch_files_in_dir(generated_assets_full_path)
7979
end
8080

0 commit comments

Comments
 (0)