sprockets 2.11.3 → 3.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +296 -0
  3. data/LICENSE +2 -2
  4. data/README.md +235 -242
  5. data/bin/sprockets +1 -0
  6. data/lib/rake/sprocketstask.rb +5 -4
  7. data/lib/sprockets/asset.rb +143 -210
  8. data/lib/sprockets/autoload/closure.rb +7 -0
  9. data/lib/sprockets/autoload/coffee_script.rb +7 -0
  10. data/lib/sprockets/autoload/eco.rb +7 -0
  11. data/lib/sprockets/autoload/ejs.rb +7 -0
  12. data/lib/sprockets/autoload/sass.rb +7 -0
  13. data/lib/sprockets/autoload/uglifier.rb +7 -0
  14. data/lib/sprockets/autoload/yui.rb +7 -0
  15. data/lib/sprockets/autoload.rb +11 -0
  16. data/lib/sprockets/base.rb +56 -393
  17. data/lib/sprockets/bower.rb +58 -0
  18. data/lib/sprockets/bundle.rb +69 -0
  19. data/lib/sprockets/cache/file_store.rb +168 -14
  20. data/lib/sprockets/cache/memory_store.rb +66 -0
  21. data/lib/sprockets/cache/null_store.rb +46 -0
  22. data/lib/sprockets/cache.rb +236 -0
  23. data/lib/sprockets/cached_environment.rb +69 -0
  24. data/lib/sprockets/closure_compressor.rb +35 -10
  25. data/lib/sprockets/coffee_script_processor.rb +25 -0
  26. data/lib/sprockets/coffee_script_template.rb +17 -0
  27. data/lib/sprockets/compressing.rb +44 -23
  28. data/lib/sprockets/configuration.rb +83 -0
  29. data/lib/sprockets/context.rb +86 -144
  30. data/lib/sprockets/dependencies.rb +73 -0
  31. data/lib/sprockets/deprecation.rb +90 -0
  32. data/lib/sprockets/digest_utils.rb +180 -0
  33. data/lib/sprockets/directive_processor.rb +207 -211
  34. data/lib/sprockets/eco_processor.rb +32 -0
  35. data/lib/sprockets/eco_template.rb +9 -30
  36. data/lib/sprockets/ejs_processor.rb +31 -0
  37. data/lib/sprockets/ejs_template.rb +9 -29
  38. data/lib/sprockets/encoding_utils.rb +261 -0
  39. data/lib/sprockets/engines.rb +53 -35
  40. data/lib/sprockets/environment.rb +17 -64
  41. data/lib/sprockets/erb_processor.rb +30 -0
  42. data/lib/sprockets/erb_template.rb +11 -0
  43. data/lib/sprockets/errors.rb +4 -13
  44. data/lib/sprockets/file_reader.rb +15 -0
  45. data/lib/sprockets/http_utils.rb +117 -0
  46. data/lib/sprockets/jst_processor.rb +35 -15
  47. data/lib/sprockets/legacy.rb +330 -0
  48. data/lib/sprockets/legacy_proc_processor.rb +35 -0
  49. data/lib/sprockets/legacy_tilt_processor.rb +29 -0
  50. data/lib/sprockets/loader.rb +325 -0
  51. data/lib/sprockets/manifest.rb +202 -127
  52. data/lib/sprockets/manifest_utils.rb +45 -0
  53. data/lib/sprockets/mime.rb +112 -31
  54. data/lib/sprockets/path_dependency_utils.rb +85 -0
  55. data/lib/sprockets/path_digest_utils.rb +47 -0
  56. data/lib/sprockets/path_utils.rb +287 -0
  57. data/lib/sprockets/paths.rb +42 -19
  58. data/lib/sprockets/processing.rb +178 -126
  59. data/lib/sprockets/processor_utils.rb +180 -0
  60. data/lib/sprockets/resolve.rb +211 -0
  61. data/lib/sprockets/sass_cache_store.rb +22 -17
  62. data/lib/sprockets/sass_compressor.rb +39 -15
  63. data/lib/sprockets/sass_functions.rb +2 -70
  64. data/lib/sprockets/sass_importer.rb +2 -29
  65. data/lib/sprockets/sass_processor.rb +292 -0
  66. data/lib/sprockets/sass_template.rb +12 -53
  67. data/lib/sprockets/server.rb +129 -84
  68. data/lib/sprockets/transformers.rb +145 -0
  69. data/lib/sprockets/uglifier_compressor.rb +39 -12
  70. data/lib/sprockets/unloaded_asset.rb +137 -0
  71. data/lib/sprockets/uri_tar.rb +98 -0
  72. data/lib/sprockets/uri_utils.rb +188 -0
  73. data/lib/sprockets/utils/gzip.rb +67 -0
  74. data/lib/sprockets/utils.rb +210 -44
  75. data/lib/sprockets/version.rb +1 -1
  76. data/lib/sprockets/yui_compressor.rb +39 -11
  77. data/lib/sprockets.rb +142 -81
  78. metadata +100 -80
  79. data/lib/sprockets/asset_attributes.rb +0 -137
  80. data/lib/sprockets/bundled_asset.rb +0 -78
  81. data/lib/sprockets/caching.rb +0 -96
  82. data/lib/sprockets/charset_normalizer.rb +0 -41
  83. data/lib/sprockets/index.rb +0 -100
  84. data/lib/sprockets/processed_asset.rb +0 -152
  85. data/lib/sprockets/processor.rb +0 -32
  86. data/lib/sprockets/safety_colons.rb +0 -28
  87. data/lib/sprockets/scss_template.rb +0 -13
  88. data/lib/sprockets/static_asset.rb +0 -58
@@ -0,0 +1,90 @@
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
@@ -0,0 +1,180 @@
1
+ require 'digest/md5'
2
+ require 'digest/sha1'
3
+ require 'digest/sha2'
4
+ require 'set'
5
+
6
+ module Sprockets
7
+ # Internal: Hash functions and digest related utilities. Mixed into
8
+ # Environment.
9
+ module DigestUtils
10
+ extend self
11
+
12
+ # Internal: Default digest class.
13
+ #
14
+ # Returns a Digest::Base subclass.
15
+ def digest_class
16
+ Digest::SHA256
17
+ end
18
+
19
+ # Internal: Maps digest bytesize to the digest class.
20
+ DIGEST_SIZES = {
21
+ 16 => Digest::MD5,
22
+ 20 => Digest::SHA1,
23
+ 32 => Digest::SHA256,
24
+ 48 => Digest::SHA384,
25
+ 64 => Digest::SHA512
26
+ }
27
+
28
+ # Internal: Detect digest class hash algorithm for digest bytes.
29
+ #
30
+ # While not elegant, all the supported digests have a unique bytesize.
31
+ #
32
+ # Returns Digest::Base or nil.
33
+ def detect_digest_class(bytes)
34
+ DIGEST_SIZES[bytes.bytesize]
35
+ end
36
+
37
+ ADD_VALUE_TO_DIGEST = {
38
+ String => ->(val, digest) { digest << val },
39
+ FalseClass => ->(val, digest) { digest << 'FalseClass'.freeze },
40
+ TrueClass => ->(val, digest) { digest << 'TrueClass'.freeze },
41
+ NilClass => ->(val, digest) { digest << 'NilClass'.freeze },
42
+
43
+ Symbol => ->(val, digest) {
44
+ digest << 'Symbol'.freeze
45
+ digest << val.to_s
46
+ },
47
+ Integer => ->(val, digest) {
48
+ digest << 'Integer'.freeze
49
+ digest << val.to_s
50
+ },
51
+ Array => ->(val, digest) {
52
+ digest << 'Array'.freeze
53
+ val.each do |element|
54
+ ADD_VALUE_TO_DIGEST[element.class].call(element, digest)
55
+ end
56
+ },
57
+ Hash => ->(val, digest) {
58
+ digest << 'Hash'.freeze
59
+ val.sort.each do |array|
60
+ ADD_VALUE_TO_DIGEST[Array].call(array, digest)
61
+ end
62
+ },
63
+ Set => ->(val, digest) {
64
+ digest << 'Set'.freeze
65
+ ADD_VALUE_TO_DIGEST[Array].call(val.to_a, digest)
66
+ },
67
+ Encoding => ->(val, digest) {
68
+ digest << 'Encoding'.freeze
69
+ digest << val.name
70
+ },
71
+ }
72
+ if 0.class != Integer # Ruby < 2.4
73
+ ADD_VALUE_TO_DIGEST[Fixnum] = ->(val, digest) {
74
+ digest << 'Integer'.freeze
75
+ digest << val.to_s
76
+ }
77
+ ADD_VALUE_TO_DIGEST[Bignum] = ->(val, digest) {
78
+ digest << 'Integer'.freeze
79
+ digest << val.to_s
80
+ }
81
+ end
82
+ ADD_VALUE_TO_DIGEST.default_proc = ->(_, val) {
83
+ raise TypeError, "couldn't digest #{ val }"
84
+ }
85
+ private_constant :ADD_VALUE_TO_DIGEST
86
+
87
+ # Internal: Generate a hexdigest for a nested JSON serializable object.
88
+ #
89
+ # This is used for generating cache keys, so its pretty important its
90
+ # wicked fast. Microbenchmarks away!
91
+ #
92
+ # obj - A JSON serializable object.
93
+ #
94
+ # Returns a String digest of the object.
95
+ def digest(obj)
96
+ digest = digest_class.new
97
+
98
+ ADD_VALUE_TO_DIGEST[obj.class].call(obj, digest)
99
+ digest.digest
100
+ end
101
+
102
+ # Internal: Pack a binary digest to a hex encoded string.
103
+ #
104
+ # bin - String bytes
105
+ #
106
+ # Returns hex String.
107
+ def pack_hexdigest(bin)
108
+ bin.unpack('H*').first
109
+ end
110
+
111
+ # Internal: Unpack a hex encoded digest string into binary bytes.
112
+ #
113
+ # hex - String hex
114
+ #
115
+ # Returns binary String.
116
+ def unpack_hexdigest(hex)
117
+ [hex].pack('H*')
118
+ end
119
+
120
+ # Internal: Pack a binary digest to a base64 encoded string.
121
+ #
122
+ # bin - String bytes
123
+ #
124
+ # Returns base64 String.
125
+ def pack_base64digest(bin)
126
+ [bin].pack('m0')
127
+ end
128
+
129
+ # Internal: Pack a binary digest to a urlsafe base64 encoded string.
130
+ #
131
+ # bin - String bytes
132
+ #
133
+ # Returns urlsafe base64 String.
134
+ def pack_urlsafe_base64digest(bin)
135
+ str = pack_base64digest(bin)
136
+ str.tr!('+/'.freeze, '-_'.freeze)
137
+ str.tr!('='.freeze, ''.freeze)
138
+ str
139
+ end
140
+
141
+ # Internal: Maps digest class to the CSP hash algorithm name.
142
+ HASH_ALGORITHMS = {
143
+ Digest::SHA256 => 'sha256'.freeze,
144
+ Digest::SHA384 => 'sha384'.freeze,
145
+ Digest::SHA512 => 'sha512'.freeze
146
+ }
147
+
148
+ # Public: Generate hash for use in the `integrity` attribute of an asset tag
149
+ # as per the subresource integrity specification.
150
+ #
151
+ # digest - The String byte digest of the asset content.
152
+ #
153
+ # Returns a String or nil if hash algorithm is incompatible.
154
+ def integrity_uri(digest)
155
+ case digest
156
+ when Digest::Base
157
+ digest_class = digest.class
158
+ digest = digest.digest
159
+ when String
160
+ digest_class = DIGEST_SIZES[digest.bytesize]
161
+ else
162
+ raise TypeError, "unknown digest: #{digest.inspect}"
163
+ end
164
+
165
+ if hash_name = HASH_ALGORITHMS[digest_class]
166
+ "#{hash_name}-#{pack_base64digest(digest)}"
167
+ end
168
+ end
169
+
170
+ # Public: Generate hash for use in the `integrity` attribute of an asset tag
171
+ # as per the subresource integrity specification.
172
+ #
173
+ # digest - The String hexbyte digest of the asset content.
174
+ #
175
+ # Returns a String or nil if hash algorithm is incompatible.
176
+ def hexdigest_integrity_uri(hexdigest)
177
+ integrity_uri(unpack_hexdigest(hexdigest))
178
+ end
179
+ end
180
+ end