Skip to content

Commit

Permalink
Include config.assets.version in digests (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhh authored Feb 10, 2022
1 parent b569c82 commit a4ddf9a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/propshaft/assembly.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def initialize(config)
end

def load_path
@load_path ||= Propshaft::LoadPath.new(config.paths)
@load_path ||= Propshaft::LoadPath.new(config.paths, version: config.version)
end

def resolver
Expand Down
8 changes: 4 additions & 4 deletions lib/propshaft/asset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
require "action_dispatch/http/mime_type"

class Propshaft::Asset
attr_reader :path, :logical_path
attr_reader :path, :logical_path, :version

def initialize(path, logical_path:)
@path, @logical_path = path, Pathname.new(logical_path)
def initialize(path, logical_path:, version: nil)
@path, @logical_path, @version = path, Pathname.new(logical_path), version
end

def content
Expand All @@ -21,7 +21,7 @@ def length
end

def digest
@digest ||= Digest::SHA1.hexdigest(content)
@digest ||= Digest::SHA1.hexdigest("#{content}#{version}")
end

def digested_path
Expand Down
9 changes: 5 additions & 4 deletions lib/propshaft/load_path.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
require "propshaft/asset"

class Propshaft::LoadPath
attr_reader :paths
attr_reader :paths, :version

def initialize(paths = [])
@paths = Array(paths).collect { |path| Pathname.new(path) }
def initialize(paths = [], version: nil)
@paths = Array(paths).collect { |path| Pathname.new(path) }
@version = version
end

def find(asset_name)
Expand Down Expand Up @@ -47,7 +48,7 @@ def assets_by_path
paths.each do |path|
without_dotfiles(all_files_from_tree(path)).each do |file|
logical_path = file.relative_path_from(path)
mapped[logical_path.to_s] ||= Propshaft::Asset.new(file, logical_path: logical_path)
mapped[logical_path.to_s] ||= Propshaft::Asset.new(file, logical_path: logical_path, version: version)
end if path.exist?
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/propshaft/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class Railtie < ::Rails::Railtie
config.assets = ActiveSupport::OrderedOptions.new
config.assets.paths = []
config.assets.excluded_paths = []
config.assets.version = "1"
config.assets.prefix = "/assets"
config.assets.compilers = [
[ "text/css", Propshaft::Compilers::CssAssetUrls ],
Expand Down
8 changes: 8 additions & 0 deletions test/propshaft/load_path_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ class Propshaft::LoadPathTest < ActiveSupport::TestCase
end
end

test "manifest with version" do
@load_path = Propshaft::LoadPath.new(@load_path.paths, version: "1")
@load_path.manifest.tap do |manifest|
assert_equal "one-c9373b685d5a63e4a1de7c6836a73239df552e2b.txt", manifest["one.txt"]
assert_equal "nested/three-a41a5d38da5afe428eca74b243f50405f28a6b54.txt", manifest["nested/three.txt"]
end
end

test "missing load path directory" do
assert_nil Propshaft::LoadPath.new(Pathname.new("#{__dir__}/../fixtures/assets/nowhere")).find("missing")
end
Expand Down

0 comments on commit a4ddf9a

Please sign in to comment.