From b18bab6beba81b0ad7f1b3659d7da7d796e988de Mon Sep 17 00:00:00 2001 From: Oskar Eichler Date: Fri, 28 Aug 2026 16:28:08 +0300 Subject: [PATCH] Preserve existing source maps when adding line counts --- CHANGELOG.md | 2 ++ README.md | 2 ++ lib/sprockets/preprocessors/default_source_map.rb | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6366a4d92..921c8fe31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ **Master** +- Preserve existing source maps when adding line counts. [Oskar Eichler](https://github.com/OskarEichler) + Get upgrade notes from Sprockets 3.x to 4.x at https://github.com/rails/sprockets/blob/master/UPGRADING.md # 4.4.1 diff --git a/README.md b/README.md index 958b44cd4..c1f2082b5 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,8 @@ If you want to work on Sprockets or better understand how it works read [How Spr ## Behavior Overview +The default source-map preprocessor copies an existing map before adding line-count metadata, preserving caller-owned and frozen maps. + You can interact with Sprockets primarily through directives and file extensions. This section covers how to use each of these things, and the defaults that ship with Sprockets. Since you are likely using Sprockets through another framework (such as the [Rails asset pipeline](http://guides.rubyonrails.org/asset_pipeline.html)), there will be configuration options you can toggle that will change behavior such as what directories or files get compiled. For that documentation you should see your framework's documentation. diff --git a/lib/sprockets/preprocessors/default_source_map.rb b/lib/sprockets/preprocessors/default_source_map.rb index 7f8c9340e..890b68be4 100644 --- a/lib/sprockets/preprocessors/default_source_map.rb +++ b/lib/sprockets/preprocessors/default_source_map.rb @@ -26,7 +26,7 @@ def call(input) "names" => [] } else - result[:map] = map + result[:map] = map.dup end result[:map]["x_sprockets_linecount"] = lines