Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: opal/opal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: c6ca107612df
Choose a base ref
...
head repository: opal/opal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: b96212631c96
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Oct 1, 2014

  1. Use logical_path to store the sourcemap

    As it’s used already in the magic comment
    elia committed Oct 1, 2014
    Copy the full SHA
    2e5fb8a View commit details

Commits on Oct 2, 2014

  1. Let the sourcemap server be a rack app

    Previously was a middleware
    elia committed Oct 2, 2014
    Copy the full SHA
    b962126 View commit details
Showing with 26 additions and 21 deletions.
  1. +1 −1 lib/opal/sprockets/processor.rb
  2. +25 −20 lib/opal/sprockets/server.rb
2 changes: 1 addition & 1 deletion lib/opal/sprockets/processor.rb
Original file line number Diff line number Diff line change
@@ -73,7 +73,7 @@ def evaluate(context, locals, &block)
result = builder.build_str(data, path, :prerequired => prerequired)

if self.class.source_map_enabled
register_source_map(context.pathname, result.source_map)
register_source_map(context.logical_path, result.source_map.to_s)
"#{result.to_s}\n//# sourceMappingURL=#{context.logical_path}.map\n"
else
result.to_s
45 changes: 25 additions & 20 deletions lib/opal/sprockets/server.rb
Original file line number Diff line number Diff line change
@@ -12,8 +12,7 @@
module Opal

class SourceMapServer
def initialize app, sprockets, prefix
@app = app
def initialize sprockets, prefix = '/'
@sprockets = sprockets
@prefix = prefix
end
@@ -25,29 +24,36 @@ def inspect
end

def call(env)
app_results = @app.call(env)
# return app_results unless app_results.first == 404

path_info = env['PATH_INFO'].to_s.sub(/^\//, '')
prefix_regex = %r{^(?:#{prefix}/|/)}
path_info = env['PATH_INFO'].to_s.sub(prefix_regex, '')

case path_info
when %r{^(.*)\.map$}
path = $1
asset = sprockets[path]
return app_results if asset.nil?
register = Opal::Processor.source_map_register
source = register[asset.pathname].to_s
return [404, {}, register.keys] if source.nil?
return app_results if source.nil?
return [200, {"Content-Type" => "text/json"}, [source]]
return not_found(path) if asset.nil?

# "logical_name" of a BundledAsset keeps the .js extension
source = register[asset.logical_path.sub(/\.js$/, '')]
return not_found(asset) if source.nil?

return [200, {"Content-Type" => "text/json"}, [source.to_s]]
when %r{^(.*)\.rb$}
source = File.read(sprockets.resolve(path_info))
return app_results if source.nil?
return not_found(path_info) if source.nil?
return [200, {"Content-Type" => "text/ruby"}, [source]]
else
app_results
not_found(path_info)
end
end

def not_found(*messages)
not_found = [404, {}, [{not_found: messages, keys: register.keys}.inspect]]
end

def register
Opal::Processor.source_map_register
end
end

class Server
@@ -99,18 +105,17 @@ def use_gem gem_name
def create_app
server, sprockets, prefix = self, @sprockets, self.prefix
sprockets.logger.level = Logger::DEBUG
@app = Rack::Builder.app do
apps = []
apps << Rack::Builder.app do
not_found = lambda { |env| [404, {}, []] }

use Rack::Deflater
use Rack::ShowExceptions
map(prefix) do
use SourceMapServer, sprockets, prefix if server.source_map_enabled
run sprockets
end
use Index, server if server.use_index
run Rack::Static.new(not_found, :root => server.public_root, :urls => server.public_urls)
end
apps << SourceMapServer.new(sprockets, prefix) if server.source_map_enabled
apps << sprockets
@app = Rack::Cascade.new(apps)
end

def call(env)