module Sprockets::SourceMapUtils

def format_source_map(map, input)

#}
# "names" => [..],
# "sources" => ["path.js"],
# "file" => "logical/path.js",
# "version" => 3,
#=> {
format_source_map(map, input)
#}
# "names" => [..],
# "sources" => [/root/logical/path.js],
# "sourceContents" => "blah blah blah",
# "sourceRoot" => "",
# "file" => "stdin",
# "version" => 3,
#=> {
map

Example

Unnecessary attributes are removed

sources => relative from filename
file => logical path
version => 3

NOTE: Does not support index maps

Public: Transpose source maps into a standard format
def format_source_map(map, input)
  filename      = input[:filename]
  load_path     = input[:load_path]
  load_paths    = input[:environment].config[:paths]
  mime_exts     = input[:environment].config[:mime_exts]
  pipeline_exts = input[:environment].config[:pipeline_exts]
  file          = PathUtils.split_subpath(load_path, filename)
  {
    "version"  => 3,
    "file"     => file,
    "mappings" => map["mappings"],
    "sources"  => map["sources"].map do |source|
      source = URIUtils.split_file_uri(source)[2] if source.start_with? "file://"
      source = PathUtils.join(File.dirname(filename), source) unless PathUtils.absolute_path?(source)
      _, source = PathUtils.paths_split(load_paths, source) 
      source = PathUtils.relative_path_from(file, source)
      PathUtils.set_pipeline(source, mime_exts, pipeline_exts, :source)
    end,
    "names"    => map["names"]
  }
end