sprockets 3.7.5 → 4.0.0.beta1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +2 -307
  3. data/README.md +21 -35
  4. data/bin/sprockets +11 -8
  5. data/lib/rake/sprocketstask.rb +2 -2
  6. data/lib/sprockets/asset.rb +8 -21
  7. data/lib/sprockets/autoload/babel.rb +7 -0
  8. data/lib/sprockets/autoload/jsminc.rb +7 -0
  9. data/lib/sprockets/autoload/sassc.rb +7 -0
  10. data/lib/sprockets/autoload.rb +3 -0
  11. data/lib/sprockets/babel_processor.rb +58 -0
  12. data/lib/sprockets/base.rb +8 -8
  13. data/lib/sprockets/bower.rb +4 -2
  14. data/lib/sprockets/bundle.rb +1 -1
  15. data/lib/sprockets/cache.rb +2 -4
  16. data/lib/sprockets/closure_compressor.rb +1 -2
  17. data/lib/sprockets/coffee_script_processor.rb +9 -3
  18. data/lib/sprockets/compressing.rb +2 -2
  19. data/lib/sprockets/configuration.rb +1 -7
  20. data/lib/sprockets/context.rb +10 -18
  21. data/lib/sprockets/digest_utils.rb +40 -52
  22. data/lib/sprockets/directive_processor.rb +10 -15
  23. data/lib/sprockets/erb_processor.rb +1 -13
  24. data/lib/sprockets/http_utils.rb +19 -4
  25. data/lib/sprockets/jsminc_compressor.rb +31 -0
  26. data/lib/sprockets/jst_processor.rb +10 -10
  27. data/lib/sprockets/loader.rb +34 -28
  28. data/lib/sprockets/manifest.rb +3 -35
  29. data/lib/sprockets/manifest_utils.rb +0 -2
  30. data/lib/sprockets/mime.rb +7 -62
  31. data/lib/sprockets/path_dependency_utils.rb +2 -11
  32. data/lib/sprockets/path_digest_utils.rb +1 -1
  33. data/lib/sprockets/path_utils.rb +43 -18
  34. data/lib/sprockets/preprocessors/default_source_map.rb +24 -0
  35. data/lib/sprockets/processing.rb +30 -61
  36. data/lib/sprockets/processor_utils.rb +27 -28
  37. data/lib/sprockets/resolve.rb +172 -92
  38. data/lib/sprockets/sass_cache_store.rb +1 -6
  39. data/lib/sprockets/sass_compressor.rb +14 -1
  40. data/lib/sprockets/sass_processor.rb +18 -8
  41. data/lib/sprockets/sassc_compressor.rb +30 -0
  42. data/lib/sprockets/sassc_processor.rb +68 -0
  43. data/lib/sprockets/server.rb +11 -22
  44. data/lib/sprockets/source_map_comment_processor.rb +29 -0
  45. data/lib/sprockets/source_map_processor.rb +40 -0
  46. data/lib/sprockets/source_map_utils.rb +345 -0
  47. data/lib/sprockets/transformers.rb +62 -35
  48. data/lib/sprockets/uglifier_compressor.rb +12 -5
  49. data/lib/sprockets/unloaded_asset.rb +12 -11
  50. data/lib/sprockets/uri_tar.rb +4 -2
  51. data/lib/sprockets/uri_utils.rb +9 -14
  52. data/lib/sprockets/utils.rb +30 -79
  53. data/lib/sprockets/version.rb +1 -1
  54. data/lib/sprockets.rb +80 -35
  55. metadata +70 -41
  56. data/LICENSE +0 -21
  57. data/lib/sprockets/coffee_script_template.rb +0 -17
  58. data/lib/sprockets/deprecation.rb +0 -90
  59. data/lib/sprockets/eco_template.rb +0 -17
  60. data/lib/sprockets/ejs_template.rb +0 -17
  61. data/lib/sprockets/engines.rb +0 -92
  62. data/lib/sprockets/erb_template.rb +0 -11
  63. data/lib/sprockets/legacy.rb +0 -322
  64. data/lib/sprockets/legacy_proc_processor.rb +0 -35
  65. data/lib/sprockets/legacy_tilt_processor.rb +0 -29
  66. data/lib/sprockets/sass_template.rb +0 -19
@@ -1,92 +0,0 @@
1
- require 'sprockets/legacy_tilt_processor'
2
- require 'sprockets/utils'
3
-
4
- module Sprockets
5
- # `Engines` provides a global and `Environment` instance registry.
6
- #
7
- # An engine is a type of processor that is bound to a filename
8
- # extension. `application.js.coffee` indicates that the
9
- # `CoffeeScriptProcessor` engine will be ran on the file.
10
- #
11
- # Extensions can be stacked and will be evaulated from right to
12
- # left. `application.js.coffee.erb` will first run `ERBProcessor`
13
- # then `CoffeeScriptProcessor`.
14
- #
15
- # All `Engine`s must follow the `Template` interface. It is
16
- # recommended to subclass `Template`.
17
- #
18
- # Its recommended that you register engine changes on your local
19
- # `Environment` instance.
20
- #
21
- # environment.register_engine '.foo', FooProcessor
22
- #
23
- # The global registry is exposed for plugins to register themselves.
24
- #
25
- # Sprockets.register_engine '.sass', SassProcessor
26
- #
27
- module Engines
28
- include Utils
29
-
30
- # Returns a `Hash` of `Engine`s registered on the `Environment`.
31
- # If an `ext` argument is supplied, the `Engine` associated with
32
- # that extension will be returned.
33
- #
34
- # environment.engines
35
- # # => {".coffee" => CoffeeScriptProcessor, ".sass" => SassProcessor, ...}
36
- #
37
- def engines
38
- config[:engines]
39
- end
40
-
41
- # Internal: Returns a `Hash` of engine extensions to mime types.
42
- #
43
- # # => { '.coffee' => 'application/javascript' }
44
- def engine_mime_types
45
- config[:engine_mime_types]
46
- end
47
-
48
- # Registers a new Engine `klass` for `ext`. If the `ext` already
49
- # has an engine registered, it will be overridden.
50
- #
51
- # environment.register_engine '.coffee', CoffeeScriptProcessor
52
- #
53
- def register_engine(ext, klass, options = {})
54
- unless options[:silence_deprecation]
55
- msg = <<-MSG
56
- Sprockets method `register_engine` is deprecated.
57
- Please register a mime type using `register_mime_type` then
58
- use `register_compressor` or `register_transformer`.
59
- https://github.com/rails/sprockets/blob/master/guides/extending_sprockets.md#supporting-all-versions-of-sprockets-in-processors
60
- MSG
61
-
62
- Deprecation.new([caller.first]).warn(msg)
63
- end
64
-
65
- ext = Sprockets::Utils.normalize_extension(ext)
66
-
67
- self.computed_config = {}
68
-
69
- if klass.respond_to?(:call)
70
- processor = klass
71
- self.config = hash_reassoc(config, :engines) do |engines|
72
- engines.merge(ext => klass)
73
- end
74
- if options[:mime_type]
75
- self.config = hash_reassoc(config, :engine_mime_types) do |mime_types|
76
- mime_types.merge(ext.to_s => options[:mime_type])
77
- end
78
- end
79
- else
80
- processor = LegacyTiltProcessor.new(klass)
81
- self.config = hash_reassoc(config, :engines) do |engines|
82
- engines.merge(ext => processor)
83
- end
84
- if klass.respond_to?(:default_mime_type) && klass.default_mime_type
85
- self.config = hash_reassoc(config, :engine_mime_types) do |mime_types|
86
- mime_types.merge(ext.to_s => klass.default_mime_type)
87
- end
88
- end
89
- end
90
- end
91
- end
92
- end
@@ -1,11 +0,0 @@
1
- require 'sprockets/erb_processor'
2
-
3
- module Sprockets
4
- # Deprecated
5
- class ERBTemplate < ERBProcessor
6
- def call(*args)
7
- Deprecation.new.warn "ERBTemplate is deprecated please use ERBProcessor instead"
8
- super
9
- end
10
- end
11
- end
@@ -1,322 +0,0 @@
1
- require 'pathname'
2
- require 'sprockets/asset'
3
- require 'sprockets/base'
4
- require 'sprockets/cached_environment'
5
- require 'sprockets/context'
6
- require 'sprockets/manifest'
7
- require 'sprockets/resolve'
8
-
9
- module Sprockets
10
- autoload :CoffeeScriptTemplate, 'sprockets/coffee_script_template'
11
- autoload :EcoTemplate, 'sprockets/eco_template'
12
- autoload :EjsTemplate, 'sprockets/ejs_template'
13
- autoload :ERBTemplate, 'sprockets/erb_template'
14
- autoload :SassTemplate, 'sprockets/sass_template'
15
- autoload :ScssTemplate, 'sprockets/sass_template'
16
-
17
- # Deprecated
18
- Index = CachedEnvironment
19
-
20
- class Base
21
- include Resolve
22
-
23
- # Deprecated: Change default return type of resolve() to return 2.x
24
- # compatible plain filename String. 4.x will always return an Asset URI
25
- # and a set of file system dependencies that had to be read to compute the
26
- # result.
27
- #
28
- # 2.x
29
- #
30
- # resolve("foo.js")
31
- # # => "/path/to/app/javascripts/foo.js"
32
- #
33
- # 3.x
34
- #
35
- # resolve("foo.js")
36
- # # => "/path/to/app/javascripts/foo.js"
37
- #
38
- # resolve("foo.js", compat: true)
39
- # # => "/path/to/app/javascripts/foo.js"
40
- #
41
- # resolve("foo.js", compat: false)
42
- # # => [
43
- # # "file:///path/to/app/javascripts/foo.js?type=application/javascript"
44
- # # #<Set: {"file-digest:/path/to/app/javascripts/foo.js"}>
45
- # # ]
46
- #
47
- # 4.x
48
- #
49
- # resolve("foo.js")
50
- # # => [
51
- # # "file:///path/to/app/javascripts/foo.js?type=application/javascript"
52
- # # #<Set: {"file-digest:/path/to/app/javascripts/foo.js"}>
53
- # # ]
54
- #
55
- def resolve_with_compat(path, options = {})
56
- options = options.dup
57
- if options.delete(:compat) { true }
58
- uri, _ = resolve_without_compat(path, options)
59
- if uri
60
- path, _ = parse_asset_uri(uri)
61
- path
62
- else
63
- nil
64
- end
65
- else
66
- resolve_without_compat(path, options)
67
- end
68
- end
69
- alias_method :resolve_without_compat, :resolve
70
- alias_method :resolve, :resolve_with_compat
71
-
72
- # Deprecated: Iterate over all logical paths with a matcher.
73
- #
74
- # Remove from 4.x.
75
- #
76
- # args - List of matcher objects.
77
- #
78
- # Returns Enumerator if no block is given.
79
- def each_logical_path(*args, &block)
80
- return to_enum(__method__, *args) unless block_given?
81
-
82
- filters = args.flatten.map { |arg| Manifest.compile_match_filter(arg) }
83
- logical_paths.each do |a, b|
84
- if filters.any? { |f| f.call(a, b) }
85
- if block.arity == 2
86
- yield a, b
87
- else
88
- yield a
89
- end
90
- end
91
- end
92
-
93
- nil
94
- end
95
-
96
- # Deprecated: Enumerate over all logical paths in the environment.
97
- #
98
- # Returns an Enumerator of [logical_path, filename].
99
- def logical_paths
100
- return to_enum(__method__) unless block_given?
101
-
102
- seen = Set.new
103
-
104
- paths.each do |load_path|
105
- stat_tree(load_path).each do |filename, stat|
106
- next unless stat.file?
107
-
108
- path = split_subpath(load_path, filename)
109
- path, mime_type, _, _ = parse_path_extnames(path)
110
- path = normalize_logical_path(path)
111
- path += mime_types[mime_type][:extensions].first if mime_type
112
-
113
- if !seen.include?(path)
114
- yield path, filename
115
- seen << path
116
- end
117
- end
118
- end
119
-
120
- nil
121
- end
122
-
123
- def cache_get(key)
124
- cache.get(key)
125
- end
126
-
127
- def cache_set(key, value)
128
- cache.set(key, value)
129
- end
130
-
131
- def normalize_logical_path(path)
132
- dirname, basename = File.split(path)
133
- path = dirname if basename == 'index'
134
- path
135
- end
136
-
137
- private
138
- # Deprecated: Seriously.
139
- def matches_filter(filters, logical_path, filename)
140
- return true if filters.empty?
141
-
142
- filters.any? do |filter|
143
- if filter.is_a?(Regexp)
144
- filter.match(logical_path)
145
- elsif filter.respond_to?(:call)
146
- if filter.arity == 1
147
- filter.call(logical_path)
148
- else
149
- filter.call(logical_path, filename.to_s)
150
- end
151
- else
152
- File.fnmatch(filter.to_s, logical_path)
153
- end
154
- end
155
- end
156
-
157
- def unescape(str)
158
- str = URIUtils::URI_PARSER.unescape(str)
159
- str.force_encoding(Encoding.default_internal) if Encoding.default_internal
160
- str
161
- end
162
- end
163
-
164
- class Asset
165
- # Deprecated: Use #filename instead.
166
- #
167
- # Returns Pathname.
168
- def pathname
169
- @pathname ||= Pathname.new(filename)
170
- end
171
-
172
- # Deprecated: Expand asset into an `Array` of parts.
173
- #
174
- # Appending all of an assets body parts together should give you
175
- # the asset's contents as a whole.
176
- #
177
- # This allows you to link to individual files for debugging
178
- # purposes.
179
- #
180
- # Use Asset#included instead. Keeping a full copy of the bundle's processed
181
- # assets in memory (and in cache) is expensive and redundant. The common use
182
- # case is to relink to the assets anyway.
183
- #
184
- # Returns Array of Assets.
185
- def to_a
186
- if metadata[:included]
187
- metadata[:included].map { |uri| @environment.load(uri) }
188
- else
189
- [self]
190
- end
191
- end
192
-
193
- # Deprecated: Get all required Assets.
194
- #
195
- # See Asset#to_a
196
- #
197
- # Returns Array of Assets.
198
- def dependencies
199
- to_a.reject { |a| a.filename.eql?(self.filename) }
200
- end
201
-
202
- # Deprecated: Returns Time of the last time the source was modified.
203
- #
204
- # Time resolution is normalized to the nearest second.
205
- #
206
- # Returns Time.
207
- def mtime
208
- Time.at(@mtime)
209
- end
210
- end
211
-
212
- class Context
213
- # Deprecated: Change default return type of resolve() to return 2.x
214
- # compatible plain filename String. 4.x will always return an Asset URI.
215
- #
216
- # 2.x
217
- #
218
- # resolve("foo.js")
219
- # # => "/path/to/app/javascripts/foo.js"
220
- #
221
- # 3.x
222
- #
223
- # resolve("foo.js")
224
- # # => "/path/to/app/javascripts/foo.js"
225
- #
226
- # resolve("foo.js", compat: true)
227
- # # => "/path/to/app/javascripts/foo.js"
228
- #
229
- # resolve("foo.js", compat: false)
230
- # # => "file:///path/to/app/javascripts/foo.js?type=application/javascript"
231
- #
232
- # 4.x
233
- #
234
- # resolve("foo.js")
235
- # # => "file:///path/to/app/javascripts/foo.js?type=application/javascript"
236
- #
237
- def resolve_with_compat(path, options = {})
238
- options = options.dup
239
-
240
- # Support old :content_type option, prefer :accept going forward
241
- if type = options.delete(:content_type)
242
- type = self.content_type if type == :self
243
- options[:accept] ||= type
244
- end
245
-
246
- if options.delete(:compat) { true }
247
- uri = resolve_without_compat(path, options)
248
- path, _ = environment.parse_asset_uri(uri)
249
- path
250
- else
251
- resolve_without_compat(path, options)
252
- end
253
- end
254
- alias_method :resolve_without_compat, :resolve
255
- alias_method :resolve, :resolve_with_compat
256
- end
257
-
258
- class Manifest
259
- # Deprecated: Compile logical path matching filter into a proc that can be
260
- # passed to logical_paths.select(&proc).
261
- #
262
- # compile_match_filter(proc { |logical_path|
263
- # File.extname(logical_path) == '.js'
264
- # })
265
- #
266
- # compile_match_filter(/application.js/)
267
- #
268
- # compile_match_filter("foo/*.js")
269
- #
270
- # Returns a Proc or raise a TypeError.
271
- def self.compile_match_filter(filter)
272
- # If the filter is already a proc, great nothing to do.
273
- if filter.respond_to?(:call)
274
- filter
275
- # If the filter is a regexp, wrap it in a proc that tests it against the
276
- # logical path.
277
- elsif filter.is_a?(Regexp)
278
- proc { |logical_path| filter.match(logical_path) }
279
- elsif filter.is_a?(String)
280
- # If its an absolute path, detect the matching full filename
281
- if PathUtils.absolute_path?(filter)
282
- proc { |logical_path, filename| filename == filter.to_s }
283
- else
284
- # Otherwise do an fnmatch against the logical path.
285
- proc { |logical_path| File.fnmatch(filter.to_s, logical_path) }
286
- end
287
- else
288
- raise TypeError, "unknown filter type: #{filter.inspect}"
289
- end
290
- end
291
-
292
- def self.simple_logical_path?(str)
293
- str.is_a?(String) &&
294
- !PathUtils.absolute_path?(str) &&
295
- str !~ /\*|\*\*|\?|\[|\]|\{|\}/
296
- end
297
-
298
- def self.compute_alias_logical_path(path)
299
- dirname, basename = File.split(path)
300
- extname = File.extname(basename)
301
- if File.basename(basename, extname) == 'index'
302
- "#{dirname}#{extname}"
303
- else
304
- nil
305
- end
306
- end
307
-
308
- # Deprecated: Filter logical paths in environment. Useful for selecting what
309
- # files you want to compile.
310
- #
311
- # Returns an Enumerator.
312
- def filter_logical_paths(*args)
313
- filters = args.flatten.map { |arg| self.class.compile_match_filter(arg) }
314
- environment.cached.logical_paths.select do |a, b|
315
- filters.any? { |f| f.call(a, b) }
316
- end
317
- end
318
-
319
- # Deprecated alias.
320
- alias_method :find_logical_paths, :filter_logical_paths
321
- end
322
- end
@@ -1,35 +0,0 @@
1
- require 'delegate'
2
-
3
- module Sprockets
4
- # Deprecated: Wraps legacy process Procs with new processor call signature.
5
- #
6
- # Will be removed in Sprockets 4.x.
7
- #
8
- # LegacyProcProcessor.new(:compress,
9
- # proc { |context, data| data.gsub(...) })
10
- #
11
- class LegacyProcProcessor < Delegator
12
- def initialize(name, proc)
13
- @name = name
14
- @proc = proc
15
- end
16
-
17
- def __getobj__
18
- @proc
19
- end
20
-
21
- def name
22
- "Sprockets::LegacyProcProcessor (#{@name})"
23
- end
24
-
25
- def to_s
26
- name
27
- end
28
-
29
- def call(input)
30
- context = input[:environment].context_class.new(input)
31
- data = @proc.call(context, input[:data])
32
- context.metadata.merge(data: data.to_str)
33
- end
34
- end
35
- end
@@ -1,29 +0,0 @@
1
- require 'delegate'
2
-
3
- module Sprockets
4
- # Deprecated: Wraps legacy engine and process Tilt templates with new
5
- # processor call signature.
6
- #
7
- # Will be removed in Sprockets 4.x.
8
- #
9
- # LegacyTiltProcessor.new(Tilt::CoffeeScriptProcessor)
10
- #
11
- class LegacyTiltProcessor < Delegator
12
- def initialize(klass)
13
- @klass = klass
14
- end
15
-
16
- def __getobj__
17
- @klass
18
- end
19
-
20
- def call(input)
21
- filename = input[:filename]
22
- data = input[:data]
23
- context = input[:environment].context_class.new(input)
24
-
25
- data = @klass.new(filename) { data }.render(context, {})
26
- context.metadata.merge(data: data.to_str)
27
- end
28
- end
29
- end
@@ -1,19 +0,0 @@
1
- require 'sprockets/sass_processor'
2
-
3
- module Sprockets
4
- # Deprecated
5
- class SassTemplate < SassProcessor
6
- def self.call(*args)
7
- Deprecation.new.warn "SassTemplate is deprecated please use SassProcessor instead"
8
- super
9
- end
10
- end
11
-
12
- # Deprecated
13
- class ScssTemplate < ScssProcessor
14
- def self.call(*args)
15
- Deprecation.new.warn "ScssTemplate is deprecated please use ScssProcessor instead"
16
- super
17
- end
18
- end
19
- end