Method: Sprockets::SourceMapProcessor.call

Defined in:
lib/sprockets/source_map_processor.rb

.call(input) ⇒ Object



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
# File 'lib/sprockets/source_map_processor.rb', line 26

def self.call(input)
  links = Set.new(input[:metadata][:links])
  env = input[:environment]

  uri, _ = env.resolve!(input[:filename], accept: self.original_content_type(input[:content_type]))
  asset  = env.load(uri)
  map    = asset.[:map]

  # TODO: Because of the default piplene hack we have to apply dependencies
  #       from compiled asset to the source map, otherwise the source map cache
  #       will never detect the changes from directives
  dependencies = Set.new(input[:metadata][:dependencies])
  dependencies.merge(asset.[:dependencies])

  map["file"] = PathUtils.split_subpath(input[:load_path], input[:filename])
  sources = map["sections"] ? map["sections"].map { |s| s["map"]["sources"] }.flatten : map["sources"]

  sources.each do |source|
    source = PathUtils.join(File.dirname(map["file"]), source)
    uri, _ = env.resolve!(source)
    links << uri
  end

  json = JSON.generate(map)

  { data: json, links: links, dependencies: dependencies }
end