Skip to content

Commit

Permalink
Clean old sourcemap assets
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelolx committed Aug 30, 2024
1 parent fb52297 commit 8750853
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/propshaft/output_path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def all_files_from_tree(path)
end

def extract_path_and_digest(digested_path)
digest = digested_path.to_s[/-([0-9a-f]{7,128})\.(?!digested)[^.]+\z/, 1]
digest = digested_path.to_s[/-([0-9a-f]{7,128})\.(?!digested)/, 1]
path = digest ? digested_path.sub("-#{digest}", "") : digested_path

[path, digest]
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/output/one-f2e1ec15.txt.map
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
One from first path map
16 changes: 15 additions & 1 deletion test/propshaft/output_path_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ class Propshaft::OutputPathTest < ActiveSupport::TestCase
setup do
@manifest = {
".manifest.json": ".manifest.json",
"one.txt": "one-f2e1ec14.txt"
"one.txt": "one-f2e1ec14.txt",
"one.txt.map": "one-f2e1ec15.txt.map"
}.stringify_keys
@output_path = Propshaft::OutputPath.new(Pathname.new("#{__dir__}/../fixtures/output"), @manifest)
end
Expand Down Expand Up @@ -49,6 +50,19 @@ class Propshaft::OutputPathTest < ActiveSupport::TestCase
FileUtils.rm(current) if File.exist?(current)
end

test "clean keeps the correct number of versions regardless of the file extension" do
old = output_asset("by_count.txt.map", "old", created_at: Time.now - 300)
current = output_asset("by_count.txt.map", "current", created_at: Time.now - 180)

@output_path.clean(1, 0)

assert File.exist?(current)
assert_not File.exist?(old)
ensure
FileUtils.rm(old) if File.exist?(old)
FileUtils.rm(current) if File.exist?(current)
end

test "clean keeps all versions under a certain age" do
old = output_asset("by_age.txt", "old")
current = output_asset("by_age.txt", "current")
Expand Down

0 comments on commit 8750853

Please sign in to comment.