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

Commits on Nov 12, 2014

  1. Bump version for next beta release

    And update the CHANGELOG.
    elia committed Nov 12, 2014
    Copy the full SHA
    6d9a7ba View commit details

Commits on Nov 13, 2014

  1. Deprecate Opal::Sprockets::Environment

    It can easily be replaced by `Opal::Server` or by appending `Opal.paths` 
    to a `Sprockets::Environment`:
    
        Sprockets::Environment.new.tap { |e| Opal.paths.each {|p| e.append_path(p)} }
    elia committed Nov 13, 2014
    Copy the full SHA
    f409f7f View commit details

Commits on Nov 15, 2014

  1. Copy the full SHA
    9deb138 View commit details
  2. Use File.basename to get correct path

    ryanstout authored and elia committed Nov 15, 2014
    Copy the full SHA
    2bab1f5 View commit details
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## edge (upcoming 0.7)

* Deprecated `Opal::Sprockets::Environment`. It can easily be replaced by `Opal::Server` or by appending `Opal.paths` to a `Sprockets::Environment`:

Sprockets::Environment.new.tap { |e| Opal.paths.each {|p| e.append_path(p)} }

* Add `Set` methods `#classify`, `#collect!`, `#map!`, `#subtract` `#replace`,
`#difference` and `#eql?`

1 change: 0 additions & 1 deletion lib/opal/sprockets.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require 'opal/sprockets/environment'
require 'opal/sprockets/processor'
require 'opal/sprockets/erb'
require 'opal/sprockets/server'
2 changes: 2 additions & 0 deletions lib/opal/sprockets/environment.rb
Original file line number Diff line number Diff line change
@@ -19,6 +19,8 @@ def self.process asset
# do this for you.
class Environment < ::Sprockets::Environment
def initialize *args
warn "Opal::Sprockets::Environment is deprecated. "\
"Please use Opal::Server directly or append Opal.paths to the environment manually."
super
append_opal_paths
end
2 changes: 1 addition & 1 deletion lib/opal/sprockets/processor.rb
Original file line number Diff line number Diff line change
@@ -75,7 +75,7 @@ def evaluate(context, locals, &block)

if self.class.source_map_enabled
register_source_map(context.logical_path, result.source_map.to_s)
"#{result.to_s}\n//# sourceMappingURL=#{context.logical_path}.map\n"
"#{result.to_s}\n//# sourceMappingURL=#{File.basename(context.logical_path)}.map\n"
else
result.to_s
end
6 changes: 4 additions & 2 deletions lib/opal/sprockets/server.rb
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
require 'rack/directory'
require 'rack/showexceptions'
require 'opal/source_map'
require 'opal/sprockets/environment'
require 'sprockets'
require 'erb'

module Opal
@@ -73,10 +73,12 @@ def initialize debug_or_options = {}
@use_index = true
@public_root = nil
@public_urls = ['/']
@sprockets = options.fetch(:sprockets, Environment.new)
@sprockets = options.fetch(:sprockets, ::Sprockets::Environment.new)
@debug = options.fetch(:debug, true)
@prefix = options.fetch(:prefix, '/assets')

Opal.paths.each { |p| @sprockets.append_path(p) }

yield self if block_given?
create_app
end
2 changes: 1 addition & 1 deletion lib/opal/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Opal
VERSION = '0.7.0.beta2'
VERSION = '0.7.0.beta3'
end
1 change: 1 addition & 0 deletions spec/lib/fixtures/source_map.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
puts 'smap!'
1 change: 1 addition & 0 deletions spec/lib/fixtures/source_map/subfolder/other_file.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
puts 'other!'
30 changes: 0 additions & 30 deletions spec/lib/sprockets/environment_spec.rb

This file was deleted.

2 changes: 1 addition & 1 deletion spec/lib/sprockets/path_reader_spec.rb
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
describe Opal::Sprockets::PathReader do
subject(:path_reader) { described_class.new(env, context) }

let(:env) { Opal::Environment.new }
let(:env) { Sprockets::Environment.new.tap { |e| Opal.paths.each {|p| e.append_path(p)} } }
let(:context) { double('context', depend_on: nil, depend_on_asset: nil) }

let(:logical_path) { 'sprockets_file' }
30 changes: 30 additions & 0 deletions spec/lib/sprockets/server_spec.rb
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ def app
described_class.new { |s|
s.main = 'opal'
s.debug = false
s.append_path "#{__dir__}/../fixtures"
s.sprockets.logger = Logger.new('/dev/null')
}
end
@@ -17,4 +18,33 @@ def app
expect(last_response).to be_ok
end

describe 'source maps' do
it 'serves map on a top level file' do
get '/assets/source_map.js'
expect(last_response).to be_ok

get '/assets/source_map.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
end
end

def extract_linked_map(body)
source_map_comment_regexp = %r{//# sourceMappingURL=(.*)$}
expect(body).to match(source_map_comment_regexp)
body.scan(source_map_comment_regexp).first.first
end
end