26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/sprockets-esbuild/transformers.rb', line 26
def call(input)
data = input[:data]
input[:cache].fetch([cache_key, data]) do
out, err, status = Open3.capture3(*ESBUILD, '--sourcemap',
"--sourcefile=#{input[:filename]}", "--loader=#{loader}",
stdin_data: input[:data])
match = out.match %r{^//# sourceMappingURL=data:application/json;base64,(.*)\s*}
if match
out[match.begin(0)..match.end(0)] = ''
map = JSON.parse(Base64.decode64(match[1]))
map = SourceMapUtils.format_source_map(map, input)
map = SourceMapUtils.combine_source_maps(input[:metadata][:map], map)
else
map = nil
end
if status.success? and err.empty?
if map
{ data: out, map: map }
else
out
end
else
raise Error, "esbuild exit status=#{status.exitstatus}\n#{err}"
end
end
end
|