sprockets 3.7.3 → 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.
- checksums.yaml +5 -5
- data/CHANGELOG.md +2 -299
- data/README.md +21 -35
- data/bin/sprockets +11 -8
- data/lib/rake/sprocketstask.rb +2 -2
- data/lib/sprockets/asset.rb +8 -21
- data/lib/sprockets/autoload/babel.rb +7 -0
- data/lib/sprockets/autoload/jsminc.rb +7 -0
- data/lib/sprockets/autoload/sassc.rb +7 -0
- data/lib/sprockets/autoload.rb +3 -0
- data/lib/sprockets/babel_processor.rb +58 -0
- data/lib/sprockets/base.rb +8 -8
- data/lib/sprockets/bower.rb +4 -2
- data/lib/sprockets/bundle.rb +1 -1
- data/lib/sprockets/cache.rb +2 -4
- data/lib/sprockets/closure_compressor.rb +1 -2
- data/lib/sprockets/coffee_script_processor.rb +9 -3
- data/lib/sprockets/compressing.rb +2 -2
- data/lib/sprockets/configuration.rb +1 -7
- data/lib/sprockets/context.rb +10 -18
- data/lib/sprockets/digest_utils.rb +40 -52
- data/lib/sprockets/directive_processor.rb +10 -15
- data/lib/sprockets/erb_processor.rb +1 -13
- data/lib/sprockets/http_utils.rb +19 -4
- data/lib/sprockets/jsminc_compressor.rb +31 -0
- data/lib/sprockets/jst_processor.rb +10 -10
- data/lib/sprockets/loader.rb +34 -28
- data/lib/sprockets/manifest.rb +3 -35
- data/lib/sprockets/manifest_utils.rb +0 -2
- data/lib/sprockets/mime.rb +7 -62
- data/lib/sprockets/path_dependency_utils.rb +2 -11
- data/lib/sprockets/path_digest_utils.rb +1 -1
- data/lib/sprockets/path_utils.rb +43 -18
- data/lib/sprockets/preprocessors/default_source_map.rb +24 -0
- data/lib/sprockets/processing.rb +30 -61
- data/lib/sprockets/processor_utils.rb +27 -28
- data/lib/sprockets/resolve.rb +172 -92
- data/lib/sprockets/sass_cache_store.rb +1 -6
- data/lib/sprockets/sass_compressor.rb +14 -1
- data/lib/sprockets/sass_processor.rb +18 -8
- data/lib/sprockets/sassc_compressor.rb +30 -0
- data/lib/sprockets/sassc_processor.rb +68 -0
- data/lib/sprockets/server.rb +11 -22
- data/lib/sprockets/source_map_comment_processor.rb +29 -0
- data/lib/sprockets/source_map_processor.rb +40 -0
- data/lib/sprockets/source_map_utils.rb +345 -0
- data/lib/sprockets/transformers.rb +62 -35
- data/lib/sprockets/uglifier_compressor.rb +12 -5
- data/lib/sprockets/unloaded_asset.rb +12 -11
- data/lib/sprockets/uri_tar.rb +4 -2
- data/lib/sprockets/uri_utils.rb +5 -8
- data/lib/sprockets/utils.rb +30 -79
- data/lib/sprockets/version.rb +1 -1
- data/lib/sprockets.rb +80 -35
- metadata +70 -41
- data/LICENSE +0 -21
- data/lib/sprockets/coffee_script_template.rb +0 -17
- data/lib/sprockets/deprecation.rb +0 -90
- data/lib/sprockets/eco_template.rb +0 -17
- data/lib/sprockets/ejs_template.rb +0 -17
- data/lib/sprockets/engines.rb +0 -92
- data/lib/sprockets/erb_template.rb +0 -11
- data/lib/sprockets/legacy.rb +0 -330
- data/lib/sprockets/legacy_proc_processor.rb +0 -35
- data/lib/sprockets/legacy_tilt_processor.rb +0 -29
- data/lib/sprockets/sass_template.rb +0 -19
@@ -18,6 +18,8 @@ module Sprockets
|
|
18
18
|
config[:transformers]
|
19
19
|
end
|
20
20
|
|
21
|
+
Transformer = Struct.new :from, :to, :proc
|
22
|
+
|
21
23
|
# Public: Register a transformer from and to a mime type.
|
22
24
|
#
|
23
25
|
# from - String mime type
|
@@ -33,10 +35,30 @@ module Sprockets
|
|
33
35
|
#
|
34
36
|
# Returns nothing.
|
35
37
|
def register_transformer(from, to, proc)
|
36
|
-
self.config = hash_reassoc(config, :registered_transformers
|
37
|
-
transformers.
|
38
|
+
self.config = hash_reassoc(config, :registered_transformers) do |transformers|
|
39
|
+
transformers << Transformer.new(from, to, proc)
|
40
|
+
end
|
41
|
+
compute_transformers!(self.config[:registered_transformers])
|
42
|
+
end
|
43
|
+
|
44
|
+
# Internal: Register transformer for existing type adding a suffix.
|
45
|
+
#
|
46
|
+
# types - Array of existing mime type Strings
|
47
|
+
# type_format - String suffix formatting string
|
48
|
+
# extname - String extension to append
|
49
|
+
# processor - Callable block that accepts an input Hash.
|
50
|
+
#
|
51
|
+
# Returns nothing.
|
52
|
+
def register_transformer_suffix(types, type_format, extname, processor)
|
53
|
+
Array(types).each do |type|
|
54
|
+
extensions, charset = mime_types[type].values_at(:extensions, :charset)
|
55
|
+
parts = type.split('/')
|
56
|
+
suffix_type = type_format.sub('\1', parts[0]).sub('\2', parts[1])
|
57
|
+
extensions = extensions.map { |ext| "#{ext}#{extname}" }
|
58
|
+
|
59
|
+
register_mime_type(suffix_type, extensions: extensions, charset: charset)
|
60
|
+
register_transformer(suffix_type, type, processor)
|
38
61
|
end
|
39
|
-
compute_transformers!
|
40
62
|
end
|
41
63
|
|
42
64
|
# Internal: Resolve target mime type that the source type should be
|
@@ -89,53 +111,58 @@ module Sprockets
|
|
89
111
|
# types - Array of mime type steps
|
90
112
|
#
|
91
113
|
# Returns Processor.
|
92
|
-
def compose_transformers(transformers, types)
|
114
|
+
def compose_transformers(transformers, types, preprocessors, postprocessors)
|
93
115
|
if types.length < 2
|
94
116
|
raise ArgumentError, "too few transform types: #{types.inspect}"
|
95
117
|
end
|
96
118
|
|
97
|
-
|
98
|
-
processors = []
|
99
|
-
|
100
|
-
loop do
|
101
|
-
src = types[i]
|
102
|
-
dst = types[i+1]
|
103
|
-
break unless src && dst
|
104
|
-
|
119
|
+
processors = types.each_cons(2).map { |src, dst|
|
105
120
|
unless processor = transformers[src][dst]
|
106
121
|
raise ArgumentError, "missing transformer for type: #{src} to #{dst}"
|
107
122
|
end
|
108
|
-
|
109
|
-
|
110
|
-
processors.concat config[:preprocessors][dst]
|
123
|
+
processor
|
124
|
+
}
|
111
125
|
|
112
|
-
|
113
|
-
end
|
114
|
-
|
115
|
-
if processors.size > 1
|
116
|
-
compose_processors(*processors.reverse)
|
117
|
-
elsif processors.size == 1
|
118
|
-
processors.first
|
119
|
-
end
|
126
|
+
compose_transformer_list processors, preprocessors, postprocessors
|
120
127
|
end
|
121
128
|
|
122
129
|
private
|
123
|
-
def
|
124
|
-
|
125
|
-
|
130
|
+
def compose_transformer_list(transformers, preprocessors, postprocessors)
|
131
|
+
processors = []
|
132
|
+
|
133
|
+
transformers.each do |processor|
|
134
|
+
processors.concat postprocessors[processor.from]
|
135
|
+
processors << processor.proc
|
136
|
+
processors.concat preprocessors[processor.to]
|
137
|
+
end
|
138
|
+
|
139
|
+
if processors.size > 1
|
140
|
+
compose_processors(*processors.reverse)
|
141
|
+
elsif processors.size == 1
|
142
|
+
processors.first
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def compute_transformers!(registered_transformers)
|
147
|
+
preprocessors = self.config[:preprocessors]
|
148
|
+
postprocessors = self.config[:postprocessors]
|
149
|
+
transformers = Hash.new { {} }
|
126
150
|
inverted_transformers = Hash.new { Set.new }
|
151
|
+
incoming_edges = registered_transformers.group_by(&:from)
|
152
|
+
|
153
|
+
registered_transformers.each do |t|
|
154
|
+
traversals = dfs_paths([t]) { |k| incoming_edges.fetch(k.to, []) }
|
127
155
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
src, dst = types.first, types.last
|
132
|
-
processor = compose_transformers(registered_transformers, types)
|
156
|
+
traversals.each do |nodes|
|
157
|
+
src, dst = nodes.first.from, nodes.last.to
|
158
|
+
processor = compose_transformer_list nodes, preprocessors, postprocessors
|
133
159
|
|
134
|
-
|
135
|
-
|
160
|
+
transformers[src] = {} unless transformers.key?(src)
|
161
|
+
transformers[src][dst] = processor
|
136
162
|
|
137
|
-
|
138
|
-
|
163
|
+
inverted_transformers[dst] = Set.new unless inverted_transformers.key?(dst)
|
164
|
+
inverted_transformers[dst] << src
|
165
|
+
end
|
139
166
|
end
|
140
167
|
|
141
168
|
self.config = hash_reassoc(config, :transformers) { transformers }
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'sprockets/autoload'
|
2
2
|
require 'sprockets/digest_utils'
|
3
|
+
require 'sprockets/source_map_utils'
|
3
4
|
|
4
5
|
module Sprockets
|
5
6
|
# Public: Uglifier/Uglify compressor.
|
@@ -15,7 +16,7 @@ module Sprockets
|
|
15
16
|
# Sprockets::UglifierCompressor.new(comments: :copyright)
|
16
17
|
#
|
17
18
|
class UglifierCompressor
|
18
|
-
VERSION = '
|
19
|
+
VERSION = '2'
|
19
20
|
|
20
21
|
# Public: Return singleton instance with default options.
|
21
22
|
#
|
@@ -41,16 +42,22 @@ module Sprockets
|
|
41
42
|
options[:copyright] ||= false
|
42
43
|
else
|
43
44
|
# Uglifier >= 2.x
|
44
|
-
options[:
|
45
|
+
options[:copyright] ||= :none
|
45
46
|
end
|
46
47
|
|
47
|
-
@
|
48
|
+
@uglifier = Autoload::Uglifier.new(options)
|
48
49
|
@cache_key = "#{self.class.name}:#{Autoload::Uglifier::VERSION}:#{VERSION}:#{DigestUtils.digest(options)}".freeze
|
49
50
|
end
|
50
51
|
|
51
52
|
def call(input)
|
52
|
-
@uglifier
|
53
|
-
|
53
|
+
js, map = @uglifier.compile_with_map(input[:data])
|
54
|
+
|
55
|
+
map = SourceMapUtils.combine_source_maps(
|
56
|
+
input[:metadata][:map],
|
57
|
+
SourceMapUtils.decode_json_source_map(map)["mappings"]
|
58
|
+
)
|
59
|
+
|
60
|
+
{ data: js, map: map }
|
54
61
|
end
|
55
62
|
end
|
56
63
|
end
|
@@ -12,8 +12,8 @@ module Sprockets
|
|
12
12
|
# and full path such as
|
13
13
|
# "file:///Path/app/assets/js/app.js?type=application/javascript"
|
14
14
|
# env - The current "environment" that assets are being loaded into.
|
15
|
-
# We need it so we know where the +root+ (directory where
|
16
|
-
# is being invoked). We also need for the `file_digest` method,
|
15
|
+
# We need it so we know where the +root+ (directory where Sprockets
|
16
|
+
# is being invoked). We also need it for the `file_digest` method,
|
17
17
|
# since, for some strange reason, memoization is provided by
|
18
18
|
# overriding methods such as `stat` in the `PathUtils` module.
|
19
19
|
#
|
@@ -30,7 +30,7 @@ module Sprockets
|
|
30
30
|
# Internal: Full file path without schema
|
31
31
|
#
|
32
32
|
# This returns a string containing the full path to the asset without the schema.
|
33
|
-
# Information is loaded
|
33
|
+
# Information is loaded lazily since we want `UnloadedAsset.new(dep, self).relative_path`
|
34
34
|
# to be fast. Calling this method the first time allocates an array and a hash.
|
35
35
|
#
|
36
36
|
# Example
|
@@ -48,8 +48,8 @@ module Sprockets
|
|
48
48
|
|
49
49
|
# Internal: Hash of param values
|
50
50
|
#
|
51
|
-
# This information is generated and used internally by
|
52
|
-
# Known keys include `:type` which
|
51
|
+
# This information is generated and used internally by Sprockets.
|
52
|
+
# Known keys include `:type` which stores the asset's mime-type, `:id` which is a fully resolved
|
53
53
|
# digest for the asset (includes dependency digest as opposed to a digest of only file contents)
|
54
54
|
# and `:pipeline`. Hash may be empty.
|
55
55
|
#
|
@@ -79,12 +79,12 @@ module Sprockets
|
|
79
79
|
|
80
80
|
# Public: Dependency History key
|
81
81
|
#
|
82
|
-
# Used to retrieve an array of "histories" each of which
|
82
|
+
# Used to retrieve an array of "histories" each of which contains a set of stored dependencies
|
83
83
|
# for a given asset path and filename digest.
|
84
84
|
#
|
85
|
-
# A dependency can refer to either an asset
|
85
|
+
# A dependency can refer to either an asset e.g. index.js
|
86
86
|
# may rely on jquery.js (so jquery.js is a dependency), or other factors that may affect
|
87
|
-
# compilation, such as the VERSION of
|
87
|
+
# compilation, such as the VERSION of Sprockets (i.e. the environment) and what "processors"
|
88
88
|
# are used.
|
89
89
|
#
|
90
90
|
# For example a history array with one Set of dependencies may look like:
|
@@ -97,7 +97,7 @@ module Sprockets
|
|
97
97
|
# This method of asset lookup is used to ensure that none of the dependencies have been modified
|
98
98
|
# since last lookup. If one of them has, the key will be different and a new entry must be stored.
|
99
99
|
#
|
100
|
-
# URI
|
100
|
+
# URI dependencies are later converted to "compressed" paths
|
101
101
|
#
|
102
102
|
# Returns a String.
|
103
103
|
def dependency_history_key
|
@@ -108,8 +108,9 @@ module Sprockets
|
|
108
108
|
#
|
109
109
|
# Used to retrieve a string containing the "compressed" path to an asset based on
|
110
110
|
# a digest. The digest is generated from dependencies stored via information stored in
|
111
|
-
# the `dependency_history_key` after each of the "dependencies" is "resolved"
|
112
|
-
# "environment-version" may be resolved to "environment-1.0-3.2.0"
|
111
|
+
# the `dependency_history_key` after each of the "dependencies" is "resolved".
|
112
|
+
# For example "environment-version" may be resolved to "environment-1.0-3.2.0"
|
113
|
+
# for version "3.2.0" of Sprockets
|
113
114
|
#
|
114
115
|
# Returns a String.
|
115
116
|
def digest_key(digest)
|
data/lib/sprockets/uri_tar.rb
CHANGED
@@ -14,8 +14,10 @@ module Sprockets
|
|
14
14
|
@env = env
|
15
15
|
uri = uri.to_s
|
16
16
|
if uri.include?("://".freeze)
|
17
|
-
|
18
|
-
@scheme
|
17
|
+
uri_array = uri.split("://".freeze)
|
18
|
+
@scheme = uri_array.shift
|
19
|
+
@scheme << "://".freeze
|
20
|
+
@path = uri_array.join("".freeze)
|
19
21
|
else
|
20
22
|
@scheme = "".freeze
|
21
23
|
@path = uri
|
data/lib/sprockets/uri_utils.rb
CHANGED
@@ -50,9 +50,6 @@ module Sprockets
|
|
50
50
|
# Hack for parsing Windows "file:///C:/Users/IEUser" paths
|
51
51
|
path.gsub!(/^\/([a-zA-Z]:)/, '\1'.freeze)
|
52
52
|
|
53
|
-
host = nil if host && host.empty?
|
54
|
-
query = nil if query && query.empty?
|
55
|
-
|
56
53
|
[scheme, host, path, query]
|
57
54
|
end
|
58
55
|
|
@@ -62,7 +59,7 @@ module Sprockets
|
|
62
59
|
def join_file_uri(scheme, host, path, query)
|
63
60
|
str = "#{scheme}://"
|
64
61
|
str << host if host
|
65
|
-
path = "/#{path}" unless path.start_with?("/")
|
62
|
+
path = "/#{path}" unless path.start_with?("/".freeze)
|
66
63
|
str << URI::Generic::DEFAULT_PARSER.escape(path)
|
67
64
|
str << "?#{query}" if query
|
68
65
|
str
|
@@ -75,7 +72,7 @@ module Sprockets
|
|
75
72
|
# Returns true or false.
|
76
73
|
def valid_asset_uri?(str)
|
77
74
|
# Quick prefix check before attempting a full parse
|
78
|
-
str.start_with?("file://") && parse_asset_uri(str) ? true : false
|
75
|
+
str.start_with?("file://".freeze) && parse_asset_uri(str) ? true : false
|
79
76
|
rescue URI::InvalidURIError
|
80
77
|
false
|
81
78
|
end
|
@@ -171,7 +168,7 @@ module Sprockets
|
|
171
168
|
end
|
172
169
|
end
|
173
170
|
|
174
|
-
"#{query.join('&')}" if query.any?
|
171
|
+
"#{query.join('&'.freeze)}" if query.any?
|
175
172
|
end
|
176
173
|
|
177
174
|
# Internal: Parse query string into hash of params
|
@@ -180,8 +177,8 @@ module Sprockets
|
|
180
177
|
#
|
181
178
|
# Return Hash of params.
|
182
179
|
def parse_uri_query_params(query)
|
183
|
-
query.to_s.split('&').reduce({}) do |h, p|
|
184
|
-
k, v = p.split('=', 2)
|
180
|
+
query.to_s.split('&'.freeze).reduce({}) do |h, p|
|
181
|
+
k, v = p.split('='.freeze, 2)
|
185
182
|
v = URI::Generic::DEFAULT_PARSER.unescape(v) if v
|
186
183
|
h[k.to_sym] = v || true
|
187
184
|
h
|
data/lib/sprockets/utils.rb
CHANGED
@@ -14,15 +14,11 @@ module Sprockets
|
|
14
14
|
#
|
15
15
|
# Returns false if .dup would raise a TypeError, otherwise true.
|
16
16
|
def duplicable?(obj)
|
17
|
-
|
18
|
-
|
17
|
+
case obj
|
18
|
+
when NilClass, FalseClass, TrueClass, Symbol, Numeric
|
19
|
+
false
|
19
20
|
else
|
20
|
-
|
21
|
-
when NilClass, FalseClass, TrueClass, Symbol, Numeric
|
22
|
-
false
|
23
|
-
else
|
24
|
-
true
|
25
|
-
end
|
21
|
+
true
|
26
22
|
end
|
27
23
|
end
|
28
24
|
|
@@ -49,7 +45,8 @@ module Sprockets
|
|
49
45
|
# Similar to Hash#store for nested frozen hashes.
|
50
46
|
#
|
51
47
|
# hash - Hash
|
52
|
-
#
|
48
|
+
# key_a - Object key. Use multiple keys for nested hashes.
|
49
|
+
# key_b - Object key. Use multiple keys for nested hashes.
|
53
50
|
# block - Receives current value at key.
|
54
51
|
#
|
55
52
|
# Examples
|
@@ -60,13 +57,13 @@ module Sprockets
|
|
60
57
|
# end
|
61
58
|
#
|
62
59
|
# Returns duplicated frozen Hash.
|
63
|
-
def hash_reassoc(hash,
|
64
|
-
if
|
65
|
-
hash_reassoc1(hash,
|
66
|
-
|
67
|
-
hash_reassoc1(hash, keys[0]) do |value|
|
68
|
-
hash_reassoc(value, *keys[1..-1], &block)
|
60
|
+
def hash_reassoc(hash, key_a, key_b = nil, &block)
|
61
|
+
if key_b
|
62
|
+
hash_reassoc1(hash, key_a) do |value|
|
63
|
+
hash_reassoc(value, key_b, &block)
|
69
64
|
end
|
65
|
+
else
|
66
|
+
hash_reassoc1(hash, key_a, &block)
|
70
67
|
end
|
71
68
|
end
|
72
69
|
|
@@ -78,19 +75,16 @@ module Sprockets
|
|
78
75
|
def string_end_with_semicolon?(str)
|
79
76
|
i = str.size - 1
|
80
77
|
while i >= 0
|
81
|
-
c = str[i]
|
78
|
+
c = str[i]
|
82
79
|
i -= 1
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
unless c == 0x0A || c == 0x20 || c == 0x09
|
90
|
-
return c === 0x3B
|
80
|
+
if c == "\n" || c == " " || c == "\t"
|
81
|
+
next
|
82
|
+
elsif c != ";"
|
83
|
+
return false
|
84
|
+
else
|
85
|
+
return true
|
91
86
|
end
|
92
87
|
end
|
93
|
-
|
94
88
|
true
|
95
89
|
end
|
96
90
|
|
@@ -102,50 +96,11 @@ module Sprockets
|
|
102
96
|
#
|
103
97
|
# Returns buf String.
|
104
98
|
def concat_javascript_sources(buf, source)
|
105
|
-
buf
|
106
|
-
|
107
|
-
buf <<
|
108
|
-
|
109
|
-
# If the source contains non-ASCII characters, indexing on it becomes O(N).
|
110
|
-
# 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)
|
111
|
-
source = source.encode(Encoding::UTF_32LE) unless source.ascii_only?
|
112
|
-
|
113
|
-
if !string_end_with_semicolon?(source)
|
114
|
-
buf << ";\n"
|
115
|
-
elsif source[source.size - 1].ord != 0x0A
|
116
|
-
buf << "\n"
|
117
|
-
end
|
99
|
+
if buf.bytesize > 0
|
100
|
+
buf << ";" unless string_end_with_semicolon?(buf)
|
101
|
+
buf << "\n" unless buf.end_with?("\n")
|
118
102
|
end
|
119
|
-
|
120
|
-
buf
|
121
|
-
end
|
122
|
-
|
123
|
-
# Internal: Prepends a leading "." to an extension if its missing.
|
124
|
-
#
|
125
|
-
# normalize_extension("js")
|
126
|
-
# # => ".js"
|
127
|
-
#
|
128
|
-
# normalize_extension(".css")
|
129
|
-
# # => ".css"
|
130
|
-
#
|
131
|
-
def normalize_extension(extension)
|
132
|
-
extension = extension.to_s
|
133
|
-
if extension[/^\./]
|
134
|
-
extension
|
135
|
-
else
|
136
|
-
".#{extension}"
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
# Internal: Feature detect if UnboundMethods can #bind to any Object or
|
141
|
-
# just Objects that share the same super class.
|
142
|
-
# Basically if RUBY_VERSION >= 2.
|
143
|
-
UNBOUND_METHODS_BIND_TO_ANY_OBJECT = begin
|
144
|
-
foo = Module.new { def bar; end }
|
145
|
-
foo.instance_method(:bar).bind(Object.new)
|
146
|
-
true
|
147
|
-
rescue TypeError
|
148
|
-
false
|
103
|
+
buf << source
|
149
104
|
end
|
150
105
|
|
151
106
|
# Internal: Inject into target module for the duration of the block.
|
@@ -160,10 +115,6 @@ module Sprockets
|
|
160
115
|
old_methods[sym] = base.instance_method(sym) if base.method_defined?(sym)
|
161
116
|
end
|
162
117
|
|
163
|
-
unless UNBOUND_METHODS_BIND_TO_ANY_OBJECT
|
164
|
-
base.send(:include, mod) unless base < mod
|
165
|
-
end
|
166
|
-
|
167
118
|
mod.instance_methods.each do |sym|
|
168
119
|
method = mod.instance_method(sym)
|
169
120
|
base.send(:define_method, sym, method)
|
@@ -217,16 +168,16 @@ module Sprockets
|
|
217
168
|
# Returns an Array of node Arrays.
|
218
169
|
def dfs_paths(path)
|
219
170
|
paths = []
|
220
|
-
stack
|
171
|
+
stack = [path]
|
172
|
+
seen = Set.new
|
221
173
|
|
222
174
|
while path = stack.pop
|
223
|
-
|
224
|
-
|
225
|
-
paths << path if path.size > 1
|
175
|
+
seen.add(path.last)
|
176
|
+
paths << path
|
226
177
|
|
227
|
-
|
228
|
-
|
229
|
-
|
178
|
+
children = yield path.last
|
179
|
+
children.reverse_each do |node|
|
180
|
+
stack.push(path + [node]) unless seen.include?(node)
|
230
181
|
end
|
231
182
|
end
|
232
183
|
|
data/lib/sprockets/version.rb
CHANGED
data/lib/sprockets.rb
CHANGED
@@ -4,7 +4,6 @@ require 'sprockets/cache'
|
|
4
4
|
require 'sprockets/environment'
|
5
5
|
require 'sprockets/errors'
|
6
6
|
require 'sprockets/manifest'
|
7
|
-
require 'sprockets/deprecation'
|
8
7
|
|
9
8
|
module Sprockets
|
10
9
|
require 'sprockets/processor_utils'
|
@@ -23,21 +22,19 @@ module Sprockets
|
|
23
22
|
dependencies: Set.new.freeze,
|
24
23
|
dependency_resolvers: {}.freeze,
|
25
24
|
digest_class: Digest::SHA256,
|
26
|
-
engine_mime_types: {}.freeze,
|
27
|
-
engines: {}.freeze,
|
28
25
|
mime_exts: {}.freeze,
|
29
26
|
mime_types: {}.freeze,
|
30
27
|
paths: [].freeze,
|
31
28
|
pipelines: {}.freeze,
|
29
|
+
pipeline_exts: {}.freeze,
|
32
30
|
postprocessors: Hash.new { |h, k| [].freeze }.freeze,
|
33
31
|
preprocessors: Hash.new { |h, k| [].freeze }.freeze,
|
34
|
-
registered_transformers:
|
35
|
-
root:
|
32
|
+
registered_transformers: [].freeze,
|
33
|
+
root: __dir__.dup.freeze,
|
36
34
|
transformers: Hash.new { |h, k| {}.freeze }.freeze,
|
37
35
|
version: "",
|
38
36
|
gzip_enabled: true
|
39
37
|
}.freeze
|
40
|
-
self.computed_config = {}
|
41
38
|
|
42
39
|
@context_class = Context
|
43
40
|
|
@@ -48,6 +45,7 @@ module Sprockets
|
|
48
45
|
# Common asset text types
|
49
46
|
register_mime_type 'application/javascript', extensions: ['.js'], charset: :unicode
|
50
47
|
register_mime_type 'application/json', extensions: ['.json'], charset: :unicode
|
48
|
+
register_mime_type 'application/ruby', extensions: ['.rb']
|
51
49
|
register_mime_type 'application/xml', extensions: ['.xml']
|
52
50
|
register_mime_type 'text/css', extensions: ['.css'], charset: :css
|
53
51
|
register_mime_type 'text/html', extensions: ['.html', '.htm'], charset: :html
|
@@ -80,74 +78,123 @@ module Sprockets
|
|
80
78
|
register_mime_type 'application/x-font-opentype', extensions: ['.otf']
|
81
79
|
register_mime_type 'application/x-font-ttf', extensions: ['.ttf']
|
82
80
|
register_mime_type 'application/font-woff', extensions: ['.woff']
|
81
|
+
register_mime_type 'application/font-woff2', extensions: ['.woff2']
|
82
|
+
|
83
|
+
require 'sprockets/source_map_processor'
|
84
|
+
register_mime_type 'application/js-sourcemap+json', extensions: ['.js.map']
|
85
|
+
register_mime_type 'application/css-sourcemap+json', extensions: ['.css.map']
|
86
|
+
register_transformer 'application/javascript', 'application/js-sourcemap+json', SourceMapProcessor
|
87
|
+
register_transformer 'text/css', 'application/css-sourcemap+json', SourceMapProcessor
|
83
88
|
|
84
89
|
register_pipeline :source do |env|
|
85
90
|
[]
|
86
91
|
end
|
87
92
|
|
88
|
-
register_pipeline :self do |env, type, file_type
|
89
|
-
env.self_processors_for(type, file_type
|
93
|
+
register_pipeline :self do |env, type, file_type|
|
94
|
+
env.self_processors_for(type, file_type)
|
95
|
+
end
|
96
|
+
|
97
|
+
register_pipeline :default do |env, type, file_type|
|
98
|
+
# TODO: Hack for to inject source map transformer
|
99
|
+
if (type == "application/js-sourcemap+json" && file_type != "application/js-sourcemap+json") ||
|
100
|
+
(type == "application/css-sourcemap+json" && file_type != "application/css-sourcemap+json")
|
101
|
+
[SourceMapProcessor]
|
102
|
+
else
|
103
|
+
env.default_processors_for(type, file_type)
|
104
|
+
end
|
90
105
|
end
|
91
106
|
|
92
|
-
|
93
|
-
|
107
|
+
require 'sprockets/source_map_comment_processor'
|
108
|
+
register_pipeline :debug do
|
109
|
+
[SourceMapCommentProcessor]
|
94
110
|
end
|
95
111
|
|
112
|
+
require 'sprockets/preprocessors/default_source_map'
|
113
|
+
register_preprocessor 'text/css', Preprocessors::DefaultSourceMap.new
|
114
|
+
register_preprocessor 'application/javascript', Preprocessors::DefaultSourceMap.new
|
115
|
+
|
96
116
|
require 'sprockets/directive_processor'
|
97
|
-
register_preprocessor 'text/css', DirectiveProcessor.new(
|
98
|
-
|
99
|
-
)
|
100
|
-
register_preprocessor 'application/javascript', DirectiveProcessor.new(
|
101
|
-
comments: ["//", ["/*", "*/"]] + ["#", ["###", "###"]]
|
102
|
-
)
|
117
|
+
register_preprocessor 'text/css', DirectiveProcessor.new(comments: ["//", ["/*", "*/"]])
|
118
|
+
register_preprocessor 'application/javascript', DirectiveProcessor.new(comments: ["//", ["/*", "*/"]])
|
103
119
|
|
104
120
|
require 'sprockets/bundle'
|
105
121
|
register_bundle_processor 'application/javascript', Bundle
|
106
122
|
register_bundle_processor 'text/css', Bundle
|
107
123
|
|
108
|
-
register_bundle_metadata_reducer '*/*', :data, proc { "" },
|
124
|
+
register_bundle_metadata_reducer '*/*', :data, proc { "" }, :concat
|
109
125
|
register_bundle_metadata_reducer 'application/javascript', :data, proc { "" }, Utils.method(:concat_javascript_sources)
|
110
126
|
register_bundle_metadata_reducer '*/*', :links, :+
|
127
|
+
register_bundle_metadata_reducer '*/*', :map, SourceMapUtils.method(:concat_source_maps)
|
111
128
|
|
112
129
|
require 'sprockets/closure_compressor'
|
113
130
|
require 'sprockets/sass_compressor'
|
131
|
+
require 'sprockets/sassc_compressor'
|
132
|
+
require 'sprockets/jsminc_compressor'
|
114
133
|
require 'sprockets/uglifier_compressor'
|
115
134
|
require 'sprockets/yui_compressor'
|
116
135
|
register_compressor 'text/css', :sass, SassCompressor
|
136
|
+
register_compressor 'text/css', :sassc, SasscCompressor
|
117
137
|
register_compressor 'text/css', :scss, SassCompressor
|
138
|
+
register_compressor 'text/css', :scssc, SasscCompressor
|
118
139
|
register_compressor 'text/css', :yui, YUICompressor
|
119
140
|
register_compressor 'application/javascript', :closure, ClosureCompressor
|
141
|
+
register_compressor 'application/javascript', :jsmin, JSMincCompressor
|
142
|
+
register_compressor 'application/javascript', :jsminc, JSMincCompressor
|
120
143
|
register_compressor 'application/javascript', :uglifier, UglifierCompressor
|
121
144
|
register_compressor 'application/javascript', :uglify, UglifierCompressor
|
122
145
|
register_compressor 'application/javascript', :yui, YUICompressor
|
123
146
|
|
147
|
+
# Babel, TheFuture™ is now
|
148
|
+
require 'sprockets/babel_processor'
|
149
|
+
register_mime_type 'application/ecmascript-6', extensions: ['.es6'], charset: :unicode
|
150
|
+
register_transformer 'application/ecmascript-6', 'application/javascript', BabelProcessor
|
151
|
+
register_preprocessor 'application/ecmascript-6', DirectiveProcessor.new(comments: ["//", ["/*", "*/"]])
|
152
|
+
|
124
153
|
# Mmm, CoffeeScript
|
125
154
|
require 'sprockets/coffee_script_processor'
|
126
|
-
|
127
|
-
|
128
|
-
|
155
|
+
register_mime_type 'text/coffeescript', extensions: ['.coffee', '.js.coffee']
|
156
|
+
register_transformer 'text/coffeescript', 'application/javascript', CoffeeScriptProcessor
|
157
|
+
register_preprocessor 'text/coffeescript', DirectiveProcessor.new(comments: ["#", ["###", "###"]])
|
129
158
|
|
130
|
-
# JST
|
159
|
+
# JST processors
|
131
160
|
require 'sprockets/eco_processor'
|
132
161
|
require 'sprockets/ejs_processor'
|
133
162
|
require 'sprockets/jst_processor'
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
163
|
+
register_mime_type 'text/eco', extensions: ['.eco', '.jst.eco']
|
164
|
+
register_mime_type 'text/ejs', extensions: ['.ejs', '.jst.ejs']
|
165
|
+
register_transformer 'text/eco', 'application/javascript+function', EcoProcessor
|
166
|
+
register_transformer 'text/ejs', 'application/javascript+function', EjsProcessor
|
167
|
+
register_transformer 'application/javascript+function', 'application/javascript', JstProcessor
|
139
168
|
|
140
|
-
# CSS
|
169
|
+
# CSS processors
|
141
170
|
require 'sprockets/sass_processor'
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
171
|
+
register_mime_type 'text/sass', extensions: ['.sass', '.css.sass']
|
172
|
+
register_mime_type 'text/scss', extensions: ['.scss', '.css.scss']
|
173
|
+
register_transformer 'text/sass', 'text/css', SassProcessor
|
174
|
+
register_transformer 'text/scss', 'text/css', ScssProcessor
|
175
|
+
register_preprocessor 'text/sass', DirectiveProcessor.new(comments: ["//", ["/*", "*/"]])
|
176
|
+
register_preprocessor 'text/scss', DirectiveProcessor.new(comments: ["//", ["/*", "*/"]])
|
146
177
|
register_bundle_metadata_reducer 'text/css', :sass_dependencies, Set.new, :+
|
147
178
|
|
148
|
-
#
|
179
|
+
# ERB
|
149
180
|
require 'sprockets/erb_processor'
|
150
|
-
|
181
|
+
register_transformer_suffix(%w(
|
182
|
+
application/ecmascript-6
|
183
|
+
application/javascript
|
184
|
+
application/json
|
185
|
+
application/xml
|
186
|
+
text/coffeescript
|
187
|
+
text/css
|
188
|
+
text/html
|
189
|
+
text/plain
|
190
|
+
text/sass
|
191
|
+
text/scss
|
192
|
+
text/yaml
|
193
|
+
), 'application/\2+ruby', '.erb', ERBProcessor)
|
194
|
+
|
195
|
+
register_mime_type 'application/html+ruby', extensions: ['.html.erb', '.erb', '.rhtml'], charset: :html
|
196
|
+
register_mime_type 'application/xml+ruby', extensions: ['.xml.erb', '.rxml']
|
197
|
+
|
151
198
|
|
152
199
|
register_dependency_resolver 'environment-version' do |env|
|
153
200
|
env.version
|
@@ -165,5 +212,3 @@ module Sprockets
|
|
165
212
|
depend_on 'environment-version'
|
166
213
|
depend_on 'environment-paths'
|
167
214
|
end
|
168
|
-
|
169
|
-
require 'sprockets/legacy'
|