From cfb5fac5b270c70e500f634583b68493246eae95 Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Tue, 6 Dec 2022 19:43:05 +0100 Subject: [PATCH] Prevent adding duplicate lines for source maps --- lib/tasks/sourcemap.rake | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/tasks/sourcemap.rake b/lib/tasks/sourcemap.rake index a5a7964c..107c6fd2 100644 --- a/lib/tasks/sourcemap.rake +++ b/lib/tasks/sourcemap.rake @@ -48,7 +48,11 @@ namespace :assets do end # Read the source map file and append the source map link - write_asset(file, "#{file.read}\n#{mapping_string}", manifest) + existing_file_content = file.readlines + next if existing_file_content.blank? || existing_file_content[-1].include?(mapping_string) + + new_content = existing_file_content + ["\n", mapping_string] + write_asset(file, new_content.join, manifest) end File.write(manifest_path, manifest_json.to_json)