From 0c7a9f750ddf3a4fd9a6ad9f91331c80b15c20fd Mon Sep 17 00:00:00 2001 From: Luan Date: Mon, 7 Oct 2019 16:55:23 -0300 Subject: [PATCH] fixes webpacker:clean erroring because of nested hashes on manifest --- lib/webpacker/commands.rb | 11 ++++++++++- test/command_test.rb | 6 ++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/webpacker/commands.rb b/lib/webpacker/commands.rb index c58b67eb7..8203dc305 100644 --- a/lib/webpacker/commands.rb +++ b/lib/webpacker/commands.rb @@ -7,7 +7,7 @@ def initialize(webpacker) def clean(count_to_keep = 2) if config.public_output_path.exist? && config.public_manifest_path.exist? - files_in_manifest = manifest.refresh.values.map { |f| File.join config.root_path, "public", f } + files_in_manifest = process_manifest_hash(manifest.refresh) files_to_be_removed = files_in_manifest.flat_map do |file_in_manifest| file_prefix, file_ext = file_in_manifest.scan(/(.*)[0-9a-f]{20}(.*)/).first versions_of_file = Dir.glob("#{file_prefix}*#{file_ext}").grep(/#{file_prefix}[0-9a-f]{20}#{file_ext}/) @@ -36,4 +36,13 @@ def compile manifest.refresh if success end end + + private + def process_manifest_hash(manifest_hash) + manifest_hash.values.map do |value| + next process_manifest_hash(value) if value.is_a?(Hash) + + File.join(config.root_path, "public", value) + end.flatten + end end diff --git a/test/command_test.rb b/test/command_test.rb index b1e70ac31..236ce7d11 100644 --- a/test/command_test.rb +++ b/test/command_test.rb @@ -24,4 +24,10 @@ def test_compile_command_returns_failure_status_when_stale end end end + + def test_clean_command_works_with_nested_hashes_and_without_any_compiled_files + File.stub :delete, true do + assert Webpacker.commands.clean + end + end end