Skip to content

Commit

Permalink
Merge pull request #452 from rails/schneems/remove-source-map-hack
Browse files Browse the repository at this point in the history
Remove source map hack
  • Loading branch information
schneems committed Jan 12, 2017
2 parents d22a4ea + b88299a commit 983b53c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
8 changes: 1 addition & 7 deletions lib/sprockets.rb
Expand Up @@ -99,13 +99,7 @@ module Sprockets
end

register_pipeline :default do |env, type, file_type|
# TODO: Hack for to inject source map transformer
if (type == "application/js-sourcemap+json" && file_type != "application/js-sourcemap+json") ||
(type == "application/css-sourcemap+json" && file_type != "application/css-sourcemap+json")
[SourceMapProcessor]
else
env.default_processors_for(type, file_type)
end
env.default_processors_for(type, file_type)
end

require 'sprockets/source_map_comment_processor'
Expand Down
4 changes: 3 additions & 1 deletion lib/sprockets/directive_processor.rb
Expand Up @@ -70,7 +70,9 @@ def _call(input)
@uri = input[:uri]
@filename = input[:filename]
@dirname = File.dirname(@filename)
@content_type = input[:content_type]
# If loading a source map file like `application.js.map` resolve
# dependencies using `.js` instead of `.js.map`
@content_type = SourceMapProcessor.original_content_type(input[:content_type], error_when_not_found: false)
@required = Set.new(input[:metadata][:required])
@stubbed = Set.new(input[:metadata][:stubbed])
@links = Set.new(input[:metadata][:links])
Expand Down
12 changes: 7 additions & 5 deletions lib/sprockets/source_map_processor.rb
Expand Up @@ -3,21 +3,23 @@

module Sprockets
class SourceMapProcessor
def self.call(input)
case input[:content_type]
def self.original_content_type(source_map_content_type, error_when_not_found: true)
case source_map_content_type
when "application/js-sourcemap+json"
accept = "application/javascript"
when "application/css-sourcemap+json"
accept = "text/css"
else
fail input[:content_type]
fail(source_map_content_type) if error_when_not_found
source_map_content_type
end
end

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

env = input[:environment]

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

Expand Down

0 comments on commit 983b53c

Please sign in to comment.