Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed crash because hashes in manifest #2315

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 14 additions & 1 deletion lib/webpacker/commands.rb
Expand Up @@ -7,7 +7,10 @@ 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 = []
scan_for_paths(manifest.refresh, files_in_manifest)
files_in_manifest.uniq!

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}/)
Expand Down Expand Up @@ -36,4 +39,14 @@ def compile
manifest.refresh if success
end
end

def scan_for_paths(hash, paths)
hash.values.each do |value|
if value.is_a?(Hash)
scan_for_paths(value, paths)
else
paths << File.join(config.root_path, "public", value)
end
end
end
end