opal-sprockets 0.4.2.pre.1.0.11.0.3.1 → 0.4.2.0.11.0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c9f4fd15ecf2dfdcb1d252b9fe800c835c106295c7a46494876f0c88ad1c3342
4
- data.tar.gz: 6b142da62511a90f76d62546b832a9b7983fd8b59cee93ec5ea0b2db7be81d82
3
+ metadata.gz: dca9f9cc92bc73a4bdaa577f7a32b962af5ec4e535adbd3c06a5b80fc835af63
4
+ data.tar.gz: 5d2beb0fc445ba75afecec5e5c40344a6c561ce3a38b7c3d5a58dc6dc8a8c0b7
5
5
  SHA512:
6
- metadata.gz: 5b8510a4797ea716f7c5b38d0a993dda59dc581dfcdfeb7387ad0f8e8204a04f27926f02103f0402c621351ea7e68374594aca009e7b80054d3a859261ced89d
7
- data.tar.gz: 14c629c523cfa8a82e3c1f524fc9975048ac08bfdf11347d79b2022a9075131ce970155bd2d6c5979b1a61a22dc7a2c503d30fbf519a3a859a62ba2a2075bab8
6
+ metadata.gz: aa1dc4f51c6effa43f9c1fb73a6fc310a4e94ef111b32b0242d78498374f2f15a90a1687df73aa2ec63f823bf32c3b9795cc1e8bfe92bf478776a723665b397d
7
+ data.tar.gz: 9c79b7a79613d9e242621477f4a0e170811bdda6c013593d5bfba26830d15cb01f61b7ab8afdba565b0425caf272d7cf7e15b79ac05dd33d74ea2cd307d95b5c
data/.gitignore CHANGED
@@ -2,7 +2,7 @@
2
2
  *.gem
3
3
  .yardoc
4
4
  .bundle
5
- Gemfile.lock
5
+ /Gemfile.lock
6
6
  build/
7
7
  /.github_access_token
8
8
  /tmp
data/.travis.yml CHANGED
@@ -1,5 +1,11 @@
1
1
  language: ruby
2
2
 
3
+ branches:
4
+ only:
5
+ - master
6
+ - /^.*-stable$/
7
+ - /^.*ci-check$/
8
+
3
9
  matrix:
4
10
  include:
5
11
  - rvm: 2.1.10
@@ -11,6 +17,18 @@ matrix:
11
17
  - rvm: 2.4.4
12
18
  env: SPROCKETS_VERSION='~> 3.7.1'
13
19
  - rvm: 2.5.1
20
+ env: SPROCKETS_VERSION='~> 3.7.1'
21
+
22
+ - rvm: 2.1.10
23
+ env: OPAL_VERSION='~> 0.11.3' RACK_VERSION='< 2.0.0' SPROCKETS_VERSION='~> 3.4.1'
24
+ - rvm: 2.2.10
25
+ env: OPAL_VERSION='~> 0.11.3' SPROCKETS_VERSION='~> 3.5.2'
26
+ - rvm: 2.3.7
27
+ env: OPAL_VERSION='~> 0.11.3' SPROCKETS_VERSION='~> 3.6.3'
28
+ - rvm: 2.4.4
29
+ env: OPAL_VERSION='~> 0.11.3' SPROCKETS_VERSION='~> 3.7.1'
30
+ - rvm: 2.5.1
31
+ env: OPAL_VERSION='~> 0.11.3' SPROCKETS_VERSION='~> 3.7.1'
14
32
 
15
33
  notifications:
16
34
  irc: "irc.freenode.org#opal"
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [v0.4.2](https://github.com/opal/opal-sprockets/compare/v0.4.1.0.11.0.3.1...v0.4.2.0.11.0.3.1)
4
+
5
+ *7 September 2018*
6
+
7
+ - Inline source-maps with their source-contents for better performance and simpler architecture
8
+
9
+
3
10
  ## [v0.4.1](https://github.com/opal/opal-sprockets/compare/v0.4.0.0.10.0.3.0.0...v0.4.1.0.11.0.3.1)
4
11
 
5
12
  *30 December 2017*
data/Gemfile CHANGED
@@ -2,7 +2,10 @@ source 'https://rubygems.org'
2
2
  gemspec
3
3
 
4
4
  opal_path = File.expand_path('../opal')
5
- if File.exist? opal_path
5
+
6
+ if ENV['OPAL_VERSION']
7
+ gem 'opal', ENV['OPAL_VERSION']
8
+ elsif File.exist? opal_path
6
9
  gem 'opal', path: opal_path
7
10
  else
8
11
  gem 'opal', github: 'opal/opal'
@@ -0,0 +1,38 @@
1
+ GIT
2
+ remote: git://github.com/opal/opal.git
3
+ revision: d77bd3ce19e101988578cdb6314d659491a77844
4
+ specs:
5
+ opal (0.11.99.dev)
6
+ ast (>= 2.3.0)
7
+ parser (= 2.5.1.0)
8
+
9
+ PATH
10
+ remote: ..
11
+ specs:
12
+ opal-sprockets (0.4.2.pre.1.0.11.0.3.1)
13
+ opal (~> 0.11.0)
14
+ sprockets (~> 3.1)
15
+ tilt (>= 1.4)
16
+
17
+ GEM
18
+ remote: https://rubygems.org/
19
+ specs:
20
+ ast (2.4.0)
21
+ concurrent-ruby (1.0.5)
22
+ parser (2.5.1.0)
23
+ ast (~> 2.4.0)
24
+ rack (2.0.5)
25
+ sprockets (3.7.2)
26
+ concurrent-ruby (~> 1.0)
27
+ rack (> 1, < 3)
28
+ tilt (2.0.8)
29
+
30
+ PLATFORMS
31
+ ruby
32
+
33
+ DEPENDENCIES
34
+ opal!
35
+ opal-sprockets!
36
+
37
+ BUNDLED WITH
38
+ 1.16.4
@@ -1,9 +1,9 @@
1
1
  require 'set'
2
+ require 'base64'
2
3
  require 'tilt/opal'
3
4
  require 'sprockets'
4
5
  require 'opal/builder'
5
6
  require 'opal/sprockets/path_reader'
6
- require 'opal/sprockets/source_map_server'
7
7
 
8
8
  $OPAL_SOURCE_MAPS = {}
9
9
 
@@ -49,11 +49,13 @@ module Opal
49
49
  process_required_trees(compiler.required_trees, context)
50
50
 
51
51
  if Opal::Config.source_map_enabled
52
- map_contents = compiler.source_map.as_json.to_json
53
- ::Opal::SourceMapServer.set_map_cache(sprockets, logical_path, map_contents)
52
+ map_data = compiler.source_map.as_json
53
+ # Opal 0.11 doesn't fill sourcesContent
54
+ add_sources_content_if_missing(map_data, data)
55
+ "#{result}\n#{to_data_uri_comment(map_data.to_json)}"
56
+ else
57
+ result.to_s
54
58
  end
55
-
56
- result.to_s
57
59
  end
58
60
 
59
61
  def self.sprockets_extnames_regexp(sprockets)
@@ -135,6 +137,14 @@ module Opal
135
137
 
136
138
  private
137
139
 
140
+ def add_sources_content_if_missing(data, content)
141
+ data[:sourcesContent] = data.delete(:sourcesContent) || data.delete('sourcesContent') || [content]
142
+ end
143
+
144
+ def to_data_uri_comment(map_to_json)
145
+ "//# sourceMappingURL=data:application/json;base64,#{Base64.encode64(map_to_json).delete("\n")}"
146
+ end
147
+
138
148
  def stubbed_files
139
149
  ::Opal::Config.stubbed_files
140
150
  end
@@ -1,15 +1,10 @@
1
+ require 'erb'
1
2
  require 'rack'
2
- require 'opal/source_map'
3
3
  require 'sprockets'
4
- require 'erb'
5
- require 'opal/sprockets/source_map_server'
6
- require 'opal/sprockets/source_map_header_patch'
7
4
 
8
5
  module Opal
9
6
  module Sprockets
10
7
  class Server
11
- SOURCE_MAPS_PREFIX_PATH = '/__OPAL_SOURCE_MAPS__'
12
-
13
8
  attr_accessor :debug, :use_index, :index_path, :main, :public_root,
14
9
  :public_urls, :sprockets, :prefix
15
10
 
@@ -51,25 +46,12 @@ module Opal
51
46
  def create_app
52
47
  server, sprockets, prefix = self, @sprockets, self.prefix
53
48
  sprockets.logger.level ||= Logger::DEBUG
54
- source_map_enabled = self.source_map_enabled
55
- if source_map_enabled
56
- maps_prefix = SOURCE_MAPS_PREFIX_PATH
57
- maps_app = SourceMapServer.new(sprockets, maps_prefix)
58
- ::Opal::Sprockets::SourceMapHeaderPatch.inject!(maps_prefix)
59
- end
60
49
 
61
50
  @app = Rack::Builder.app do
62
51
  not_found = lambda { |env| [404, {}, []] }
63
52
  use Rack::Deflater
64
53
  use Rack::ShowExceptions
65
54
  use Index, server if server.use_index
66
- if source_map_enabled
67
- map(maps_prefix) do
68
- use Rack::ConditionalGet
69
- use Rack::ETag
70
- run maps_app
71
- end
72
- end
73
55
  map(prefix) { run sprockets }
74
56
  run Rack::Static.new(not_found, root: server.public_root, urls: server.public_urls)
75
57
  end
@@ -1,6 +1,6 @@
1
1
  module Opal
2
2
  module Sprockets
3
- BASE_VERSION = '0.4.2.pre.1'
3
+ BASE_VERSION = '0.4.2'
4
4
  OPAL_VERSION = '0.11.0'
5
5
  SPROCKETS_VERSION = '3.1'
6
6
  VERSION = "#{BASE_VERSION}.#{OPAL_VERSION}.#{SPROCKETS_VERSION}"
@@ -5,8 +5,6 @@ require 'rack/test'
5
5
  describe Opal::Sprockets::Server do
6
6
  include Rack::Test::Methods
7
7
 
8
- let(:maps_prefix) { described_class::SOURCE_MAPS_PREFIX_PATH }
9
-
10
8
  def app
11
9
  described_class.new { |s|
12
10
  s.main = 'opal'
@@ -42,67 +40,40 @@ describe Opal::Sprockets::Server do
42
40
  end
43
41
 
44
42
  describe 'source maps' do
45
- it 'serves map on a top level file' do
46
- get '/assets/source_map.js'
47
- expect(last_response).to be_ok
48
-
49
- get maps_prefix+'/source_map.self.map'
50
- expect(last_response).to be_ok
43
+ RSpec::Matchers.define :include_inline_source_map do
44
+ match do |actual_response|
45
+ actual_response.ok? &&
46
+ actual_response.body.lines.last.start_with?('//# sourceMappingURL=data:application/json;base64,')
47
+ end
51
48
  end
52
49
 
53
- it 'serves map on a subfolder file' do
54
- js_path = '/assets/source_map/subfolder/other_file.self.js'
55
- map_path = maps_prefix+'/source_map/subfolder/other_file.self.map'
56
-
57
- get js_path
58
-
59
- expect(last_response).to be_ok
60
- received_map_path = extract_map_path(last_response)
61
- expect(expand_path(received_map_path, js_path+'/..')).to eq(map_path)
62
-
63
- get maps_prefix+'/source_map/subfolder/other_file.self.map'
64
- expect(last_response).to be_ok
50
+ def extract_inline_map(response)
51
+ last_line = response.body.lines.last
52
+ b64_encoded = last_line.split('//# sourceMappingURL=data:application/json;base64,', 2)[1]
53
+ json_string = Base64.decode64(b64_encoded)
54
+ JSON.parse(json_string, symbolize_names: true)
65
55
  end
66
56
 
67
- it 'serves map on a subfolder file' do
68
- js_path = '/assets/source_map/subfolder/other_file.self.js'
69
- map_path = maps_prefix+'/source_map/subfolder/other_file.self.map'
70
-
71
- get js_path
57
+ it 'serves map for a top level file' do
58
+ get '/assets/opal_file.js'
59
+ expect(last_response).to include_inline_source_map
72
60
 
73
- expect(last_response).to be_ok
74
- received_map_path = extract_map_path(last_response)
75
- expect(expand_path(received_map_path, js_path+'/..')).to eq(map_path)
61
+ map = extract_inline_map(last_response)
76
62
 
77
- get maps_prefix+'/source_map/subfolder/other_file.self.map'
78
- expect(last_response).to be_ok
79
- map = ::SourceMap::Map.from_json(last_response.body)
80
-
81
- if Gem::Version.new(Opal::VERSION) >= Gem::Version.new('0.11.2')
82
- expect(map.sources).to include(maps_prefix+'/source_map/subfolder/other_file.rb')
83
- else
84
- expect(map.sources).to include(maps_prefix+'/source_map/subfolder/other_file')
85
- end
63
+ expect(map[:sources]).to eq(['opal_file.rb']).or eq(['opal_file'])
64
+ expect(map[:sourcesContent]).to eq(["require 'opal'\nputs 'hi from opal!'\n"])
86
65
  end
87
- end
88
66
 
89
- def extract_map_path(response)
90
- source_map_comment_regexp = %r{//# sourceMappingURL=(.*)$}
67
+ it 'serves map for a subfolder file' do
68
+ get '/assets/source_map/subfolder/other_file.self.js'
69
+ expect(last_response).to include_inline_source_map
91
70
 
92
- case
93
- when response.body =~ source_map_comment_regexp
94
- body.scan(source_map_comment_regexp).first.first
95
- when response.headers['X-SourceMap']
96
- response.headers['X-SourceMap']
97
- else
98
- raise "cannot find source map in response: #{response.inspect}"
99
- end
100
- end
71
+ map = extract_inline_map(last_response)
101
72
 
102
- def expand_path(file_name, dir_string)
103
- path = File.expand_path(file_name, dir_string)
104
- # Remove Windows letter and colon (eg. C:) from path
105
- path = path[2..-1] if !(RUBY_PLATFORM =~ /mswin|mingw/).nil?
106
- path
73
+ expect(map[:sources])
74
+ .to eq(['source_map/subfolder/other_file.rb'])
75
+ .or eq(['source_map/subfolder/other_file'])
76
+ expect(map[:sourcesContent]).to eq(["puts 'other!'\n"])
77
+ end
107
78
  end
108
79
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opal-sprockets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2.pre.1.0.11.0.3.1
4
+ version: 0.4.2.0.11.0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elia Schito
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-08-23 00:00:00.000000000 Z
12
+ date: 2018-09-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sprockets
@@ -123,6 +123,7 @@ files:
123
123
  - README.md
124
124
  - Rakefile
125
125
  - example/Gemfile
126
+ - example/Gemfile.lock
126
127
  - example/app/application.rb
127
128
  - example/app/user.rb
128
129
  - example/config.ru
@@ -134,8 +135,6 @@ files:
134
135
  - lib/opal/sprockets/path_reader.rb
135
136
  - lib/opal/sprockets/processor.rb
136
137
  - lib/opal/sprockets/server.rb
137
- - lib/opal/sprockets/source_map_header_patch.rb
138
- - lib/opal/sprockets/source_map_server.rb
139
138
  - lib/opal/sprockets/version.rb
140
139
  - opal-sprockets.gemspec
141
140
  - spec/fixtures/complex_sprockets.js.rb.erb
@@ -148,7 +147,6 @@ files:
148
147
  - spec/fixtures/required_tree_test/required_file1.rb
149
148
  - spec/fixtures/required_tree_test/required_file2.rb
150
149
  - spec/fixtures/requires.rb
151
- - spec/fixtures/source_map.rb
152
150
  - spec/fixtures/source_map/subfolder/other_file.rb
153
151
  - spec/fixtures/sprockets_file.js.rb
154
152
  - spec/fixtures/sprockets_require_tree_test.rb
@@ -175,9 +173,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
175
173
  version: '0'
176
174
  required_rubygems_version: !ruby/object:Gem::Requirement
177
175
  requirements:
178
- - - ">"
176
+ - - ">="
179
177
  - !ruby/object:Gem::Version
180
- version: 1.3.1
178
+ version: '0'
181
179
  requirements: []
182
180
  rubyforge_project:
183
181
  rubygems_version: 2.7.7
@@ -195,7 +193,6 @@ test_files:
195
193
  - spec/fixtures/required_tree_test/required_file1.rb
196
194
  - spec/fixtures/required_tree_test/required_file2.rb
197
195
  - spec/fixtures/requires.rb
198
- - spec/fixtures/source_map.rb
199
196
  - spec/fixtures/source_map/subfolder/other_file.rb
200
197
  - spec/fixtures/sprockets_file.js.rb
201
198
  - spec/fixtures/sprockets_require_tree_test.rb
@@ -1,41 +0,0 @@
1
- require 'sprockets/server'
2
-
3
- module Opal
4
- module Sprockets
5
- module SourceMapHeaderPatch
6
- # Adds the source map header to all sprocket responses for assets
7
- # with a .rb or .opal extension in the extension chain.
8
- def headers_with_opal_source_maps(env, asset, length)
9
- headers_without_opal_source_maps(env, asset, length).tap do |current_headers|
10
- if asset.pathname.to_s =~ /\.(rb|opal)\b/
11
- base_path = asset.logical_path.gsub('.js', '')
12
- current_headers['X-SourceMap'] = "#{::Opal::Sprockets::SourceMapHeaderPatch.prefix}/#{base_path}.map"
13
- end
14
- end
15
- end
16
-
17
- def self.included(base)
18
- # Poor man's alias_method_chain :)
19
- base.send(:alias_method, :headers_without_opal_source_maps, :headers)
20
- base.send(:alias_method, :headers, :headers_with_opal_source_maps)
21
- end
22
-
23
- def self.inject!(prefix)
24
- self.prefix = prefix
25
- unless ::Sprockets::Server.ancestors.include?(self)
26
- ::Sprockets::Server.send :include, self
27
- end
28
- end
29
-
30
- def self.prefix
31
- @prefix
32
- end
33
-
34
- def self.prefix= val
35
- @prefix = val
36
- end
37
- end
38
- end
39
- end
40
-
41
-
@@ -1,115 +0,0 @@
1
- module Opal
2
- class SourceMapServer
3
- # Carelessly taken from Sprockets::Caching (Sprockets v2)
4
- class Cache
5
- def initialize
6
- @cache = {}
7
- end
8
-
9
- attr_reader :cache
10
-
11
- def cache_get(key)
12
- # `Cache#get(key)` for Memcache
13
- if cache.respond_to?(:get)
14
- cache.get(key)
15
-
16
- # `Cache#[key]` so `Hash` can be used
17
- elsif cache.respond_to?(:[])
18
- cache[key]
19
-
20
- # `Cache#read(key)` for `ActiveSupport::Cache` support
21
- elsif cache.respond_to?(:read)
22
- cache.read(key)
23
-
24
- else
25
- nil
26
- end
27
- end
28
-
29
- def cache_set(key, value)
30
- # `Cache#set(key, value)` for Memcache
31
- if cache.respond_to?(:set)
32
- cache.set(key, value)
33
-
34
- # `Cache#[key]=value` so `Hash` can be used
35
- elsif cache.respond_to?(:[]=)
36
- cache[key] = value
37
-
38
- # `Cache#write(key, value)` for `ActiveSupport::Cache` support
39
- elsif cache.respond_to?(:write)
40
- cache.write(key, value)
41
- end
42
-
43
- value
44
- end
45
- end
46
-
47
- def self.get_map_cache(sprockets, logical_path)
48
- logical_path = logical_path.gsub(/\.js#{REGEXP_END}/, '')
49
- cache_key = cache_key_for_path(logical_path+'.map')
50
- cache(sprockets).cache_get(cache_key)
51
- end
52
-
53
- def self.set_map_cache(sprockets, logical_path, map_contents)
54
- logical_path = logical_path.gsub(/\.js#{REGEXP_END}/, '')
55
- cache_key = cache_key_for_path(logical_path+'.map')
56
- cache(sprockets).cache_set(cache_key, map_contents)
57
- end
58
-
59
- def self.cache(sprockets)
60
- @cache ||= sprockets.cache ? sprockets : Cache.new
61
- end
62
-
63
- def self.cache_key_for_path(logical_path)
64
- base_name = logical_path.gsub(/\.js#{REGEXP_END}/, '')
65
- File.join('opal', 'source_maps', base_name)
66
- end
67
-
68
-
69
- def initialize sprockets, prefix = '/'
70
- @sprockets = sprockets
71
- @prefix = prefix
72
- end
73
-
74
- attr_reader :sprockets, :prefix
75
-
76
- def inspect
77
- "#<#{self.class}:#{object_id}>"
78
- end
79
-
80
- def call(env)
81
- prefix_regex = %r{^(?:#{prefix}/|/)}
82
- path_info = env['PATH_INFO'].to_s.sub(prefix_regex, '')
83
-
84
- case path_info
85
- when %r{^(.*)\.self\.map$}
86
- path = $1
87
- asset = sprockets[path+'.js']
88
- return not_found(path) if asset.nil?
89
-
90
- # "logical_name" of a BundledAsset keeps the .js extension
91
- source = SourceMapServer.get_map_cache(sprockets, asset.logical_path)
92
- return not_found(asset) if source.nil?
93
-
94
- map = JSON.parse(source)
95
- map['sources'] = map['sources'].map {|s| "#{prefix}/#{s}"}
96
- source = map.to_json
97
-
98
- return [200, {"Content-Type" => "text/json"}, [source.to_s]]
99
- when %r{^(.*)\.rb$}
100
- begin
101
- asset = sprockets.resolve(path_info.sub(/\.rb#{REGEXP_END}/,''))
102
- rescue Sprockets::FileNotFound
103
- return not_found(path_info)
104
- end
105
- return [200, {"Content-Type" => "text/ruby"}, [Pathname(asset).read]]
106
- else
107
- not_found(path_info)
108
- end
109
- end
110
-
111
- def not_found(*messages)
112
- not_found = [404, {}, [{not_found: messages}.inspect]]
113
- end
114
- end
115
- end
@@ -1 +0,0 @@
1
- puts 'smap!'