sprockets 3.0.0 → 3.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +296 -0
  3. data/README.md +49 -183
  4. data/bin/sprockets +1 -0
  5. data/lib/sprockets/asset.rb +3 -2
  6. data/lib/sprockets/base.rb +13 -2
  7. data/lib/sprockets/bundle.rb +5 -1
  8. data/lib/sprockets/cache/file_store.rb +7 -4
  9. data/lib/sprockets/cache.rb +6 -4
  10. data/lib/sprockets/closure_compressor.rb +5 -11
  11. data/lib/sprockets/coffee_script_processor.rb +2 -2
  12. data/lib/sprockets/coffee_script_template.rb +12 -1
  13. data/lib/sprockets/compressing.rb +20 -0
  14. data/lib/sprockets/context.rb +3 -1
  15. data/lib/sprockets/dependencies.rb +8 -8
  16. data/lib/sprockets/deprecation.rb +90 -0
  17. data/lib/sprockets/digest_utils.rb +81 -57
  18. data/lib/sprockets/eco_processor.rb +2 -2
  19. data/lib/sprockets/eco_template.rb +12 -1
  20. data/lib/sprockets/ejs_processor.rb +2 -2
  21. data/lib/sprockets/ejs_template.rb +12 -1
  22. data/lib/sprockets/encoding_utils.rb +7 -4
  23. data/lib/sprockets/engines.rb +11 -0
  24. data/lib/sprockets/erb_template.rb +6 -1
  25. data/lib/sprockets/errors.rb +0 -1
  26. data/lib/sprockets/http_utils.rb +3 -1
  27. data/lib/sprockets/legacy.rb +16 -0
  28. data/lib/sprockets/legacy_proc_processor.rb +1 -1
  29. data/lib/sprockets/legacy_tilt_processor.rb +2 -2
  30. data/lib/sprockets/loader.rb +208 -59
  31. data/lib/sprockets/manifest.rb +57 -6
  32. data/lib/sprockets/path_utils.rb +20 -15
  33. data/lib/sprockets/processing.rb +10 -0
  34. data/lib/sprockets/processor_utils.rb +77 -0
  35. data/lib/sprockets/resolve.rb +9 -6
  36. data/lib/sprockets/sass_cache_store.rb +6 -1
  37. data/lib/sprockets/sass_compressor.rb +9 -17
  38. data/lib/sprockets/sass_processor.rb +16 -9
  39. data/lib/sprockets/sass_template.rb +14 -2
  40. data/lib/sprockets/server.rb +32 -12
  41. data/lib/sprockets/uglifier_compressor.rb +6 -13
  42. data/lib/sprockets/unloaded_asset.rb +137 -0
  43. data/lib/sprockets/uri_tar.rb +98 -0
  44. data/lib/sprockets/uri_utils.rb +5 -7
  45. data/lib/sprockets/utils/gzip.rb +67 -0
  46. data/lib/sprockets/utils.rb +35 -18
  47. data/lib/sprockets/version.rb +1 -1
  48. data/lib/sprockets/yui_compressor.rb +4 -14
  49. data/lib/sprockets.rb +21 -11
  50. metadata +28 -3
@@ -14,11 +14,15 @@ module Sprockets
14
14
  #
15
15
  # Returns false if .dup would raise a TypeError, otherwise true.
16
16
  def duplicable?(obj)
17
- case obj
18
- when NilClass, FalseClass, TrueClass, Symbol, Numeric
19
- false
20
- else
17
+ if RUBY_VERSION >= "2.4.0"
21
18
  true
19
+ else
20
+ case obj
21
+ when NilClass, FalseClass, TrueClass, Symbol, Numeric
22
+ false
23
+ else
24
+ true
25
+ end
22
26
  end
23
27
  end
24
28
 
@@ -74,32 +78,45 @@ module Sprockets
74
78
  def string_end_with_semicolon?(str)
75
79
  i = str.size - 1
76
80
  while i >= 0
77
- c = str[i]
81
+ c = str[i].ord
78
82
  i -= 1
79
- if c == "\n" || c == " " || c == "\t"
80
- next
81
- elsif c != ";"
82
- return false
83
- else
84
- return true
83
+
84
+ # Need to compare against the ordinals because the string can be UTF_8 or UTF_32LE encoded
85
+ # 0x0A == "\n"
86
+ # 0x20 == " "
87
+ # 0x09 == "\t"
88
+ # 0x3B == ";"
89
+ unless c == 0x0A || c == 0x20 || c == 0x09
90
+ return c === 0x3B
85
91
  end
86
92
  end
93
+
87
94
  true
88
95
  end
89
96
 
90
97
  # Internal: Accumulate asset source to buffer and append a trailing
91
98
  # semicolon if necessary.
92
99
  #
93
- # buf - String memo
94
- # asset - Asset
100
+ # buf - String buffer to append to
101
+ # source - String source to append
95
102
  #
96
- # Returns appended buffer String.
103
+ # Returns buf String.
97
104
  def concat_javascript_sources(buf, source)
98
- if string_end_with_semicolon?(buf)
99
- buf + source
100
- else
101
- buf + ";\n" + source
105
+ if source.bytesize > 0
106
+ buf << source
107
+
108
+ # If the source contains non-ASCII characters, indexing on it becomes O(N).
109
+ # This will lead to O(N^2) performance in string_end_with_semicolon?, so we should use 32 bit encoding to make sure indexing stays O(1)
110
+ source = source.encode(Encoding::UTF_32LE) unless source.ascii_only?
111
+
112
+ if !string_end_with_semicolon?(source)
113
+ buf << ";\n"
114
+ elsif source[source.size - 1].ord != 0x0A
115
+ buf << "\n"
116
+ end
102
117
  end
118
+
119
+ buf
103
120
  end
104
121
 
105
122
  # Internal: Prepends a leading "." to an extension if its missing.
@@ -1,3 +1,3 @@
1
1
  module Sprockets
2
- VERSION = "3.0.0"
2
+ VERSION = "3.7.2"
3
3
  end
@@ -1,4 +1,5 @@
1
1
  require 'sprockets/autoload'
2
+ require 'sprockets/digest_utils'
2
3
 
3
4
  module Sprockets
4
5
  # Public: YUI compressor.
@@ -35,12 +36,7 @@ module Sprockets
35
36
 
36
37
  def initialize(options = {})
37
38
  @options = options
38
- @cache_key = [
39
- self.class.name,
40
- Autoload::YUI::Compressor::VERSION,
41
- VERSION,
42
- options
43
- ].freeze
39
+ @cache_key = "#{self.class.name}:#{Autoload::YUI::Compressor::VERSION}:#{VERSION}:#{DigestUtils.digest(options)}".freeze
44
40
  end
45
41
 
46
42
  def call(input)
@@ -48,15 +44,9 @@ module Sprockets
48
44
 
49
45
  case input[:content_type]
50
46
  when 'application/javascript'
51
- key = @cache_key + [input[:content_type], input[:data]]
52
- input[:cache].fetch(key) do
53
- Autoload::YUI::JavaScriptCompressor.new(@options).compress(data)
54
- end
47
+ Autoload::YUI::JavaScriptCompressor.new(@options).compress(data)
55
48
  when 'text/css'
56
- key = @cache_key + [input[:content_type], input[:data]]
57
- input[:cache].fetch(key) do
58
- Autoload::YUI::CssCompressor.new(@options).compress(data)
59
- end
49
+ Autoload::YUI::CssCompressor.new(@options).compress(data)
60
50
  else
61
51
  data
62
52
  end
data/lib/sprockets.rb CHANGED
@@ -1,8 +1,10 @@
1
+ # encoding: utf-8
1
2
  require 'sprockets/version'
2
3
  require 'sprockets/cache'
3
4
  require 'sprockets/environment'
4
5
  require 'sprockets/errors'
5
6
  require 'sprockets/manifest'
7
+ require 'sprockets/deprecation'
6
8
 
7
9
  module Sprockets
8
10
  require 'sprockets/processor_utils'
@@ -32,7 +34,8 @@ module Sprockets
32
34
  registered_transformers: Hash.new { |h, k| {}.freeze }.freeze,
33
35
  root: File.expand_path('..', __FILE__).freeze,
34
36
  transformers: Hash.new { |h, k| {}.freeze }.freeze,
35
- version: ""
37
+ version: "",
38
+ gzip_enabled: true
36
39
  }.freeze
37
40
  self.computed_config = {}
38
41
 
@@ -74,6 +77,7 @@ module Sprockets
74
77
 
75
78
  # Common font types
76
79
  register_mime_type 'application/vnd.ms-fontobject', extensions: ['.eot']
80
+ register_mime_type 'application/x-font-opentype', extensions: ['.otf']
77
81
  register_mime_type 'application/x-font-ttf', extensions: ['.ttf']
78
82
  register_mime_type 'application/font-woff', extensions: ['.woff']
79
83
 
@@ -101,8 +105,8 @@ module Sprockets
101
105
  register_bundle_processor 'application/javascript', Bundle
102
106
  register_bundle_processor 'text/css', Bundle
103
107
 
104
- register_bundle_metadata_reducer '*/*', :data, :+
105
- register_bundle_metadata_reducer 'application/javascript', :data, Utils.method(:concat_javascript_sources)
108
+ register_bundle_metadata_reducer '*/*', :data, proc { "" }, :concat
109
+ register_bundle_metadata_reducer 'application/javascript', :data, proc { "" }, Utils.method(:concat_javascript_sources)
106
110
  register_bundle_metadata_reducer '*/*', :links, :+
107
111
 
108
112
  require 'sprockets/closure_compressor'
@@ -119,31 +123,37 @@ module Sprockets
119
123
 
120
124
  # Mmm, CoffeeScript
121
125
  require 'sprockets/coffee_script_processor'
122
- register_engine '.coffee', CoffeeScriptProcessor, mime_type: 'application/javascript'
126
+ Deprecation.silence do
127
+ register_engine '.coffee', CoffeeScriptProcessor, mime_type: 'application/javascript', silence_deprecation: true
128
+ end
123
129
 
124
130
  # JST engines
125
131
  require 'sprockets/eco_processor'
126
132
  require 'sprockets/ejs_processor'
127
133
  require 'sprockets/jst_processor'
128
- register_engine '.jst', JstProcessor, mime_type: 'application/javascript'
129
- register_engine '.eco', EcoProcessor, mime_type: 'application/javascript'
130
- register_engine '.ejs', EjsProcessor, mime_type: 'application/javascript'
134
+ Deprecation.silence do
135
+ register_engine '.jst', JstProcessor, mime_type: 'application/javascript', silence_deprecation: true
136
+ register_engine '.eco', EcoProcessor, mime_type: 'application/javascript', silence_deprecation: true
137
+ register_engine '.ejs', EjsProcessor, mime_type: 'application/javascript', silence_deprecation: true
138
+ end
131
139
 
132
140
  # CSS engines
133
141
  require 'sprockets/sass_processor'
134
- register_engine '.sass', SassProcessor, mime_type: 'text/css'
135
- register_engine '.scss', ScssProcessor, mime_type: 'text/css'
142
+ Deprecation.silence do
143
+ register_engine '.sass', SassProcessor, mime_type: 'text/css', silence_deprecation: true
144
+ register_engine '.scss', ScssProcessor, mime_type: 'text/css', silence_deprecation: true
145
+ end
136
146
  register_bundle_metadata_reducer 'text/css', :sass_dependencies, Set.new, :+
137
147
 
138
148
  # Other
139
149
  require 'sprockets/erb_processor'
140
- register_engine '.erb', ERBProcessor, mime_type: 'text/plain'
150
+ register_engine '.erb', ERBProcessor, mime_type: 'text/plain', silence_deprecation: true
141
151
 
142
152
  register_dependency_resolver 'environment-version' do |env|
143
153
  env.version
144
154
  end
145
155
  register_dependency_resolver 'environment-paths' do |env|
146
- env.paths
156
+ env.paths.map {|path| env.compress_from_root(path) }
147
157
  end
148
158
  register_dependency_resolver 'file-digest' do |env, str|
149
159
  env.file_digest(env.parse_file_digest_uri(str))
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sprockets
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Stephenson
@@ -9,10 +9,30 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-04-12 00:00:00.000000000 Z
12
+ date: 2018-06-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">"
19
+ - !ruby/object:Gem::Version
20
+ version: '1'
21
+ - - "<"
22
+ - !ruby/object:Gem::Version
23
+ version: '3'
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ requirements:
28
+ - - ">"
29
+ - !ruby/object:Gem::Version
30
+ version: '1'
31
+ - - "<"
32
+ - !ruby/object:Gem::Version
33
+ version: '3'
34
+ - !ruby/object:Gem::Dependency
35
+ name: concurrent-ruby
16
36
  requirement: !ruby/object:Gem::Requirement
17
37
  requirements:
18
38
  - - "~>"
@@ -217,6 +237,7 @@ executables:
217
237
  extensions: []
218
238
  extra_rdoc_files: []
219
239
  files:
240
+ - CHANGELOG.md
220
241
  - LICENSE
221
242
  - README.md
222
243
  - bin/sprockets
@@ -246,6 +267,7 @@ files:
246
267
  - lib/sprockets/configuration.rb
247
268
  - lib/sprockets/context.rb
248
269
  - lib/sprockets/dependencies.rb
270
+ - lib/sprockets/deprecation.rb
249
271
  - lib/sprockets/digest_utils.rb
250
272
  - lib/sprockets/directive_processor.rb
251
273
  - lib/sprockets/eco_processor.rb
@@ -284,8 +306,11 @@ files:
284
306
  - lib/sprockets/server.rb
285
307
  - lib/sprockets/transformers.rb
286
308
  - lib/sprockets/uglifier_compressor.rb
309
+ - lib/sprockets/unloaded_asset.rb
310
+ - lib/sprockets/uri_tar.rb
287
311
  - lib/sprockets/uri_utils.rb
288
312
  - lib/sprockets/utils.rb
313
+ - lib/sprockets/utils/gzip.rb
289
314
  - lib/sprockets/version.rb
290
315
  - lib/sprockets/yui_compressor.rb
291
316
  homepage: https://github.com/rails/sprockets
@@ -308,7 +333,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
308
333
  version: '0'
309
334
  requirements: []
310
335
  rubyforge_project: sprockets
311
- rubygems_version: 2.4.5
336
+ rubygems_version: 2.7.6
312
337
  signing_key:
313
338
  specification_version: 4
314
339
  summary: Rack-based asset packaging system