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: 2bab1f58553e
Choose a base ref
...
head repository: opal/opal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 578911b70987
Choose a head ref
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on Nov 16, 2014

  1. Add trailing comma

    elia committed Nov 16, 2014
    Copy the full SHA
    539c819 View commit details
  2. Fix map sources paths

    elia committed Nov 16, 2014
    Copy the full SHA
    578911b View commit details
Showing with 23 additions and 1 deletion.
  1. +1 −1 lib/opal/sprockets/processor.rb
  2. +4 −0 lib/opal/sprockets/server.rb
  3. +18 −0 spec/lib/sprockets/server_spec.rb
2 changes: 1 addition & 1 deletion lib/opal/sprockets/processor.rb
Original file line number Diff line number Diff line change
@@ -104,7 +104,7 @@ def self.new_builder(context)
:const_missing => const_missing_enabled,
:dynamic_require_severity => dynamic_require_severity,
:irb => irb_enabled,
:inline_operators => inline_operators_enabled
:inline_operators => inline_operators_enabled,
}

path_reader = ::Opal::Sprockets::PathReader.new(context.environment, context)
4 changes: 4 additions & 0 deletions lib/opal/sprockets/server.rb
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
require 'rack/showexceptions'
require 'opal/source_map'
require 'sprockets'
require 'sourcemap'
require 'erb'

module Opal
@@ -35,6 +36,9 @@ def call(env)

# "logical_name" of a BundledAsset keeps the .js extension
source = register[asset.logical_path.sub(/\.js$/, '')]
map = JSON.parse(source)
map['sources'] = map['sources'].map {|s| "#{prefix}/#{s}"}
source = map.to_json
return not_found(asset) if source.nil?

return [200, {"Content-Type" => "text/json"}, [source.to_s]]
18 changes: 18 additions & 0 deletions spec/lib/sprockets/server_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'lib/spec_helper'
require 'sourcemap'
require 'rack/test'

describe Opal::Server do
@@ -40,6 +41,23 @@ def app
get '/assets/source_map/subfolder/other_file.map'
expect(last_response).to be_ok
end

it 'serves map on a subfolder file' do
js_path = '/assets/source_map/subfolder/other_file.js'
map_path = '/assets/source_map/subfolder/other_file.map'

get js_path

expect(last_response).to be_ok
received_map_path = extract_linked_map(last_response.body)
expect(File.expand_path(received_map_path, js_path+'/..')).to eq(map_path)


get '/assets/source_map/subfolder/other_file.map'
expect(last_response).to be_ok
map = ::SourceMap::Map.from_json(last_response.body)
expect(map.sources).to include('/assets/source_map/subfolder/other_file.rb')
end
end

def extract_linked_map(body)