sprockets 4.0.0.beta5 → 4.0.0.beta6
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 +5 -0
- data/lib/sprockets.rb +7 -5
- data/lib/sprockets/cache.rb +1 -1
- data/lib/sprockets/cache/file_store.rb +5 -2
- data/lib/sprockets/manifest.rb +2 -1
- data/lib/sprockets/preprocessors/default_source_map.rb +6 -2
- data/lib/sprockets/server.rb +13 -0
- data/lib/sprockets/source_map_comment_processor.rb +1 -1
- data/lib/sprockets/source_map_processor.rb +2 -2
- data/lib/sprockets/source_map_utils.rb +10 -7
- data/lib/sprockets/utils.rb +21 -20
- data/lib/sprockets/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4d2caeaadba82b93fec24d508ff3dc84fa5f48db942cc968c732d5f2eb0fd0c0
|
4
|
+
data.tar.gz: 5cc1d606e6ded78d675802867b00978e45a881642dd7cf3c6fcb8e2e2da8c799
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dbe7fe89fb3d28046ea2ec42bd2f65d955d31752f713adc27f29049d206067dabaa0ed4e8021597cf6a6ef6969d65f9c392abd407091ea9544e53c11cec0fbcd
|
7
|
+
data.tar.gz: '08ead7193ee03944662ab0f748282b339a083f04fb77179e1232b06feacdc4565ec9fc7f7d9a6815ac29eaca87c9b40e985fc144798a01dde4ee9a37df3c2c92'
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,11 @@ Get upgrade notes from Sprockets 3.x to 4.x at https://github.com/rails/sprocket
|
|
4
4
|
|
5
5
|
## Master
|
6
6
|
|
7
|
+
## 4.0.0.beta6
|
8
|
+
|
9
|
+
- Fix source map line offsets [#515]
|
10
|
+
- Return a `400 Bad Request` when the path encoding is invalid. [#514]
|
11
|
+
|
7
12
|
## 4.0.0.beta5
|
8
13
|
|
9
14
|
- Reduce string allocations
|
data/lib/sprockets.rb
CHANGED
@@ -107,10 +107,6 @@ module Sprockets
|
|
107
107
|
[SourceMapCommentProcessor]
|
108
108
|
end
|
109
109
|
|
110
|
-
require 'sprockets/preprocessors/default_source_map'
|
111
|
-
register_preprocessor 'text/css', Preprocessors::DefaultSourceMap.new
|
112
|
-
register_preprocessor 'application/javascript', Preprocessors::DefaultSourceMap.new
|
113
|
-
|
114
110
|
require 'sprockets/directive_processor'
|
115
111
|
register_preprocessor 'text/css', DirectiveProcessor.new(comments: ["//", ["/*", "*/"]])
|
116
112
|
register_preprocessor 'application/javascript', DirectiveProcessor.new(comments: ["//", ["/*", "*/"]])
|
@@ -123,7 +119,6 @@ module Sprockets
|
|
123
119
|
register_bundle_metadata_reducer 'application/javascript', :data, proc { String.new("") }, Utils.method(:concat_javascript_sources)
|
124
120
|
register_bundle_metadata_reducer '*/*', :links, :+
|
125
121
|
register_bundle_metadata_reducer '*/*', :sources, proc { [] }, :+
|
126
|
-
register_bundle_metadata_reducer '*/*', :map, proc { |input| { "version" => 3, "file" => PathUtils.split_subpath(input[:load_path], input[:filename]), "sections" => [] } }, SourceMapUtils.method(:concat_source_maps)
|
127
122
|
|
128
123
|
require 'sprockets/closure_compressor'
|
129
124
|
require 'sprockets/sass_compressor'
|
@@ -219,4 +214,11 @@ module Sprockets
|
|
219
214
|
|
220
215
|
depend_on 'environment-version'
|
221
216
|
depend_on 'environment-paths'
|
217
|
+
|
218
|
+
require 'sprockets/preprocessors/default_source_map'
|
219
|
+
register_preprocessor 'text/css', Preprocessors::DefaultSourceMap.new
|
220
|
+
register_preprocessor 'application/javascript', Preprocessors::DefaultSourceMap.new
|
221
|
+
|
222
|
+
register_bundle_metadata_reducer 'text/css', :map, proc { |input| { "version" => 3, "file" => PathUtils.split_subpath(input[:load_path], input[:filename]), "sections" => [] } }, SourceMapUtils.method(:concat_source_maps)
|
223
|
+
register_bundle_metadata_reducer 'application/javascript', :map, proc { |input| { "version" => 3, "file" => PathUtils.split_subpath(input[:load_path], input[:filename]), "sections" => [] } }, SourceMapUtils.method(:concat_source_maps)
|
222
224
|
end
|
data/lib/sprockets/cache.rb
CHANGED
@@ -51,7 +51,7 @@ module Sprockets
|
|
51
51
|
# Internal: Cache key version for this class. Rarely should have to change
|
52
52
|
# unless the cache format radically changes. Will be bump on major version
|
53
53
|
# releases though.
|
54
|
-
VERSION = '4.0'
|
54
|
+
VERSION = '4.0.0'
|
55
55
|
|
56
56
|
def self.default_logger
|
57
57
|
logger = Logger.new($stderr)
|
@@ -22,6 +22,7 @@ module Sprockets
|
|
22
22
|
DEFAULT_MAX_SIZE = 25 * 1024 * 1024
|
23
23
|
EXCLUDED_DIRS = ['.', '..'].freeze
|
24
24
|
GITKEEP_FILES = ['.gitkeep', '.keep'].freeze
|
25
|
+
|
25
26
|
# Internal: Default standard error fatal logger.
|
26
27
|
#
|
27
28
|
# Returns a Logger.
|
@@ -34,8 +35,10 @@ module Sprockets
|
|
34
35
|
# Public: Initialize the cache store.
|
35
36
|
#
|
36
37
|
# root - A String path to a directory to persist cached values to.
|
37
|
-
# max_size - A Integer of the maximum
|
38
|
-
# (default:
|
38
|
+
# max_size - A Integer of the maximum size the store will hold (in bytes).
|
39
|
+
# (default: 25MB).
|
40
|
+
# logger - The logger to which some info will be printed.
|
41
|
+
# (default logger level is FATAL and won't output anything).
|
39
42
|
def initialize(root, max_size = DEFAULT_MAX_SIZE, logger = self.class.default_logger)
|
40
43
|
@root = root
|
41
44
|
@max_size = max_size
|
data/lib/sprockets/manifest.rb
CHANGED
@@ -13,7 +13,7 @@ module Sprockets
|
|
13
13
|
map = input[:metadata][:map]
|
14
14
|
filename = input[:filename]
|
15
15
|
load_path = input[:load_path]
|
16
|
-
lines = input[:data].lines.
|
16
|
+
lines = input[:data].lines.length
|
17
17
|
basename = File.basename(filename)
|
18
18
|
mime_exts = input[:environment].config[:mime_exts]
|
19
19
|
pipeline_exts = input[:environment].config[:pipeline_exts]
|
@@ -25,10 +25,14 @@ module Sprockets
|
|
25
25
|
"sources" => [PathUtils.set_pipeline(basename, mime_exts, pipeline_exts, :source)],
|
26
26
|
"names" => []
|
27
27
|
}
|
28
|
+
else
|
29
|
+
result[:map] = map
|
28
30
|
end
|
31
|
+
|
32
|
+
result[:map]["x_sprockets_linecount"] = lines
|
29
33
|
return result
|
30
34
|
end
|
31
|
-
|
35
|
+
|
32
36
|
private
|
33
37
|
|
34
38
|
def default_mappings(lines)
|
data/lib/sprockets/server.rb
CHANGED
@@ -37,6 +37,10 @@ module Sprockets
|
|
37
37
|
# Extract the path from everything after the leading slash
|
38
38
|
path = Rack::Utils.unescape(env['PATH_INFO'].to_s.sub(/^\//, ''))
|
39
39
|
|
40
|
+
unless path.valid_encoding?
|
41
|
+
return bad_request_response(env)
|
42
|
+
end
|
43
|
+
|
40
44
|
# Strip fingerprint
|
41
45
|
if fingerprint = path_fingerprint(path)
|
42
46
|
path = path.sub("-#{fingerprint}", '')
|
@@ -131,6 +135,15 @@ module Sprockets
|
|
131
135
|
[ 304, cache_headers(env, etag), [] ]
|
132
136
|
end
|
133
137
|
|
138
|
+
# Returns a 400 Forbidden response tuple
|
139
|
+
def bad_request_response(env)
|
140
|
+
if head_request?(env)
|
141
|
+
[ 400, { "Content-Type" => "text/plain", "Content-Length" => "0" }, [] ]
|
142
|
+
else
|
143
|
+
[ 400, { "Content-Type" => "text/plain", "Content-Length" => "11" }, [ "Bad Request" ] ]
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
134
147
|
# Returns a 403 Forbidden response tuple
|
135
148
|
def forbidden_response(env)
|
136
149
|
if head_request?(env)
|
@@ -29,7 +29,7 @@ module Sprockets
|
|
29
29
|
path = PathUtils.relative_path_from(PathUtils.split_subpath(input[:load_path], uri), map.digest_path)
|
30
30
|
|
31
31
|
asset.metadata.merge(
|
32
|
-
data: asset.source + (comment % path),
|
32
|
+
data: asset.source + (comment % path) + "\n",
|
33
33
|
links: asset.links + [asset.uri, map.uri]
|
34
34
|
)
|
35
35
|
end
|
@@ -6,9 +6,9 @@ module Sprockets
|
|
6
6
|
def self.original_content_type(source_map_content_type, error_when_not_found: true)
|
7
7
|
case source_map_content_type
|
8
8
|
when "application/js-sourcemap+json"
|
9
|
-
|
9
|
+
"application/javascript"
|
10
10
|
when "application/css-sourcemap+json"
|
11
|
-
|
11
|
+
"text/css"
|
12
12
|
else
|
13
13
|
fail(source_map_content_type) if error_when_not_found
|
14
14
|
source_map_content_type
|
@@ -48,7 +48,7 @@ module Sprockets
|
|
48
48
|
"sources" => map["sources"].map do |source|
|
49
49
|
source = URIUtils.split_file_uri(source)[2] if source.start_with? "file://"
|
50
50
|
source = PathUtils.join(File.dirname(filename), source) unless PathUtils.absolute_path?(source)
|
51
|
-
_, source = PathUtils.paths_split(load_paths, source)
|
51
|
+
_, source = PathUtils.paths_split(load_paths, source)
|
52
52
|
source = PathUtils.relative_path_from(file, source)
|
53
53
|
PathUtils.set_pipeline(source, mime_exts, pipeline_exts, :source)
|
54
54
|
end,
|
@@ -72,13 +72,16 @@ module Sprockets
|
|
72
72
|
# Returns a new source map hash.
|
73
73
|
def concat_source_maps(a, b)
|
74
74
|
return a || b unless a && b
|
75
|
-
a
|
75
|
+
a = make_index_map(a)
|
76
|
+
b = make_index_map(b)
|
76
77
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
offset
|
81
|
-
|
78
|
+
offset = 0
|
79
|
+
if a["sections"].count != 0 && !a["sections"].last["map"]["mappings"].empty?
|
80
|
+
last_line_count = a["sections"].last["map"].delete("x_sprockets_linecount")
|
81
|
+
offset += last_line_count
|
82
|
+
|
83
|
+
last_offset = a["sections"].last["offset"]["line"]
|
84
|
+
offset += last_offset
|
82
85
|
end
|
83
86
|
|
84
87
|
a["sections"] += b["sections"].map do |section|
|
data/lib/sprockets/utils.rb
CHANGED
@@ -68,6 +68,9 @@ module Sprockets
|
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
|
+
WHITESPACE_ORDINALS = {0x0A => "\n", 0x20 => " ", 0x09 => "\t"}
|
72
|
+
private_constant :WHITESPACE_ORDINALS
|
73
|
+
|
71
74
|
# Internal: Check if string has a trailing semicolon.
|
72
75
|
#
|
73
76
|
# str - String
|
@@ -79,14 +82,9 @@ module Sprockets
|
|
79
82
|
c = str[i].ord
|
80
83
|
i -= 1
|
81
84
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
# 0x09 == "\t"
|
86
|
-
# 0x3B == ";"
|
87
|
-
unless c == 0x0A || c == 0x20 || c == 0x09
|
88
|
-
return c === 0x3B
|
89
|
-
end
|
85
|
+
next if WHITESPACE_ORDINALS[c]
|
86
|
+
|
87
|
+
return c === 0x3B
|
90
88
|
end
|
91
89
|
|
92
90
|
true
|
@@ -100,18 +98,21 @@ module Sprockets
|
|
100
98
|
#
|
101
99
|
# Returns buf String.
|
102
100
|
def concat_javascript_sources(buf, source)
|
103
|
-
if source.bytesize
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
101
|
+
return buf if source.bytesize <= 0
|
102
|
+
|
103
|
+
buf << source
|
104
|
+
# If the source contains non-ASCII characters, indexing on it becomes O(N).
|
105
|
+
# 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)
|
106
|
+
source = source.encode(Encoding::UTF_32LE) unless source.ascii_only?
|
107
|
+
return buf if string_end_with_semicolon?(source)
|
108
|
+
|
109
|
+
# If the last character in the string was whitespace,
|
110
|
+
# such as a newline, then we want to put the semicolon
|
111
|
+
# before the whitespace. Otherwise append a semicolon.
|
112
|
+
if whitespace = WHITESPACE_ORDINALS[source[-1].ord]
|
113
|
+
buf[-1] = ";#{whitespace}"
|
114
|
+
else
|
115
|
+
buf << ";"
|
115
116
|
end
|
116
117
|
|
117
118
|
buf
|
data/lib/sprockets/version.rb
CHANGED
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: 4.0.0.
|
4
|
+
version: 4.0.0.beta6
|
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: 2017-
|
12
|
+
date: 2017-11-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|
@@ -402,7 +402,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
402
402
|
version: 1.3.1
|
403
403
|
requirements: []
|
404
404
|
rubyforge_project: sprockets
|
405
|
-
rubygems_version: 2.6.
|
405
|
+
rubygems_version: 2.6.14
|
406
406
|
signing_key:
|
407
407
|
specification_version: 4
|
408
408
|
summary: Rack-based asset packaging system
|