Skip to content

Commit 90e6592

Browse files
committed
Add transform_values method to Propshaft::Manifest
This will allow libraries to go back to the previous manifest format of a hash with logical_path pointing to the digested_path.
1 parent a96b510 commit 90e6592

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

lib/propshaft/manifest.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ def to_json
7070
end.to_json
7171
end
7272

73+
def transform_values(&block)
74+
@entries.transform_values(&block)
75+
end
76+
7377
private
7478
attr_reader :integrity_hash_algorithm
7579
end

test/propshaft/manifest_test.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,42 @@ class Propshaft::ManifestTest < ActiveSupport::TestCase
116116
assert_nil entry.integrity
117117
end
118118

119+
test "transform_values applies block to all entries" do
120+
manifest = Propshaft::Manifest.new
121+
122+
entry1 = Propshaft::Manifest::ManifestEntry.new(
123+
logical_path: "app.js",
124+
digested_path: "app-abc123.js",
125+
integrity: "sha384-test1"
126+
)
127+
128+
entry2 = Propshaft::Manifest::ManifestEntry.new(
129+
logical_path: "style.css",
130+
digested_path: "style-def456.css",
131+
integrity: nil
132+
)
133+
134+
manifest.push(entry1)
135+
manifest.push(entry2)
136+
137+
# Transform to get digested_path
138+
hash = manifest.transform_values { |entry| entry.digested_path }
139+
assert_equal({ "app.js" => "app-abc123.js", "style.css" => "style-def456.css" }, hash)
140+
141+
# Transform to get integrity
142+
hash = manifest.transform_values { |entry| entry.integrity }
143+
assert_equal({ "app.js" => "sha384-test1", "style.css" => nil }, hash)
144+
145+
# Transform to get logical_path (for demonstration)
146+
hash = manifest.transform_values { |entry| entry.logical_path }
147+
assert_equal({ "app.js" => "app.js", "style.css" => "style.css" }, hash)
148+
end
149+
150+
test "transform_values returns empty hash for empty manifest" do
151+
manifest = Propshaft::Manifest.new
152+
assert_equal({}, manifest.transform_values { |entry| entry.digested_path })
153+
end
154+
119155
private
120156
def create_manifest(integrity_hash_algorithm = nil)
121157
Propshaft::Manifest.new(integrity_hash_algorithm:).tap do |manifest|

0 commit comments

Comments
 (0)