class Sprockets::AddSourceMapCommentToAssetProcessor


added to the original asset as a comment at the bottom.
with it’s full fingerprint. This is done and then
Finally once we have that file, we can generate a link to it
`SourceMapProcessor` processor.
This will trigger a new asset to be loaded and generated by the
for a JS source map.
we use a use a special mime type. For example ‘application/js-sourcemap+json`
To do this we ensure that the original aset is loaded, then
To add this comment we must have an asset we can link to.
information that is needed to build a source map file.
to the `asset.to_hash[:map]` key. This contains all the
As an asset is built it gets source map information added
//# application.js-80af0efcc960fc2ac93eda2f7b12e3db40ab360bf6ea269ceed3bea3678326f9.map
map. An example of a comment might look like this
to the bottom of a css or JS file that is serving a source
This is a processor designed to add a source map “comment”

def self.call(input)

def self.call(input)
  case input[:content_type]
  when "application/javascript"
    comment = "\n//# sourceMappingURL=%s"
    map_type = "application/js-sourcemap+json"
  when "text/css"
    comment = "\n/*# sourceMappingURL=%s */"
    map_type = "application/css-sourcemap+json"
  else
    fail input[:content_type]
  end
  env = input[:environment]
  uri, _ = env.resolve!(input[:filename], accept: input[:content_type])
  asset = env.load(uri)
  uri, _ = env.resolve!(input[:filename], accept: map_type)
  map = env.load(uri)
  uri, params = URIUtils.parse_asset_uri(input[:uri])
  uri = env.expand_from_root(params[:index_alias]) if params[:index_alias]
  path = PathUtils.relative_path_from(PathUtils.split_subpath(input[:load_path], uri), map.digest_path)
  asset.metadata.merge(
    data: asset.source + (comment % path) + "\n",
    links: asset.links + [asset.uri, map.uri]
  )
end