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 sourcemap with path prefix when using esbuild with publicPath #501

Open
wants to merge 1 commit 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 @@ -23,7 +23,7 @@ def call(input)

private
def combine_sourcemap_logical_path(sourcefile:, sourcemap:)
if (parts = sourcefile.split("/")).many?
if (parts = sourcefile.split("/")).many? && !sourcemap.split("/").many?
parts[0..-2].append(sourcemap).join("/")
else
sourcemap
Expand Down
21 changes: 21 additions & 0 deletions test/test_sourcemapping_url_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,25 @@ def resolve(path, **kargs)
output = Sprockets::Rails::SourcemappingUrlProcessor.call(input)
assert_equal({ data: "var mapped;\n" }, output)
end


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

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

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