Skip to content

Commit

Permalink
Warn on missing asset in compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
brenogazzola committed Nov 22, 2021
1 parent 1d87136 commit 0d9a03a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
7 changes: 4 additions & 3 deletions lib/propshaft/compilers/css_asset_urls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def initialize(assembly)
end

def compile(logical_path, input)
input.gsub(ASSET_URL_PATTERN) { asset_url resolve_path(logical_path.dirname, $1) }
input.gsub(ASSET_URL_PATTERN) { asset_url resolve_path(logical_path.dirname, $1), logical_path, $1 }
end

private
Expand All @@ -25,11 +25,12 @@ def resolve_path(directory, filename)
end
end

def asset_url(resolved_path)
def asset_url(resolved_path, logical_path, pattern)
if asset = assembly.load_path.find(resolved_path)
%[url("#{assembly.config.prefix}/#{asset.digested_path}")]
else
raise Propshaft::MissingAssetError.new(resolved_path)
Propshaft.logger.warn "Removed '#{pattern}' for missing asset '#{resolved_path}' in #{logical_path}"
%[url("")]
end
end
end
5 changes: 2 additions & 3 deletions test/propshaft/compilers/css_asset_urls_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,8 @@ class Propshaft::Compilers::CssAssetUrlsTest < ActiveSupport::TestCase
end

test "missing asset" do
assert_raise Propshaft::MissingAssetError do
compile_asset_with_content(%({ background: url(missing.jpg); }))
end
compiled = compile_asset_with_content(%({ background: url('file-not-found.jpg'); }))
assert_match /{ background: url\(""\); }/, compiled
end

private
Expand Down

0 comments on commit 0d9a03a

Please sign in to comment.