Skip to content

Commit

Permalink
per review
Browse files Browse the repository at this point in the history
  • Loading branch information
Judahmeek committed Jun 13, 2024
1 parent de94a90 commit 4a99250
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 23 deletions.
12 changes: 2 additions & 10 deletions lib/react_on_rails/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def configure_generated_assets_dirs_deprecation
packer_public_output_path = ReactOnRails::PackerUtils.packer_public_output_path
# rubocop:disable Layout/LineLength
Rails.logger.warn "Error configuring config/initializers/react_on_rails. Define neither the generated_assets_dirs nor " \
"the generated_assets_dir when using Shakapacker. This is defined by " \
"the generated_assets_dir when using #{ReactOnRails::PackerUtils.packer_type.upcase_first}. This is defined by " \
"public_output_path specified in #{ReactOnRails::PackerUtils.packer_type}.yml = #{packer_public_output_path}."
# rubocop:enable Layout/LineLength
return
Expand Down Expand Up @@ -257,18 +257,10 @@ def raise_missing_components_subdirectory
raise ReactOnRails::Error, msg
end

def shakapacker_precompile?
Shakapacker.config.shakapacker_precompile?
end

def shakapacker_clean_task
"shakapacker:clean"
end

def compile_command_conflict_message
<<~MSG
React on Rails and Shakapacker error in configuration!
React on Rails and #{ReactOnRails::PackerUtils.packer_type.upcase_first} error in configuration!
In order to use config/react_on_rails.rb config.build_production_command,
you must edit config/#{ReactOnRails::PackerUtils.packer_type}.yml to include this value in the default configuration:
'#{ReactOnRails::PackerUtils.packer_type}_precompile: false'
Expand Down
24 changes: 12 additions & 12 deletions lib/react_on_rails/packer_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def self.packer_type
nil
end

def self.adapter
def self.packer
return nil unless using_packer?

if using_shakapacker?
Expand All @@ -42,7 +42,7 @@ def self.adapter
def self.dev_server_running?
return false unless using_packer?

adapter.dev_server.running?
packer.dev_server.running?
end

def self.shakapacker_version
Expand All @@ -68,17 +68,17 @@ def self.shakapacker_version_requirement_met?(required_version)
# the hashed server bundle if using the same bundle for the client.
# Otherwise returns a file path.
def self.bundle_js_uri_from_packer(bundle_name)
hashed_bundle_name = adapter.manifest.lookup!(bundle_name)
hashed_bundle_name = packer.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 adapter.dev_server.running? && (!is_server_bundle ||
if packer.dev_server.running? && (!is_server_bundle ||
ReactOnRails.configuration.same_bundle_for_client_and_server)
"#{adapter.dev_server.protocol}://#{adapter.dev_server.host_with_port}#{hashed_bundle_name}"
"#{packer.dev_server.protocol}://#{packer.dev_server.host_with_port}#{hashed_bundle_name}"
else
File.expand_path(File.join("public", hashed_bundle_name)).to_s
end
Expand All @@ -92,31 +92,31 @@ def self.precompile?
end

def self.packer_source_path
adapter.config.source_path
packer.config.source_path
end

def self.packer_source_entry_path
adapter.config.source_entry_path
packer.config.source_entry_path
end

def self.nested_entries?
adapter.config.nested_entries?
packer.config.nested_entries?
end

def self.packer_public_output_path
adapter.config.public_output_path.to_s
packer.config.public_output_path.to_s
end

def self.manifest_exists?
adapter.config.public_manifest_path.exist?
packer.config.public_manifest_path.exist?
end

def self.packer_source_path_explicit?
adapter.config.send(:data)[:source_path].present?
packer.config.send(:data)[:source_path].present?
end

def self.check_manifest_not_cached
return unless using_packer? && adapter.config.cache_manifest?
return unless using_packer? && packer.config.cache_manifest?

msg = <<-MSG.strip_heredoc
ERROR: you have enabled cache_manifest in the #{Rails.env} env when using the
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::PackerUtils.using_packer?
begin
bundle_js_file_path(bundle_name)
rescue ReactOnRails::PackerUtils.adapter::Manifest::MissingEntryError
rescue ReactOnRails::PackerUtils.packer::Manifest::MissingEntryError
File.expand_path(
File.join(ReactOnRails::PackerUtils.packer_public_output_path,
bundle_name)
Expand Down

0 comments on commit 4a99250

Please sign in to comment.