DEV: Fix production sourcemaps with Ember CLI (#16707)

22a7905f restructured how we load Ember CLI assets in production. Unfortunately, it also broke sourcemaps for those assets. This commit fixes that regression via a couple of changes:

- It adds the necessary `.map` paths to `config.assets.precompile`
- It swaps Sprockets' default `SourcemappingUrlProcessor` with an extended version which maintains relative URLs of maps
This commit is contained in:
David Taylor
2022-05-11 10:23:32 +01:00
committed by GitHub
parent 0689338060
commit 476bd1d237
6 changed files with 66 additions and 2 deletions

View File

@ -0,0 +1,31 @@
# frozen_string_literal: true
require 'discourse_sourcemapping_url_processor'
describe DiscourseSourcemappingUrlProcessor do
def process(input)
env = Sprockets::Environment.new
env.context_class.class_eval do
def resolve(path, **kargs)
"/assets/mapped.js.map"
end
def asset_path(path, options = {})
"/assets/mapped-HEXGOESHERE.js.map"
end
end
input = { environment: env, data: input, name: 'mapped', filename: 'mapped.js', metadata: {} }
DiscourseSourcemappingUrlProcessor.call(input)[:data]
end
it 'maintains relative paths' do
output = process "var mapped;\n//# sourceMappingURL=mapped.js.map"
expect(output).to eq("var mapped;\n//# sourceMappingURL=mapped-HEXGOESHERE.js.map\n//!\n")
end
it 'uses default behaviour for non-adjacent relative paths' do
output = process "var mapped;\n//# sourceMappingURL=/assets/mapped.js.map"
expect(output).to eq("var mapped;\n//# sourceMappingURL=/assets/mapped-HEXGOESHERE.js.map\n//!\n")
end
end