sprockets 4.0.0.beta2 → 4.0.0.beta3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/README.md +25 -13
  4. data/lib/rake/sprocketstask.rb +1 -0
  5. data/lib/sprockets.rb +4 -2
  6. data/lib/sprockets/asset.rb +1 -0
  7. data/lib/sprockets/autoload.rb +1 -0
  8. data/lib/sprockets/autoload/babel.rb +1 -0
  9. data/lib/sprockets/autoload/closure.rb +1 -0
  10. data/lib/sprockets/autoload/coffee_script.rb +1 -0
  11. data/lib/sprockets/autoload/eco.rb +1 -0
  12. data/lib/sprockets/autoload/ejs.rb +1 -0
  13. data/lib/sprockets/autoload/jsminc.rb +1 -0
  14. data/lib/sprockets/autoload/sass.rb +1 -0
  15. data/lib/sprockets/autoload/sassc.rb +1 -0
  16. data/lib/sprockets/autoload/uglifier.rb +1 -0
  17. data/lib/sprockets/autoload/yui.rb +1 -0
  18. data/lib/sprockets/babel_processor.rb +3 -1
  19. data/lib/sprockets/base.rb +3 -2
  20. data/lib/sprockets/bower.rb +1 -0
  21. data/lib/sprockets/bundle.rb +1 -0
  22. data/lib/sprockets/cache.rb +4 -1
  23. data/lib/sprockets/cache/file_store.rb +1 -0
  24. data/lib/sprockets/cache/memory_store.rb +1 -0
  25. data/lib/sprockets/cache/null_store.rb +1 -0
  26. data/lib/sprockets/cached_environment.rb +4 -3
  27. data/lib/sprockets/closure_compressor.rb +3 -1
  28. data/lib/sprockets/coffee_script_processor.rb +2 -1
  29. data/lib/sprockets/compressing.rb +19 -0
  30. data/lib/sprockets/configuration.rb +1 -0
  31. data/lib/sprockets/context.rb +3 -2
  32. data/lib/sprockets/dependencies.rb +1 -0
  33. data/lib/sprockets/digest_utils.rb +64 -41
  34. data/lib/sprockets/directive_processor.rb +15 -10
  35. data/lib/sprockets/eco_processor.rb +1 -0
  36. data/lib/sprockets/ejs_processor.rb +1 -0
  37. data/lib/sprockets/encoding_utils.rb +1 -0
  38. data/lib/sprockets/environment.rb +3 -2
  39. data/lib/sprockets/erb_processor.rb +1 -0
  40. data/lib/sprockets/errors.rb +1 -0
  41. data/lib/sprockets/file_reader.rb +1 -0
  42. data/lib/sprockets/http_utils.rb +1 -0
  43. data/lib/sprockets/jsminc_compressor.rb +1 -0
  44. data/lib/sprockets/jst_processor.rb +1 -0
  45. data/lib/sprockets/loader.rb +2 -1
  46. data/lib/sprockets/manifest.rb +1 -0
  47. data/lib/sprockets/manifest_utils.rb +1 -0
  48. data/lib/sprockets/mime.rb +1 -0
  49. data/lib/sprockets/path_dependency_utils.rb +1 -0
  50. data/lib/sprockets/path_digest_utils.rb +1 -0
  51. data/lib/sprockets/path_utils.rb +18 -13
  52. data/lib/sprockets/paths.rb +1 -0
  53. data/lib/sprockets/preprocessors/default_source_map.rb +1 -0
  54. data/lib/sprockets/processing.rb +1 -0
  55. data/lib/sprockets/processor_utils.rb +15 -3
  56. data/lib/sprockets/resolve.rb +2 -1
  57. data/lib/sprockets/sass_cache_store.rb +1 -0
  58. data/lib/sprockets/sass_compressor.rb +1 -0
  59. data/lib/sprockets/sass_functions.rb +1 -0
  60. data/lib/sprockets/sass_importer.rb +1 -0
  61. data/lib/sprockets/sass_processor.rb +15 -3
  62. data/lib/sprockets/sassc_compressor.rb +4 -1
  63. data/lib/sprockets/sassc_processor.rb +5 -0
  64. data/lib/sprockets/server.rb +2 -1
  65. data/lib/sprockets/source_map_comment_processor.rb +1 -0
  66. data/lib/sprockets/source_map_processor.rb +9 -2
  67. data/lib/sprockets/source_map_utils.rb +1 -0
  68. data/lib/sprockets/transformers.rb +1 -0
  69. data/lib/sprockets/uglifier_compressor.rb +9 -12
  70. data/lib/sprockets/unloaded_asset.rb +1 -0
  71. data/lib/sprockets/uri_tar.rb +3 -4
  72. data/lib/sprockets/uri_utils.rb +2 -1
  73. data/lib/sprockets/utils.rb +25 -11
  74. data/lib/sprockets/utils/gzip.rb +1 -0
  75. data/lib/sprockets/version.rb +2 -1
  76. data/lib/sprockets/yui_compressor.rb +1 -0
  77. metadata +2 -2
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'set'
2
3
  require 'sprockets/http_utils'
3
4
  require 'sprockets/path_dependency_utils'
@@ -46,7 +47,7 @@ module Sprockets
46
47
  uri, deps = resolve(path, **kargs)
47
48
 
48
49
  unless uri
49
- message = "couldn't find file '#{path}'"
50
+ message = String.new("couldn't find file '#{path}'")
50
51
 
51
52
  if relative_path?(path) && kargs[:base_path]
52
53
  load_path, _ = paths_split(config[:paths], kargs[:base_path])
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'sass'
2
3
 
3
4
  module Sprockets
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'sprockets/autoload'
2
3
  require 'sprockets/digest_utils'
3
4
  require 'sprockets/source_map_utils'
@@ -1,2 +1,3 @@
1
+ # frozen_string_literal: true
1
2
  # Deprecated: Require sprockets/sass_processor instead
2
3
  require 'sprockets/sass_processor'
@@ -1,2 +1,3 @@
1
+ # frozen_string_literal: true
1
2
  # Deprecated: Require sprockets/sass_processor instead
2
3
  require 'sprockets/sass_processor'
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'rack/utils'
2
3
  require 'sprockets/autoload'
3
4
  require 'sprockets/source_map_utils'
@@ -81,7 +82,10 @@ module Sprockets
81
82
 
82
83
  map = SourceMapUtils.combine_source_maps(
83
84
  input[:metadata][:map],
84
- SourceMapUtils.decode_json_source_map(map.to_json(css_uri: '', type: :inline))["mappings"]
85
+ expand_map_sources(
86
+ SourceMapUtils.decode_json_source_map(map.to_json(css_uri: '', type: :inline))["mappings"],
87
+ input[:environment]
88
+ )
85
89
  )
86
90
 
87
91
  # Track all imported files
@@ -94,6 +98,16 @@ module Sprockets
94
98
  context.metadata.merge(data: css, sass_dependencies: sass_dependencies, map: map)
95
99
  end
96
100
 
101
+ private
102
+
103
+ def expand_map_sources(mapping, env)
104
+ mapping.each do |map|
105
+ uri, _ = env.resolve!(map[:source], pipeline: :source)
106
+ source_path = env.load(uri).digest_path
107
+ map[:source] = source_path
108
+ end
109
+ end
110
+
97
111
  # Public: Build the cache store to be used by the Sass engine.
98
112
  #
99
113
  # input - the input hash.
@@ -104,7 +118,6 @@ module Sprockets
104
118
  def build_cache_store(input, version)
105
119
  CacheStore.new(input[:cache], version)
106
120
  end
107
- private :build_cache_store
108
121
 
109
122
  def merge_options(options)
110
123
  defaults = @sass_config.dup
@@ -116,7 +129,6 @@ module Sprockets
116
129
  options.merge!(defaults)
117
130
  options
118
131
  end
119
- private :merge_options
120
132
 
121
133
  # Public: Functions injected into Sass context during Sprockets evaluation.
122
134
  #
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'sprockets/autoload'
2
3
  require 'sprockets/sass_compressor'
3
4
  require 'base64'
@@ -14,7 +15,9 @@ module Sprockets
14
15
  end
15
16
 
16
17
  def call(input)
17
- data = Autoload::SassC::Engine.new(input[:data], @options.merge(filename: 'filename')).render
18
+ # SassC requires the template to be modifiable
19
+ input_data = input[:data].frozen? ? input[:data].dup : input[:data]
20
+ data = Autoload::SassC::Engine.new(input_data, @options.merge(filename: 'filename')).render
18
21
 
19
22
  match_data = data.match(/(.*)\n\/\*# sourceMappingURL=data:application\/json;base64,(.+) \*\//m)
20
23
  css, map = match_data[1], Base64.decode64(match_data[2])
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'sprockets/sass_processor'
2
3
  require 'base64'
3
4
 
@@ -33,6 +34,10 @@ module Sprockets
33
34
  change_source(SourceMapUtils.decode_json_source_map(map)["mappings"], input[:source_path])
34
35
  )
35
36
 
37
+ engine.dependencies.each do |dependency|
38
+ context.metadata[:dependencies] << URIUtils.build_file_digest_uri(dependency.filename)
39
+ end
40
+
36
41
  context.metadata.merge(data: css, map: map)
37
42
  end
38
43
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'set'
2
3
  require 'time'
3
4
  require 'rack/utils'
@@ -234,7 +235,7 @@ module Sprockets
234
235
  headers = {}
235
236
 
236
237
  # Set caching headers
237
- headers["Cache-Control"] = "public"
238
+ headers["Cache-Control"] = String.new("public")
238
239
  headers["ETag"] = %("#{etag}")
239
240
 
240
241
  # If the request url contains a fingerprint, set a long
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Sprockets
2
3
  class SourceMapCommentProcessor
3
4
  def self.call(input)
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'set'
2
3
 
3
4
  module Sprockets
@@ -20,6 +21,12 @@ module Sprockets
20
21
  asset = env.load(uri)
21
22
  map = asset.metadata[:map] || []
22
23
 
24
+ # TODO: Because of the default piplene hack we have to apply dependencies
25
+ # from compiled asset to the source map, otherwise the source map cache
26
+ # will never detect the changes from directives
27
+ dependencies = Set.new(input[:metadata][:dependencies])
28
+ dependencies.merge(asset.metadata[:dependencies])
29
+
23
30
  map.map { |m| m[:source] }.uniq.compact.each do |source|
24
31
  # TODO: Resolve should expect fingerprints
25
32
  fingerprint = source[/-([0-9a-f]{7,128})\.[^.]+\z/, 1]
@@ -29,12 +36,12 @@ module Sprockets
29
36
  path = source
30
37
  end
31
38
  uri, _ = env.resolve!(path)
32
- links << env.load(uri).uri
39
+ links << uri
33
40
  end
34
41
 
35
42
  json = env.encode_json_source_map(map, filename: asset.logical_path)
36
43
 
37
- { data: json, links: links }
44
+ { data: json, links: links, dependencies: dependencies }
38
45
  end
39
46
  end
40
47
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'json'
2
3
 
3
4
  module Sprockets
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'sprockets/http_utils'
2
3
  require 'sprockets/processor_utils'
3
4
  require 'sprockets/utils'
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'sprockets/autoload'
2
3
  require 'sprockets/digest_utils'
3
4
  require 'sprockets/source_map_utils'
@@ -16,7 +17,7 @@ module Sprockets
16
17
  # Sprockets::UglifierCompressor.new(comments: :copyright)
17
18
  #
18
19
  class UglifierCompressor
19
- VERSION = '2'
20
+ VERSION = '3'
20
21
 
21
22
  # Public: Return singleton instance with default options.
22
23
  #
@@ -36,27 +37,23 @@ module Sprockets
36
37
  attr_reader :cache_key
37
38
 
38
39
  def initialize(options = {})
39
- # Feature detect Uglifier 2.0 option support
40
- if Autoload::Uglifier::DEFAULTS[:copyright]
41
- # Uglifier < 2.x
42
- options[:copyright] ||= false
43
- else
44
- # Uglifier >= 2.x
45
- options[:copyright] ||= :none
46
- end
40
+ options[:comments] ||= :none
47
41
 
48
- @uglifier = Autoload::Uglifier.new(options)
42
+ @options = options
49
43
  @cache_key = "#{self.class.name}:#{Autoload::Uglifier::VERSION}:#{VERSION}:#{DigestUtils.digest(options)}".freeze
50
44
  end
51
45
 
52
46
  def call(input)
53
- js, map = @uglifier.compile_with_map(input[:data])
47
+ if Autoload::Uglifier::VERSION.to_i < 2
48
+ raise "uglifier 1.x is no longer supported, please upgrade to 2.x"
49
+ end
50
+ @uglifier ||= Autoload::Uglifier.new(@options)
54
51
 
52
+ js, map = @uglifier.compile_with_map(input[:data])
55
53
  map = SourceMapUtils.combine_source_maps(
56
54
  input[:metadata][:map],
57
55
  SourceMapUtils.decode_json_source_map(map)["mappings"]
58
56
  )
59
-
60
57
  { data: js, map: map }
61
58
  end
62
59
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'sprockets/uri_utils'
2
3
  require 'sprockets/uri_tar'
3
4
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'sprockets/path_utils'
2
3
 
3
4
  module Sprockets
@@ -14,10 +15,8 @@ module Sprockets
14
15
  @env = env
15
16
  uri = uri.to_s
16
17
  if uri.include?("://".freeze)
17
- uri_array = uri.split("://".freeze)
18
- @scheme = uri_array.shift
19
- @scheme << "://".freeze
20
- @path = uri_array.join("".freeze)
18
+ @scheme, _, @path = uri.partition("://".freeze)
19
+ @scheme << "://".freeze
21
20
  else
22
21
  @scheme = "".freeze
23
22
  @path = uri
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'uri'
2
3
 
3
4
  module Sprockets
@@ -57,7 +58,7 @@ module Sprockets
57
58
  #
58
59
  # Returns String.
59
60
  def join_file_uri(scheme, host, path, query)
60
- str = "#{scheme}://"
61
+ str = String.new("#{scheme}://")
61
62
  str << host if host
62
63
  path = "/#{path}" unless path.start_with?("/".freeze)
63
64
  str << URI::Generic::DEFAULT_PARSER.escape(path)
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'set'
2
3
 
3
4
  module Sprockets
@@ -75,16 +76,19 @@ module Sprockets
75
76
  def string_end_with_semicolon?(str)
76
77
  i = str.size - 1
77
78
  while i >= 0
78
- c = str[i]
79
+ c = str[i].ord
79
80
  i -= 1
80
- if c == "\n" || c == " " || c == "\t"
81
- next
82
- elsif c != ";"
83
- return false
84
- else
85
- return true
81
+
82
+ # Need to compare against the ordinals because the string can be UTF_8 or UTF_32LE encoded
83
+ # 0x0A == "\n"
84
+ # 0x20 == " "
85
+ # 0x09 == "\t"
86
+ # 0x3B == ";"
87
+ unless c == 0x0A || c == 0x20 || c == 0x09
88
+ return c === 0x3B
86
89
  end
87
90
  end
91
+
88
92
  true
89
93
  end
90
94
 
@@ -96,11 +100,21 @@ module Sprockets
96
100
  #
97
101
  # Returns buf String.
98
102
  def concat_javascript_sources(buf, source)
99
- if buf.bytesize > 0
100
- buf << ";" unless string_end_with_semicolon?(buf)
101
- buf << "\n" unless buf.end_with?("\n")
103
+ if source.bytesize > 0
104
+ buf << source
105
+
106
+ # If the source contains non-ASCII characters, indexing on it becomes O(N).
107
+ # 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)
108
+ source = source.encode(Encoding::UTF_32LE) unless source.ascii_only?
109
+
110
+ if !string_end_with_semicolon?(source)
111
+ buf << ";\n"
112
+ elsif source[source.size - 1].ord != 0x0A
113
+ buf << "\n"
114
+ end
102
115
  end
103
- buf << source
116
+
117
+ buf
104
118
  end
105
119
 
106
120
  # Internal: Inject into target module for the duration of the block.
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Sprockets
2
3
  module Utils
3
4
  class Gzip
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Sprockets
2
- VERSION = "4.0.0.beta2"
3
+ VERSION = "4.0.0.beta3"
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: 4.0.0.beta2
4
+ version: 4.0.0.beta3
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: 2016-02-23 00:00:00.000000000 Z
12
+ date: 2016-08-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack