sprockets 3.7.2 → 4.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +47 -267
  3. data/README.md +477 -321
  4. data/bin/sprockets +11 -7
  5. data/lib/rake/sprocketstask.rb +3 -2
  6. data/lib/sprockets.rb +99 -39
  7. data/lib/sprockets/add_source_map_comment_to_asset_processor.rb +60 -0
  8. data/lib/sprockets/asset.rb +31 -23
  9. data/lib/sprockets/autoload.rb +5 -0
  10. data/lib/sprockets/autoload/babel.rb +8 -0
  11. data/lib/sprockets/autoload/closure.rb +1 -0
  12. data/lib/sprockets/autoload/coffee_script.rb +1 -0
  13. data/lib/sprockets/autoload/eco.rb +1 -0
  14. data/lib/sprockets/autoload/ejs.rb +1 -0
  15. data/lib/sprockets/autoload/jsminc.rb +8 -0
  16. data/lib/sprockets/autoload/sass.rb +1 -0
  17. data/lib/sprockets/autoload/sassc.rb +8 -0
  18. data/lib/sprockets/autoload/uglifier.rb +1 -0
  19. data/lib/sprockets/autoload/yui.rb +1 -0
  20. data/lib/sprockets/autoload/zopfli.rb +7 -0
  21. data/lib/sprockets/babel_processor.rb +66 -0
  22. data/lib/sprockets/base.rb +49 -12
  23. data/lib/sprockets/bower.rb +5 -2
  24. data/lib/sprockets/bundle.rb +40 -4
  25. data/lib/sprockets/cache.rb +36 -1
  26. data/lib/sprockets/cache/file_store.rb +25 -3
  27. data/lib/sprockets/cache/memory_store.rb +9 -0
  28. data/lib/sprockets/cache/null_store.rb +8 -0
  29. data/lib/sprockets/cached_environment.rb +14 -19
  30. data/lib/sprockets/closure_compressor.rb +1 -0
  31. data/lib/sprockets/coffee_script_processor.rb +18 -4
  32. data/lib/sprockets/compressing.rb +43 -3
  33. data/lib/sprockets/configuration.rb +3 -7
  34. data/lib/sprockets/context.rb +97 -24
  35. data/lib/sprockets/dependencies.rb +1 -0
  36. data/lib/sprockets/digest_utils.rb +25 -5
  37. data/lib/sprockets/directive_processor.rb +45 -35
  38. data/lib/sprockets/eco_processor.rb +1 -0
  39. data/lib/sprockets/ejs_processor.rb +1 -0
  40. data/lib/sprockets/encoding_utils.rb +1 -0
  41. data/lib/sprockets/environment.rb +9 -4
  42. data/lib/sprockets/erb_processor.rb +28 -21
  43. data/lib/sprockets/errors.rb +1 -0
  44. data/lib/sprockets/exporters/base.rb +71 -0
  45. data/lib/sprockets/exporters/file_exporter.rb +24 -0
  46. data/lib/sprockets/exporters/zlib_exporter.rb +33 -0
  47. data/lib/sprockets/exporters/zopfli_exporter.rb +14 -0
  48. data/lib/sprockets/exporting.rb +73 -0
  49. data/lib/sprockets/file_reader.rb +1 -0
  50. data/lib/sprockets/http_utils.rb +25 -7
  51. data/lib/sprockets/jsminc_compressor.rb +32 -0
  52. data/lib/sprockets/jst_processor.rb +11 -10
  53. data/lib/sprockets/loader.rb +87 -67
  54. data/lib/sprockets/manifest.rb +64 -62
  55. data/lib/sprockets/manifest_utils.rb +9 -6
  56. data/lib/sprockets/mime.rb +8 -42
  57. data/lib/sprockets/npm.rb +52 -0
  58. data/lib/sprockets/path_dependency_utils.rb +3 -11
  59. data/lib/sprockets/path_digest_utils.rb +2 -1
  60. data/lib/sprockets/path_utils.rb +87 -7
  61. data/lib/sprockets/paths.rb +1 -0
  62. data/lib/sprockets/preprocessors/default_source_map.rb +49 -0
  63. data/lib/sprockets/processing.rb +31 -61
  64. data/lib/sprockets/processor_utils.rb +24 -35
  65. data/lib/sprockets/resolve.rb +177 -93
  66. data/lib/sprockets/sass_cache_store.rb +2 -6
  67. data/lib/sprockets/sass_compressor.rb +13 -1
  68. data/lib/sprockets/sass_functions.rb +1 -0
  69. data/lib/sprockets/sass_importer.rb +1 -0
  70. data/lib/sprockets/sass_processor.rb +30 -9
  71. data/lib/sprockets/sassc_compressor.rb +56 -0
  72. data/lib/sprockets/sassc_processor.rb +297 -0
  73. data/lib/sprockets/server.rb +26 -23
  74. data/lib/sprockets/source_map_processor.rb +66 -0
  75. data/lib/sprockets/source_map_utils.rb +483 -0
  76. data/lib/sprockets/transformers.rb +63 -35
  77. data/lib/sprockets/uglifier_compressor.rb +21 -11
  78. data/lib/sprockets/unloaded_asset.rb +13 -11
  79. data/lib/sprockets/uri_tar.rb +1 -0
  80. data/lib/sprockets/uri_utils.rb +11 -8
  81. data/lib/sprockets/utils.rb +41 -74
  82. data/lib/sprockets/utils/gzip.rb +46 -14
  83. data/lib/sprockets/version.rb +2 -1
  84. data/lib/sprockets/yui_compressor.rb +1 -0
  85. metadata +127 -23
  86. data/LICENSE +0 -21
  87. data/lib/sprockets/coffee_script_template.rb +0 -17
  88. data/lib/sprockets/deprecation.rb +0 -90
  89. data/lib/sprockets/eco_template.rb +0 -17
  90. data/lib/sprockets/ejs_template.rb +0 -17
  91. data/lib/sprockets/engines.rb +0 -92
  92. data/lib/sprockets/erb_template.rb +0 -11
  93. data/lib/sprockets/legacy.rb +0 -330
  94. data/lib/sprockets/legacy_proc_processor.rb +0 -35
  95. data/lib/sprockets/legacy_tilt_processor.rb +0 -29
  96. data/lib/sprockets/sass_template.rb +0 -19
@@ -1,11 +1,50 @@
1
+ # frozen_string_literal: true
1
2
  module Sprockets
2
3
  module Utils
3
4
  class Gzip
5
+ # Private: Generates a gzipped file based off of reference asset.
6
+ #
7
+ # ZlibArchiver.call(file, source, mtime)
8
+ #
9
+ # Compresses a given `source` using stdlib Zlib algorithm
10
+ # writes contents to the `file` passed in. Sets `mtime` of
11
+ # written file to passed in `mtime`
12
+ module ZlibArchiver
13
+ def self.call(file, source, mtime)
14
+ gz = Zlib::GzipWriter.new(file, Zlib::BEST_COMPRESSION)
15
+ gz.mtime = mtime
16
+ gz.write(source)
17
+ gz.close
18
+
19
+ File.utime(mtime, mtime, file.path)
20
+ end
21
+ end
22
+
23
+ # Private: Generates a gzipped file based off of reference asset.
24
+ #
25
+ # ZopfliArchiver.call(file, source, mtime)
26
+ #
27
+ # Compresses a given `source` using the zopfli gem
28
+ # writes contents to the `file` passed in. Sets `mtime` of
29
+ # written file to passed in `mtime`
30
+ module ZopfliArchiver
31
+ def self.call(file, source, mtime)
32
+ compressed_source = Autoload::Zopfli.deflate(source, format: :gzip, mtime: mtime)
33
+ file.write(compressed_source)
34
+ file.close
35
+
36
+ nil
37
+ end
38
+ end
39
+
40
+ attr_reader :content_type, :source, :charset, :archiver
41
+
4
42
  # Private: Generates a gzipped file based off of reference file.
5
- def initialize(asset)
43
+ def initialize(asset, archiver: ZlibArchiver)
6
44
  @content_type = asset.content_type
7
45
  @source = asset.source
8
46
  @charset = asset.charset
47
+ @archiver = archiver
9
48
  end
10
49
 
11
50
  # What non-text mime types should we compress? This list comes from:
@@ -26,7 +65,7 @@ module Sprockets
26
65
  # through a compression algorithm would make them larger.
27
66
  #
28
67
  # Return Boolean.
29
- def can_compress?(mime_types)
68
+ def can_compress?
30
69
  # The "charset" of a mime type is present if the value is
31
70
  # encoded text. We can check this value to see if the asset
32
71
  # can be compressed.
@@ -38,8 +77,8 @@ module Sprockets
38
77
  # Private: Opposite of `can_compress?`.
39
78
  #
40
79
  # Returns Boolean.
41
- def cannot_compress?(mime_types)
42
- !can_compress?(mime_types)
80
+ def cannot_compress?
81
+ !can_compress?
43
82
  end
44
83
 
45
84
  # Private: Generates a gzipped file based off of reference asset.
@@ -49,16 +88,9 @@ module Sprockets
49
88
  # Does not modify the target asset.
50
89
  #
51
90
  # Returns nothing.
52
- def compress(target)
53
- mtime = PathUtils.stat(target).mtime
54
- PathUtils.atomic_write("#{target}.gz") do |f|
55
- gz = Zlib::GzipWriter.new(f, Zlib::BEST_COMPRESSION)
56
- gz.mtime = mtime
57
- gz.write(@source)
58
- gz.close
59
-
60
- File.utime(mtime, mtime, f.path)
61
- end
91
+ def compress(file, target)
92
+ mtime = Sprockets::PathUtils.stat(target).mtime
93
+ archiver.call(file, source, mtime)
62
94
 
63
95
  nil
64
96
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Sprockets
2
- VERSION = "3.7.2"
3
+ VERSION = "4.0.2"
3
4
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'sprockets/autoload'
2
3
  require 'sprockets/digest_utils'
3
4
 
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.7.2
4
+ version: 4.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Stephenson
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-06-19 00:00:00.000000000 Z
12
+ date: 2020-06-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
@@ -45,6 +45,34 @@ dependencies:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '1.0'
48
+ - !ruby/object:Gem::Dependency
49
+ name: m
50
+ requirement: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: babel-transpiler
64
+ requirement: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.6'
69
+ type: :development
70
+ prerelease: false
71
+ version_requirements: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.6'
48
76
  - !ruby/object:Gem::Dependency
49
77
  name: closure-compiler
50
78
  requirement: !ruby/object:Gem::Requirement
@@ -129,6 +157,34 @@ dependencies:
129
157
  - - "~>"
130
158
  - !ruby/object:Gem::Version
131
159
  version: '2.0'
160
+ - !ruby/object:Gem::Dependency
161
+ name: jsminc
162
+ requirement: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '1.1'
167
+ type: :development
168
+ prerelease: false
169
+ version_requirements: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: '1.1'
174
+ - !ruby/object:Gem::Dependency
175
+ name: timecop
176
+ requirement: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: 0.9.1
181
+ type: :development
182
+ prerelease: false
183
+ version_requirements: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: 0.9.1
132
188
  - !ruby/object:Gem::Dependency
133
189
  name: minitest
134
190
  requirement: !ruby/object:Gem::Requirement
@@ -177,40 +233,54 @@ dependencies:
177
233
  requirements:
178
234
  - - "~>"
179
235
  - !ruby/object:Gem::Version
180
- version: '10.0'
236
+ version: '12.0'
181
237
  type: :development
182
238
  prerelease: false
183
239
  version_requirements: !ruby/object:Gem::Requirement
184
240
  requirements:
185
241
  - - "~>"
186
242
  - !ruby/object:Gem::Version
187
- version: '10.0'
243
+ version: '12.0'
188
244
  - !ruby/object:Gem::Dependency
189
245
  name: sass
190
246
  requirement: !ruby/object:Gem::Requirement
191
247
  requirements:
192
248
  - - "~>"
193
249
  - !ruby/object:Gem::Version
194
- version: '3.1'
250
+ version: '3.4'
195
251
  type: :development
196
252
  prerelease: false
197
253
  version_requirements: !ruby/object:Gem::Requirement
198
254
  requirements:
199
255
  - - "~>"
200
256
  - !ruby/object:Gem::Version
201
- version: '3.1'
257
+ version: '3.4'
202
258
  - !ruby/object:Gem::Dependency
203
- name: uglifier
259
+ name: sassc
204
260
  requirement: !ruby/object:Gem::Requirement
205
261
  requirements:
206
262
  - - "~>"
207
263
  - !ruby/object:Gem::Version
208
- version: '2.3'
264
+ version: '2.0'
209
265
  type: :development
210
266
  prerelease: false
211
267
  version_requirements: !ruby/object:Gem::Requirement
212
268
  requirements:
213
269
  - - "~>"
270
+ - !ruby/object:Gem::Version
271
+ version: '2.0'
272
+ - !ruby/object:Gem::Dependency
273
+ name: uglifier
274
+ requirement: !ruby/object:Gem::Requirement
275
+ requirements:
276
+ - - ">="
277
+ - !ruby/object:Gem::Version
278
+ version: '2.3'
279
+ type: :development
280
+ prerelease: false
281
+ version_requirements: !ruby/object:Gem::Requirement
282
+ requirements:
283
+ - - ">="
214
284
  - !ruby/object:Gem::Version
215
285
  version: '2.3'
216
286
  - !ruby/object:Gem::Dependency
@@ -227,8 +297,36 @@ dependencies:
227
297
  - - "~>"
228
298
  - !ruby/object:Gem::Version
229
299
  version: '0.12'
300
+ - !ruby/object:Gem::Dependency
301
+ name: zopfli
302
+ requirement: !ruby/object:Gem::Requirement
303
+ requirements:
304
+ - - "~>"
305
+ - !ruby/object:Gem::Version
306
+ version: 0.0.4
307
+ type: :development
308
+ prerelease: false
309
+ version_requirements: !ruby/object:Gem::Requirement
310
+ requirements:
311
+ - - "~>"
312
+ - !ruby/object:Gem::Version
313
+ version: 0.0.4
314
+ - !ruby/object:Gem::Dependency
315
+ name: rubocop-performance
316
+ requirement: !ruby/object:Gem::Requirement
317
+ requirements:
318
+ - - "~>"
319
+ - !ruby/object:Gem::Version
320
+ version: '1.3'
321
+ type: :development
322
+ prerelease: false
323
+ version_requirements: !ruby/object:Gem::Requirement
324
+ requirements:
325
+ - - "~>"
326
+ - !ruby/object:Gem::Version
327
+ version: '1.3'
230
328
  description: Sprockets is a Rack-based asset packaging system that concatenates and
231
- serves JavaScript, CoffeeScript, CSS, LESS, Sass, and SCSS.
329
+ serves JavaScript, CoffeeScript, CSS, Sass, and SCSS.
232
330
  email:
233
331
  - sstephenson@gmail.com
234
332
  - josh@joshpeek.com
@@ -238,20 +336,25 @@ extensions: []
238
336
  extra_rdoc_files: []
239
337
  files:
240
338
  - CHANGELOG.md
241
- - LICENSE
242
339
  - README.md
243
340
  - bin/sprockets
244
341
  - lib/rake/sprocketstask.rb
245
342
  - lib/sprockets.rb
343
+ - lib/sprockets/add_source_map_comment_to_asset_processor.rb
246
344
  - lib/sprockets/asset.rb
247
345
  - lib/sprockets/autoload.rb
346
+ - lib/sprockets/autoload/babel.rb
248
347
  - lib/sprockets/autoload/closure.rb
249
348
  - lib/sprockets/autoload/coffee_script.rb
250
349
  - lib/sprockets/autoload/eco.rb
251
350
  - lib/sprockets/autoload/ejs.rb
351
+ - lib/sprockets/autoload/jsminc.rb
252
352
  - lib/sprockets/autoload/sass.rb
353
+ - lib/sprockets/autoload/sassc.rb
253
354
  - lib/sprockets/autoload/uglifier.rb
254
355
  - lib/sprockets/autoload/yui.rb
356
+ - lib/sprockets/autoload/zopfli.rb
357
+ - lib/sprockets/babel_processor.rb
255
358
  - lib/sprockets/base.rb
256
359
  - lib/sprockets/bower.rb
257
360
  - lib/sprockets/bundle.rb
@@ -262,38 +365,37 @@ files:
262
365
  - lib/sprockets/cached_environment.rb
263
366
  - lib/sprockets/closure_compressor.rb
264
367
  - lib/sprockets/coffee_script_processor.rb
265
- - lib/sprockets/coffee_script_template.rb
266
368
  - lib/sprockets/compressing.rb
267
369
  - lib/sprockets/configuration.rb
268
370
  - lib/sprockets/context.rb
269
371
  - lib/sprockets/dependencies.rb
270
- - lib/sprockets/deprecation.rb
271
372
  - lib/sprockets/digest_utils.rb
272
373
  - lib/sprockets/directive_processor.rb
273
374
  - lib/sprockets/eco_processor.rb
274
- - lib/sprockets/eco_template.rb
275
375
  - lib/sprockets/ejs_processor.rb
276
- - lib/sprockets/ejs_template.rb
277
376
  - lib/sprockets/encoding_utils.rb
278
- - lib/sprockets/engines.rb
279
377
  - lib/sprockets/environment.rb
280
378
  - lib/sprockets/erb_processor.rb
281
- - lib/sprockets/erb_template.rb
282
379
  - lib/sprockets/errors.rb
380
+ - lib/sprockets/exporters/base.rb
381
+ - lib/sprockets/exporters/file_exporter.rb
382
+ - lib/sprockets/exporters/zlib_exporter.rb
383
+ - lib/sprockets/exporters/zopfli_exporter.rb
384
+ - lib/sprockets/exporting.rb
283
385
  - lib/sprockets/file_reader.rb
284
386
  - lib/sprockets/http_utils.rb
387
+ - lib/sprockets/jsminc_compressor.rb
285
388
  - lib/sprockets/jst_processor.rb
286
- - lib/sprockets/legacy.rb
287
- - lib/sprockets/legacy_proc_processor.rb
288
- - lib/sprockets/legacy_tilt_processor.rb
289
389
  - lib/sprockets/loader.rb
290
390
  - lib/sprockets/manifest.rb
291
391
  - lib/sprockets/manifest_utils.rb
292
392
  - lib/sprockets/mime.rb
393
+ - lib/sprockets/npm.rb
293
394
  - lib/sprockets/path_dependency_utils.rb
294
395
  - lib/sprockets/path_digest_utils.rb
295
396
  - lib/sprockets/path_utils.rb
296
397
  - lib/sprockets/paths.rb
398
+ - lib/sprockets/preprocessors/default_source_map.rb
297
399
  - lib/sprockets/processing.rb
298
400
  - lib/sprockets/processor_utils.rb
299
401
  - lib/sprockets/resolve.rb
@@ -302,8 +404,11 @@ files:
302
404
  - lib/sprockets/sass_functions.rb
303
405
  - lib/sprockets/sass_importer.rb
304
406
  - lib/sprockets/sass_processor.rb
305
- - lib/sprockets/sass_template.rb
407
+ - lib/sprockets/sassc_compressor.rb
408
+ - lib/sprockets/sassc_processor.rb
306
409
  - lib/sprockets/server.rb
410
+ - lib/sprockets/source_map_processor.rb
411
+ - lib/sprockets/source_map_utils.rb
307
412
  - lib/sprockets/transformers.rb
308
413
  - lib/sprockets/uglifier_compressor.rb
309
414
  - lib/sprockets/unloaded_asset.rb
@@ -325,15 +430,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
325
430
  requirements:
326
431
  - - ">="
327
432
  - !ruby/object:Gem::Version
328
- version: 1.9.3
433
+ version: 2.5.0
329
434
  required_rubygems_version: !ruby/object:Gem::Requirement
330
435
  requirements:
331
436
  - - ">="
332
437
  - !ruby/object:Gem::Version
333
438
  version: '0'
334
439
  requirements: []
335
- rubyforge_project: sprockets
336
- rubygems_version: 2.7.6
440
+ rubygems_version: 3.1.2
337
441
  signing_key:
338
442
  specification_version: 4
339
443
  summary: Rack-based asset packaging system
data/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- Copyright (c) 2014 Sam Stephenson
2
- Copyright (c) 2014 Joshua Peek
3
-
4
- Permission is hereby granted, free of charge, to any person obtaining
5
- a copy of this software and associated documentation files (the
6
- "Software"), to deal in the Software without restriction, including
7
- without limitation the rights to use, copy, modify, merge, publish,
8
- distribute, sublicense, and/or sell copies of the Software, and to
9
- permit persons to whom the Software is furnished to do so, subject to
10
- the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be
13
- included in all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,17 +0,0 @@
1
- require 'sprockets/coffee_script_processor'
2
-
3
- module Sprockets
4
- # Deprecated
5
- module CoffeeScriptTemplate
6
- VERSION = CoffeeScriptProcessor::VERSION
7
-
8
- def self.cache_key
9
- CoffeeScriptProcessor.cache_key
10
- end
11
-
12
- def self.call(*args)
13
- Deprecation.new.warn "CoffeeScriptTemplate is deprecated please use CoffeeScriptProcessor instead"
14
- CoffeeScriptProcessor.call(*args)
15
- end
16
- end
17
- end
@@ -1,90 +0,0 @@
1
- module Sprockets
2
- class Deprecation
3
- THREAD_LOCAL__SILENCE_KEY = "_sprockets_deprecation_silence".freeze
4
- DEFAULT_BEHAVIORS = {
5
- raise: ->(message, callstack) {
6
- e = DeprecationException.new(message)
7
- e.set_backtrace(callstack.map(&:to_s))
8
- raise e
9
- },
10
-
11
- stderr: ->(message, callstack) {
12
- $stderr.puts(message)
13
- },
14
- }
15
-
16
- attr_reader :callstack
17
-
18
- def self.silence(&block)
19
- Thread.current[THREAD_LOCAL__SILENCE_KEY] = true
20
- block.call
21
- ensure
22
- Thread.current[THREAD_LOCAL__SILENCE_KEY] = false
23
- end
24
-
25
- def initialize(callstack = nil)
26
- @callstack = callstack || caller(2)
27
- end
28
-
29
- def warn(message)
30
- return if Thread.current[THREAD_LOCAL__SILENCE_KEY]
31
- deprecation_message(message).tap do |m|
32
- behavior.each { |b| b.call(m, callstack) }
33
- end
34
- end
35
-
36
- private
37
- def behavior
38
- @behavior ||= [DEFAULT_BEHAVIORS[:stderr]]
39
- end
40
-
41
- def behavior=(behavior)
42
- @behavior = Array(behavior).map { |b| DEFAULT_BEHAVIORS[b] || b }
43
- end
44
-
45
- def deprecation_message(message = nil)
46
- message ||= "You are using deprecated behavior which will be removed from the next major or minor release."
47
- "DEPRECATION WARNING: #{message} #{ deprecation_caller_message }"
48
- end
49
-
50
- def deprecation_caller_message
51
- file, line, method = extract_callstack
52
- if file
53
- if line && method
54
- "(called from #{method} at #{file}:#{line})"
55
- else
56
- "(called from #{file}:#{line})"
57
- end
58
- end
59
- end
60
-
61
- SPROCKETS_GEM_ROOT = File.expand_path("../../../../..", __FILE__) + "/"
62
-
63
- def ignored_callstack(path)
64
- path.start_with?(SPROCKETS_GEM_ROOT) || path.start_with?(RbConfig::CONFIG['rubylibdir'])
65
- end
66
-
67
- def extract_callstack
68
- return _extract_callstack if callstack.first.is_a? String
69
-
70
- offending_line = callstack.find { |frame|
71
- frame.absolute_path && !ignored_callstack(frame.absolute_path)
72
- } || callstack.first
73
-
74
- [offending_line.path, offending_line.lineno, offending_line.label]
75
- end
76
-
77
- def _extract_callstack
78
- offending_line = callstack.find { |line| !ignored_callstack(line) } || callstack.first
79
-
80
- if offending_line
81
- if md = offending_line.match(/^(.+?):(\d+)(?::in `(.*?)')?/)
82
- md.captures
83
- else
84
- offending_line
85
- end
86
- end
87
- end
88
- end
89
- private_constant :Deprecation
90
- end