Skip to content

Preserve existing source maps when adding line counts - #854

Closed
OskarEichler wants to merge 1 commit into
rails:mainfrom
OskarEichler:codex/default-map-copy
Closed

Preserve existing source maps when adding line counts#854
OskarEichler wants to merge 1 commit into
rails:mainfrom
OskarEichler:codex/default-map-copy

Conversation

@OskarEichler

Copy link
Copy Markdown

Summary

The default source-map preprocessor copies an existing map before adding line-count metadata, preserving caller-owned and frozen maps.

Only the top-level existing map is copied. This preprocessor only writes x_sprockets_linecount; nested arrays/maps are not edited or deeply copied. Nil/empty map construction, line counts, existing metadata and generated output remain unchanged. Verified frozen/mutable maps, index maps, existing line counts, empty content, newline/tail/CRLF/Unicode input.

Reproduction

With require "sprockets"; require "tmpdir":

env = Sprockets::Environment.new("/tmp")
map = {"version"=>3, "file"=>"entry.js", "sources"=>["entry.js"],
       "names"=>[], "mappings"=>"AAAA"}.freeze
input = {data:"var a=1;\n", metadata:{map:map}, filename:"/tmp/entry.js",
         load_path:"/tmp", environment:env}
result = Sprockets::Preprocessors::DefaultSourceMap.new.call(input)
p result[:map]["x_sprockets_linecount"] # 1; previously FrozenError.
p map.key?("x_sprockets_linecount") # false; caller map remains unchanged.

Verification

  • Isolated patch: unchanged bundle exec rake test and bundle exec rake test_isolated each pass 913 tests /4,109 assertions /zero failures/errors /four skips on Ruby 3.2.11 and 4.0.6.
  • 252 focused external checks pass on each Ruby. Baseline reproduces the defect. All Ruby commands use rbenv.
  • Full RuboCop: 133 files, zero offenses. Changed Ruby syntax passes both Rubies; git diff --check passes.
  • Gem build/content comparison preserves all 84 package paths, version 4.4.1, Ruby >=2.5, and dependency metadata; only README, CHANGELOG and relevant runtime files differ.

Compatibility and limitations

Breaking changes: no intended change to valid supported behavior. Incorrect cache reuse/input mutation/resource retention above changes. No new dependency or version upgrade.

Based on installed release/current upstream main 49d9f20c00ac7d9a7ee57db058961edcccd86699. This is upstream-only; no application fork pin or deployment. Older Ruby/Linux/JRuby verification is left to upstream CI, not claimed locally. Existing tests were not edited or added under the requesting repository's no-test-edit policy; focused reproductions ran externally. Prepared with AI assistance. This is not an exhaustive Sprockets review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants