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

Fix broken sourcemaps when using esbuild --public-path #515

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion lib/sprockets/rails/sourcemapping_url_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Sprockets
module Rails
# Rewrites source mapping urls with the digested paths and protect against semicolon appending with a dummy comment line
class SourcemappingUrlProcessor
REGEX = /\/\/# sourceMappingURL=(.*\.map)/
REGEX = /\/\/# sourceMappingURL=(?:.*\/)?(.*\.map)/

class << self
def call(input)
Expand Down
20 changes: 20 additions & 0 deletions test/test_sourcemapping_url_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,26 @@ def asset_path(path, options = {})
assert_equal({ data: "var mapped;\n//# sourceMappingURL=/assets/mapped-HEXGOESHERE.js.map\n//!\n" }, output)
end

def test_removing_path_prefix
@env.context_class.class_eval do
def resolve(path, **kargs)
if path == 'mapped.js.map'
"/assets/mapped.js.map"
else
raise Sprockets::FileNotFound
end
end

def asset_path(path, options = {})
"/assets/mapped-HEXGOESHERE.js.map"
end
end

input = { environment: @env, data: "var mapped;\n//# sourceMappingURL=/some/prefix/mapped.js.map", name: 'mapped', filename: 'mapped.js', metadata: {} }
output = Sprockets::Rails::SourcemappingUrlProcessor.call(input)
assert_equal({ data: "var mapped;\n//# sourceMappingURL=/assets/mapped-HEXGOESHERE.js.map\n//!\n" }, output)
end

def test_resolving_erroneously_without_map_extension
@env.context_class.class_eval do
def resolve(path, **kargs)
Expand Down