Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: replace Webpacker with Shakapacker #1622

Merged
merged 81 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
156df7f
fix: replace Webpacker with Shakapacker
adriangohjw May 20, 2024
6df4e8d
add changelog entry
Judahmeek May 21, 2024
5051a55
update gemfile to use shakapacker 8.0.0
adriangohjw May 21, 2024
6212747
Replace Webpacker with Shakapacker
adriangohjw May 21, 2024
39b32e2
Update WebpackerUtils to ShakapackerUtils
adriangohjw May 21, 2024
8c0d019
(spec) package.json - update shakapacker to v8 + add "packageManager"
adriangohjw May 21, 2024
7723165
fix specs - Update Webpacker to Shakapacker
adriangohjw May 21, 2024
797ea16
Fix rubocop linting error
adriangohjw May 21, 2024
f1c6fd7
remove post-install action for shakapacker < v7
adriangohjw May 21, 2024
8559b2c
fix: updated test description and context tag
adriangohjw May 21, 2024
d832db4
update min. shakapacker version to 7.2.1
adriangohjw May 21, 2024
4609d03
use adapter method for Shakapacker
Judahmeek Jun 14, 2023
812c94c
Ci fixes & linting
Judahmeek Jun 12, 2024
328aacb
per review
Judahmeek Jun 12, 2024
52c0ea8
Ci fix for changed-files
Judahmeek Jun 13, 2024
3711e9c
revert changes to install generator
Judahmeek Jun 13, 2024
7810da0
WIP
Judahmeek Jun 14, 2024
0d82c02
still wip
Judahmeek Jun 14, 2024
2ec90b8
getting there?
Judahmeek Jun 14, 2024
ae8fba8
more wip
Judahmeek Jun 14, 2024
bfaf244
remove appraisal and dynamically modify gemfiles
Judahmeek Jun 14, 2024
d33ad0a
wip again
Judahmeek Jun 14, 2024
446c090
more fixes
Judahmeek Jun 14, 2024
8a0003e
fixes more
Judahmeek Jun 14, 2024
15db710
still fixing
Judahmeek Jun 14, 2024
789958e
hopefully getting somewhere
Judahmeek Jun 14, 2024
96bcb5f
more fixes
Judahmeek Jun 15, 2024
e82d924
resolve install generator errors
Judahmeek Jun 25, 2024
6cc3d4f
additional fixes
Judahmeek Jun 25, 2024
25edd25
debugging integration failure
Judahmeek Jun 25, 2024
de5bfaf
add log statements
Judahmeek Jun 25, 2024
07f2e72
use info from log statements to resolve issues
Judahmeek Jun 26, 2024
19ddd8c
fix invalid job configurations
Judahmeek Jun 26, 2024
5cc7a81
add log statements to debug new issues
Judahmeek Jun 26, 2024
62c69db
further debugging
Judahmeek Jun 26, 2024
4fac40f
fix debug statement
Judahmeek Jun 26, 2024
4c9568a
fix other debug statement
Judahmeek Jun 26, 2024
32945f7
maybe fixes
Judahmeek Jun 26, 2024
0f3bdcd
fix maybes
Judahmeek Jun 26, 2024
861d544
resolve pack gen errors
Judahmeek Jun 26, 2024
60b0ec0
whatever
Judahmeek Jun 26, 2024
e2090b4
maybe maybe
Judahmeek Jun 26, 2024
1017815
all integration specs should be passing
Judahmeek Jun 26, 2024
f3be6af
linting
Judahmeek Jun 26, 2024
24c8d5a
further linting
Judahmeek Jun 26, 2024
00827e4
add example debug statement
Judahmeek Jun 26, 2024
0f6ddcb
add missing method
Judahmeek Jun 26, 2024
15cbe82
focus on generator job
Judahmeek Jun 26, 2024
b6d0201
debug yarn install
Judahmeek Jun 26, 2024
196dd26
debug/fix for packageManager key
Judahmeek Jun 26, 2024
6ba18dc
separate tasks by packer type
Judahmeek Jun 26, 2024
d6300a3
skip corepack check
Judahmeek Jun 26, 2024
8b673f2
debug more
Judahmeek Jun 26, 2024
2e94227
potential fix
Judahmeek Jun 26, 2024
321adf0
try again
Judahmeek Jun 26, 2024
6444653
closer
Judahmeek Jun 26, 2024
8162ee7
fail-fast false
Judahmeek Jun 26, 2024
a694c99
closer
Judahmeek Jun 26, 2024
2a5d78d
no point in matrix if shakapacker v6 doesn't support node 16
Judahmeek Jun 26, 2024
aaa2140
one more fix
Judahmeek Jun 26, 2024
afe89b3
Revert "focus on generator job"
Judahmeek Jun 26, 2024
428fd66
remove debug statements
Judahmeek Jun 27, 2024
ed3806f
Revert "no point in matrix if shakapacker v6 doesn't support node 16"
Judahmeek Jun 27, 2024
21fa4ea
revert 'one more fix'
Judahmeek Jun 27, 2024
43d15d0
remove all jobs except generators again
Judahmeek Jun 27, 2024
9b063e7
use Node v20 for all gen tests
Judahmeek Jun 27, 2024
6a640c5
add debug statement
Judahmeek Jun 27, 2024
2726d61
move example_type initialization logic to run_rspec file
Judahmeek Jun 27, 2024
4ca8cf1
linting & debug statement removal
Judahmeek Jun 27, 2024
a03e171
Revert "remove all jobs except generators again"
Judahmeek Jun 27, 2024
3a8df96
restore shakapacker to Gemfile & package.json
Judahmeek Jun 28, 2024
d77929e
restore dumy apps rake task
Judahmeek Jun 28, 2024
4c3cb9b
use shakapacker v8 by default
Judahmeek Jun 28, 2024
1915582
create a script to convert shakapacker support from v8 to v6
Judahmeek Jun 28, 2024
d08a465
use conversion script for CI
Judahmeek Jun 28, 2024
2061f3a
linting
Judahmeek Jun 28, 2024
82a2aa7
fixes?
Judahmeek Jun 28, 2024
b5e7939
final fixes?
Judahmeek Jun 28, 2024
4cce360
update Contributing doc
Judahmeek Jun 28, 2024
c96a47e
using_xpacker? > using_xpacker_const?
Judahmeek Jun 28, 2024
b8c5d28
linting
Judahmeek Jun 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Replace Webpacker with Shakapacker
  • Loading branch information
adriangohjw authored and Judahmeek committed Jun 14, 2024
commit 6212747fef522b1592b185c5ea197423d7f78561
12 changes: 4 additions & 8 deletions lib/react_on_rails/configuration.rb
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

double check all these changes

Original file line number Diff line number Diff line change
Expand Up @@ -256,27 +256,23 @@ def raise_missing_components_subdirectory
end

def shakapacker_precompile?
return Webpacker.config.webpacker_precompile? if ReactOnRails::WebpackerUtils.using_shakapacker_6?

Shakapacker.config.shakapacker_precompile?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

end

def shakapacker_clean_task
ReactOnRails::WebpackerUtils.using_shakapacker_6? ? "webpacker:clean" : "shakapacker:clean"
"shakapacker:clean"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

end

def compile_command_conflict_message
packer = ReactOnRails::WebpackerUtils.using_shakapacker_6? ? "webpacker" : "shakapacker"

<<~MSG

React on Rails and Shakapacker error in configuration!
In order to use config/react_on_rails.rb config.build_production_command,
you must edit config/#{packer}.yml to include this value in the default configuration:
'#{packer}_precompile: false'
you must edit config/shakapacker.yml to include this value in the default configuration:
'shakapacker_precompile: false'

Alternatively, remove the config/react_on_rails.rb config.build_production_command and the
default bin/#{packer} script will be used for assets:precompile.
default bin/shakapacker script will be used for assets:precompile.

MSG
end
Expand Down
2 changes: 1 addition & 1 deletion lib/react_on_rails/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def self.server_bundle_js_file_path
@server_bundle_path = if ReactOnRails::WebpackerUtils.using_webpacker?
begin
bundle_js_file_path(bundle_name)
rescue Webpacker::Manifest::MissingEntryError
rescue Shakapacker::Manifest::MissingEntryError
File.expand_path(
File.join(ReactOnRails::WebpackerUtils.webpacker_public_output_path,
bundle_name)
Expand Down
35 changes: 14 additions & 21 deletions lib/react_on_rails/webpacker_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ module WebpackerUtils
def self.using_webpacker?
return @using_webpacker if defined?(@using_webpacker)

@using_webpacker = ReactOnRails::Utils.gem_available?("webpacker") ||
ReactOnRails::Utils.gem_available?("shakapacker")
@using_webpacker = ReactOnRails::Utils.gem_available?("shakapacker")
end

def self.dev_server_running?
return false unless using_webpacker?

Webpacker.dev_server.running?
Shakapacker.dev_server.running?
end

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

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

if Webpacker.dev_server.running? && (!is_server_bundle ||
if Shakapacker.dev_server.running? && (!is_server_bundle ||
ReactOnRails.configuration.same_bundle_for_client_and_server)
"#{Webpacker.dev_server.protocol}://#{Webpacker.dev_server.host_with_port}#{hashed_bundle_name}"
"#{Shakapacker.dev_server.protocol}://#{Shakapacker.dev_server.host_with_port}#{hashed_bundle_name}"
else
File.expand_path(File.join("public", hashed_bundle_name)).to_s
end
end

def self.webpacker_source_path
Webpacker.config.source_path
Shakapacker.config.source_path
end

def self.webpacker_source_entry_path
Webpacker.config.source_entry_path
Shakapacker.config.source_entry_path
end

def self.nested_entries?
Webpacker.config.nested_entries?
Shakapacker.config.nested_entries?
end

def self.webpacker_public_output_path
# Webpacker has the full absolute path of webpacker output files in a Pathname
Webpacker.config.public_output_path.to_s
# Shakapacker has the full absolute path of webpacker output files in a Pathname
Shakapacker.config.public_output_path.to_s
end

def self.manifest_exists?
Webpacker.config.public_manifest_path.exist?
Shakapacker.config.public_manifest_path.exist?
end

def self.webpacker_source_path_explicit?
# WARNING: Calling private method `data` on Webpacker::Configuration, lib/webpacker/configuration.rb
config_webpacker_yml = Webpacker.config.send(:data)
# WARNING: Calling private method `data` on Shakapacker::Configuration, lib/webpacker/configuration.rb
config_webpacker_yml = Shakapacker.config.send(:data)
config_webpacker_yml[:source_path].present?
end

def self.check_manifest_not_cached
return unless using_webpacker? && Webpacker.config.cache_manifest?
return unless using_webpacker? && Shakapacker.config.cache_manifest?

msg = <<-MSG.strip_heredoc
ERROR: you have enabled cache_manifest in the #{Rails.env} env when using the
Expand Down Expand Up @@ -141,11 +140,5 @@ def self.raise_shakapacker_not_installed
def self.semver_to_string(ary)
"#{ary[0]}.#{ary[1]}.#{ary[2]}"
end

def self.using_shakapacker_6?
shakapacker_major_version = shakapacker_version_as_array[0]

shakapacker_major_version == 6
end
end
end
51 changes: 20 additions & 31 deletions spec/react_on_rails/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module ReactOnRails

before do
allow(Rails).to receive(:root).and_return(File.expand_path("."))
allow(Webpacker).to receive_message_chain("config.public_output_path")
allow(Shakapacker).to receive_message_chain("config.public_output_path")
.and_return(webpacker_public_output_path)
end

Expand Down Expand Up @@ -75,70 +75,59 @@ module ReactOnRails
end

describe ".build_production_command" do
context "when using Shakapacker 6" do
context "when using Shakapacker 7" do
before do
allow(ReactOnRails::WebpackerUtils)
.to receive("shakapacker_version")
.and_return("6.0.0")
.and_return("7.0.0")
end

it "fails when \"webpacker_precompile\" is truly and \"build_production_command\" is truly" do
allow(Webpacker).to receive_message_chain("config.webpacker_precompile?")
it "fails when \"shakapacker_precompile\" is truly and \"build_production_command\" is truly" do
allow(Shakapacker).to receive_message_chain("config.shakapacker_precompile?")
.and_return(true)
expect do
ReactOnRails.configure do |config|
config.build_production_command = "RAILS_ENV=production NODE_ENV=production bin/webpacker"
config.build_production_command = "RAILS_ENV=production NODE_ENV=production bin/shakapacker"
end
end.to raise_error(ReactOnRails::Error, /webpacker_precompile: false/)
end.to raise_error(ReactOnRails::Error, /shakapacker_precompile: false/)
end

it "doesn't fail when \"webpacker_precompile\" is falsy and \"build_production_command\" is truly" do
allow(Webpacker).to receive_message_chain("config.webpacker_precompile?")
it "doesn't fail when \"shakapacker_precompile\" is falsy and \"build_production_command\" is truly" do
allow(Shakapacker).to receive_message_chain("config.shakapacker_precompile?")
.and_return(false)
expect do
ReactOnRails.configure do |config|
config.build_production_command = "RAILS_ENV=production NODE_ENV=production bin/webpacker"
config.build_production_command = "RAILS_ENV=production NODE_ENV=production bin/shakapacker"
end
end.not_to raise_error
end

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

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

context "when using Shakapacker 7" do
context "when using Shakapacker 8" do
before do
allow(ReactOnRails::WebpackerUtils)
.to receive("shakapacker_version")
.and_return("7.0.0")
end

it "doesn't show deprecation message for webpacker_precompile?" do
allow(Webpacker).to receive_message_chain("config.shakapacker_precompile?")
.and_return(false)

expect do
ReactOnRails.configure do |config|
config.build_production_command = "RAILS_ENV=production NODE_ENV=production bin/shakapacker"
end
end.not_to output(/Consider using `shakapacker_precompile?`/).to_stdout
.and_return("8.0.0")
end

it "fails when \"shakapacker_precompile\" is truly and \"build_production_command\" is truly" do
allow(Webpacker).to receive_message_chain("config.shakapacker_precompile?")
allow(Shakapacker).to receive_message_chain("config.shakapacker_precompile?")
.and_return(true)
expect do
ReactOnRails.configure do |config|
Expand All @@ -148,7 +137,7 @@ module ReactOnRails
end

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

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

it "doesn't fail when \"shakapacker_precompile\" is falsy and \"build_production_command\" is falsy" do
allow(Webpacker).to receive_message_chain("config.shakapacker_precompile?")
allow(Shakapacker).to receive_message_chain("config.shakapacker_precompile?")
.and_return(false)
expect do
ReactOnRails.configure {} # rubocop:disable-line Lint/EmptyBlock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
.and_return(File.join(generated_assets_full_path, "manifest.json"))
allow(ReactOnRails::Utils).to receive(:bundle_js_file_path)
.with("server-bundle.js")
.and_raise(Webpacker::Manifest::MissingEntryError)
.and_raise(Shakapacker::Manifest::MissingEntryError)
touch_files_in_dir(generated_assets_full_path)
end

Expand Down
Loading