Skip to content

Commit

Permalink
fixes webpacker:clean erroring because of nested hashes on manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
LuanGB committed Oct 15, 2019
1 parent 2cef2fd commit 625a5ec
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/webpacker/commands.rb
Expand Up @@ -7,10 +7,11 @@ 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_to_be_removed = files_in_manifest.flat_map do |file_in_manifest|
files_in_manifest = process_manifest_hash(manifest.refresh)
files_to_be_removed = files_in_manifest.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}/)
next "" unless versions_of_file.any?
versions_of_file.map do |version_of_file|
next if version_of_file == file_in_manifest

Expand All @@ -36,4 +37,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
6 changes: 6 additions & 0 deletions test/command_test.rb
Expand Up @@ -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

0 comments on commit 625a5ec

Please sign in to comment.