Skip to content

Commit

Permalink
Remove config for asset host sensitivity
Browse files Browse the repository at this point in the history
  • Loading branch information
ahangarha committed Oct 16, 2023
1 parent 4e89ba0 commit 4082109
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
3 changes: 0 additions & 3 deletions lib/install/config/shakapacker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ default: &default
# Select whether the compiler will use SHA digest ('digest' option) or most most recent modified timestamp ('mtime') to determine freshness
compiler_strategy: digest

# Set whether the compiler should be sensitive to the provided asset host
compiler_strategy_asset_host_sensitive: false

# Select whether the compiler will always use a content hash and not just in production
# Don't use contentHash except for production for performance
# https://webpack.js.org/guides/build-performance/#avoid-production-specific-tooling
Expand Down
7 changes: 5 additions & 2 deletions lib/shakapacker/digest_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,16 @@ def record_compilation_digest

def compilation_digest_path
path = "last-compilation-digest-#{Shakapacker.env}"
path += "-#{generate_host_hash}" if Shakapacker.config.fetch(:compiler_strategy_asset_host_sensitive)
path += "-#{generate_host_hash}" if generate_host_hash.present?

config.cache_path.join(path)
end

def generate_host_hash
@generated_host_hashes ||= {}
# Using hash for memoizing the host hash is to make testing easier.
# The default value, prevents generating hash in the situation where no value for asset_host
# and SHAKAPACKER_ASSET_HOST are provided, leading to not add hash to the asset path.
@generated_host_hashes ||= { [nil, nil] => "" }

keys = [Rails.application.config.asset_host, ENV["SHAKAPACKER_ASSET_HOST"]]

Expand Down
1 change: 1 addition & 0 deletions spec/backward_compatibility_specs/digest_strategy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def remove_compilation_digest_path

before :all do
@digest_strategy = Webpacker::DigestStrategy.new
ENV["SHAKAPACKER_ASSET_HOST"] = nil
remove_compilation_digest_path
end

Expand Down
8 changes: 4 additions & 4 deletions spec/shakapacker/digest_strategy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def remove_compilation_digest_path
end

it "is stale when host changes" do
allow(Shakapacker.config).to receive(:fetch).with(any_args).and_call_original
allow(Shakapacker.config).to receive(:fetch).with(:compiler_strategy_asset_host_sensitive).and_return(true)
# allow(Shakapacker.config).to receive(:fetch).with(any_args).and_call_original
# allow(Shakapacker.config).to receive(:fetch).with(:compiler_strategy_asset_host_sensitive).and_return(true)

ENV["SHAKAPACKER_ASSET_HOST"] = "the-host"

Expand All @@ -52,8 +52,8 @@ def remove_compilation_digest_path
end

it "generates correct compilation_digest_path with " do
allow(Shakapacker.config).to receive(:fetch).with(any_args).and_call_original
allow(Shakapacker.config).to receive(:fetch).with(:compiler_strategy_asset_host_sensitive).and_return(true)
# allow(Shakapacker.config).to receive(:fetch).with(any_args).and_call_original
# allow(Shakapacker.config).to receive(:fetch).with(:compiler_strategy_asset_host_sensitive).and_return(true)

ENV["SHAKAPACKER_ASSET_HOST"] = "custom-path"

Expand Down

0 comments on commit 4082109

Please sign in to comment.