sprockets-rails 3.2.2 → 3.5.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 801a6cbc13340fb4c74ecf9b7aa2d5c6c563605e3462512e0073f268e269fe8d
4
- data.tar.gz: facde95b73f355f987059128c7f6d852b5b8845d26f2eca5214b4fc37ded168d
3
+ metadata.gz: a51f06b8c5ad01f10611895d361f493f20793676b3a04182f5bea67b2f5a3109
4
+ data.tar.gz: 0ad6746d0b030fb467c6f24c343d2b6eb2b372a89f0cf232b3b97825ab103a2d
5
5
  SHA512:
6
- metadata.gz: 7f6c2f179ba5b3294ad0b49357c4a7a50c207f221d6cbb5d9cad406b1143ee5ff9d5a71897f3f6a2bd9709eda8d5e5bad5380e4defa1e135700cc3edd9669749
7
- data.tar.gz: cbd34277b1e2e89c5ddded1b616ce179a269e384f1781b7032972c966737803e725440f5a23951383adf6b4a8705b50a307eb94a2bd6055ab42dcfc505aa468c
6
+ metadata.gz: 534796ce9f7e854c034119104a45c2112f3a72f606c6af5eb73b7d3bcdf76c00c91e65f632775b22320ac39c218a369c950da583269ec7023012b8a2f89e3181
7
+ data.tar.gz: bb0a83b01f58aa870429fa8be470343ee13e8c18aeb50312202724cc773eb52531ec74baa7b4a023a4a73c62897fbdc2de448db3aaf39fc58f65ffc5771d4a2a
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Sprockets Rails
2
2
 
3
- Provides Sprockets implementation for Rails 4.x (and beyond) Asset Pipeline.
3
+ Provides [Sprockets](https://github.com/rails/sprockets) implementation for Rails 4.x (and beyond) Asset Pipeline.
4
4
 
5
5
 
6
6
  ## Installation
@@ -86,7 +86,7 @@ When enabled, fingerprints will be added to asset filenames.
86
86
 
87
87
  **`config.assets.debug`**
88
88
 
89
- Enable expanded asset debugging mode. Individual files will be served to make referencing filenames in the web console easier. This feature will eventually be deprecated and replaced by Source Maps in Sprockets 3.x.
89
+ Enable asset debugging mode. A source map will be included with each asset when this is true.
90
90
 
91
91
  **`config.assets.compile`**
92
92
 
@@ -108,6 +108,10 @@ config.assets.configure do |env|
108
108
  end
109
109
  ```
110
110
 
111
+ **`config.assets.resolve_assets_in_css_urls`**
112
+
113
+ When this option is enabled, sprockets-rails will register a CSS postprocessor to resolve assets referenced in [`url()`](https://developer.mozilla.org/en-US/docs/Web/CSS/url()) function calls and replace them with the digested paths. Defaults to `true`.
114
+
111
115
  **`config.assets.resolve_with`**
112
116
 
113
117
  A list of `:environment` and `:manifest` symbols that defines the order that
@@ -196,5 +200,4 @@ Sprockets Rails is released under the [MIT License](MIT-LICENSE).
196
200
 
197
201
  ## Code Status
198
202
 
199
- * [![Travis CI](https://travis-ci.org/rails/sprockets-rails.svg?branch=master)](http://travis-ci.org/rails/sprockets-rails)
200
203
  * [![Gem Version](https://badge.fury.io/rb/sprockets-rails.svg)](http://badge.fury.io/rb/sprockets-rails)
@@ -0,0 +1,17 @@
1
+ module Sprockets
2
+ module Rails
3
+ # Resolve assets referenced in CSS `url()` calls and replace them with the digested paths
4
+ class AssetUrlProcessor
5
+ REGEX = /url\(\s*["']?(?!(?:\#|data|http))(?<relativeToCurrentDir>\.\/)?(?<path>[^"'\s)]+)\s*["']?\)/
6
+ def self.call(input)
7
+ context = input[:environment].context_class.new(input)
8
+ data = input[:data].gsub(REGEX) do |_match|
9
+ path = Regexp.last_match[:path]
10
+ "url(#{context.asset_path(path)})"
11
+ end
12
+
13
+ context.metadata.merge(data: data)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -89,8 +89,7 @@ module Sprockets
89
89
  message << "To bypass the asset pipeline and preserve this behavior,\n"
90
90
  message << "use the `skip_pipeline: true` option.\n"
91
91
 
92
- call_stack = Kernel.respond_to?(:caller_locations) && ::Rails::VERSION::MAJOR >= 5 ? caller_locations : caller
93
- ActiveSupport::Deprecation.warn(message, call_stack)
92
+ Sprockets::Rails.deprecator.warn(message, caller_locations)
94
93
  end
95
94
  super
96
95
  end
@@ -369,7 +368,7 @@ module Sprockets
369
368
  end
370
369
 
371
370
  def raise_unless_precompiled_asset(path)
372
- raise Helper::AssetNotPrecompiled.new(path) if @check_precompiled_asset && !precompiled?(path)
371
+ raise Helper::AssetNotPrecompiledError.new(path) if @check_precompiled_asset && !precompiled?(path)
373
372
  end
374
373
  end
375
374
  end
@@ -1,5 +1,7 @@
1
1
  module Sprockets
2
2
  module Rails
3
+ class LoggerSilenceError < StandardError; end
4
+
3
5
  class QuietAssets
4
6
  def initialize(app)
5
7
  @app = app
@@ -8,11 +10,23 @@ module Sprockets
8
10
 
9
11
  def call(env)
10
12
  if env['PATH_INFO'] =~ @assets_regex
13
+ raise_logger_silence_error unless ::Rails.logger.respond_to?(:silence)
14
+
11
15
  ::Rails.logger.silence { @app.call(env) }
12
16
  else
13
17
  @app.call(env)
14
18
  end
15
19
  end
20
+
21
+ private
22
+ def raise_logger_silence_error
23
+ error = "You have enabled `config.assets.quiet`, but your `Rails.logger`\n"
24
+ error << "does not use the `LoggerSilence` module.\n\n"
25
+ error << "Please use a compatible logger such as `ActiveSupport::Logger`\n"
26
+ error << "to take advantage of quiet asset logging.\n\n"
27
+
28
+ raise LoggerSilenceError, error
29
+ end
16
30
  end
17
31
  end
18
32
  end
@@ -1,7 +1,6 @@
1
1
  module Sprockets
2
2
  module Rails
3
3
  module RouteWrapper
4
-
5
4
  def internal_assets_path?
6
5
  path =~ %r{\A#{self.class.assets_prefix}\z}
7
6
  end
@@ -9,15 +8,6 @@ module Sprockets
9
8
  def internal?
10
9
  super || internal_assets_path?
11
10
  end
12
-
13
- def self.included(klass)
14
- klass.class_eval do
15
- def internal_with_sprockets?
16
- internal_without_sprockets? || internal_assets_path?
17
- end
18
- alias_method_chain :internal?, :sprockets
19
- end
20
- end
21
11
  end
22
12
  end
23
13
  end
@@ -0,0 +1,54 @@
1
+ module Sprockets
2
+ module Rails
3
+ # Rewrites source mapping urls with the digested paths and protect against semicolon appending with a dummy comment line
4
+ class SourcemappingUrlProcessor
5
+ REGEX = /\/\/# sourceMappingURL=(.*\.map)/
6
+
7
+ class << self
8
+ def call(input)
9
+ env = input[:environment]
10
+ context = env.context_class.new(input)
11
+ data = input[:data].gsub(REGEX) do |_match|
12
+ sourcemap_logical_path = combine_sourcemap_logical_path(sourcefile: input[:name], sourcemap: $1)
13
+
14
+ begin
15
+ resolved_sourcemap_comment(sourcemap_logical_path, context: context)
16
+ rescue Sprockets::FileNotFound
17
+ removed_sourcemap_comment(sourcemap_logical_path, filename: input[:filename], env: env)
18
+ end
19
+ end
20
+
21
+ { data: data }
22
+ end
23
+
24
+ private
25
+ def combine_sourcemap_logical_path(sourcefile:, sourcemap:)
26
+ if (parts = sourcefile.split("/")).many?
27
+ parts[0..-2].append(sourcemap).join("/")
28
+ else
29
+ sourcemap
30
+ end
31
+ end
32
+
33
+ def resolved_sourcemap_comment(sourcemap_logical_path, context:)
34
+ "//# sourceMappingURL=#{sourcemap_asset_path(sourcemap_logical_path, context: context)}\n//!\n"
35
+ end
36
+
37
+ def sourcemap_asset_path(sourcemap_logical_path, context:)
38
+ # FIXME: Work-around for bug where if the sourcemap is nested two levels deep, it'll resolve as the source file
39
+ # that's being mapped, rather than the map itself. So context.resolve("a/b/c.js.map") will return "c.js?"
40
+ if context.resolve(sourcemap_logical_path) =~ /\.map/
41
+ context.asset_path(sourcemap_logical_path)
42
+ else
43
+ raise Sprockets::FileNotFound, "Failed to resolve source map asset due to nesting depth"
44
+ end
45
+ end
46
+
47
+ def removed_sourcemap_comment(sourcemap_logical_path, filename:, env:)
48
+ env.logger.warn "Removed sourceMappingURL comment for missing asset '#{sourcemap_logical_path}' from #{filename}"
49
+ nil
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -1,5 +1,5 @@
1
1
  module Sprockets
2
2
  module Rails
3
- VERSION = "3.2.2"
3
+ VERSION = "3.5.0"
4
4
  end
5
5
  end
@@ -1,4 +1,13 @@
1
1
  require 'sprockets/rails/version'
2
+ require 'active_support'
2
3
  if defined? Rails::Railtie
3
4
  require 'sprockets/railtie'
4
5
  end
6
+
7
+ module Sprockets
8
+ module Rails
9
+ def self.deprecator
10
+ @deprecator ||= ActiveSupport::Deprecation.new("4.0", "Sprockets::Rails")
11
+ end
12
+ end
13
+ end
@@ -4,6 +4,9 @@ require 'action_controller/railtie'
4
4
  require 'active_support/core_ext/module/remove_method'
5
5
  require 'active_support/core_ext/numeric/bytes'
6
6
  require 'sprockets'
7
+
8
+ require 'sprockets/rails/asset_url_processor'
9
+ require 'sprockets/rails/sourcemapping_url_processor'
7
10
  require 'sprockets/rails/context'
8
11
  require 'sprockets/rails/helper'
9
12
  require 'sprockets/rails/quiet_assets'
@@ -50,17 +53,6 @@ module Rails
50
53
  @precompiled_assets ||= assets_manifest.find(config.assets.precompile).map(&:logical_path).to_set
51
54
  end
52
55
  end
53
-
54
- class Engine < Railtie
55
- # Skip defining append_assets_path on Rails <= 4.2
56
- unless initializers.find { |init| init.name == :append_assets_path }
57
- initializer :append_assets_path, :group => :all do |app|
58
- app.config.assets.paths.unshift(*paths["vendor/assets"].existent_directories)
59
- app.config.assets.paths.unshift(*paths["lib/assets"].existent_directories)
60
- app.config.assets.paths.unshift(*paths["app/assets"].existent_directories)
61
- end
62
- end
63
- end
64
56
  end
65
57
 
66
58
  module Sprockets
@@ -93,13 +85,20 @@ module Sprockets
93
85
  end
94
86
  end
95
87
 
88
+ ::Rails::Engine.initializer :append_assets_path, :group => :all do |app|
89
+ app.config.assets.paths.unshift(*paths["vendor/assets"].existent_directories)
90
+ app.config.assets.paths.unshift(*paths["lib/assets"].existent_directories)
91
+ app.config.assets.paths.unshift(*paths["app/assets"].existent_directories)
92
+ end
93
+
96
94
  config.assets = OrderedOptions.new
97
- config.assets._blocks = []
98
- config.assets.paths = []
99
- config.assets.precompile = []
100
- config.assets.prefix = "/assets"
101
- config.assets.manifest = nil
102
- config.assets.quiet = false
95
+ config.assets._blocks = []
96
+ config.assets.paths = []
97
+ config.assets.precompile = []
98
+ config.assets.prefix = "/assets"
99
+ config.assets.manifest = nil
100
+ config.assets.quiet = false
101
+ config.assets.resolve_assets_in_css_urls = true
103
102
 
104
103
  initializer :set_default_precompile do |app|
105
104
  if using_sprockets4?
@@ -116,6 +115,20 @@ module Sprockets
116
115
  end
117
116
  end
118
117
 
118
+ initializer :asset_url_processor do |app|
119
+ if app.config.assets.resolve_assets_in_css_urls
120
+ Sprockets.register_postprocessor "text/css", ::Sprockets::Rails::AssetUrlProcessor
121
+ end
122
+ end
123
+
124
+ initializer :asset_sourcemap_url_processor do |app|
125
+ Sprockets.register_postprocessor "application/javascript", ::Sprockets::Rails::SourcemappingUrlProcessor
126
+ end
127
+
128
+ initializer "sprockets-rails.deprecator" do |app|
129
+ app.deprecators[:sprockets_rails] = Sprockets::Rails.deprecator if app.respond_to?(:deprecators)
130
+ end
131
+
119
132
  config.assets.version = ""
120
133
  config.assets.debug = false
121
134
  config.assets.compile = true
@@ -223,11 +236,7 @@ module Sprockets
223
236
  ActionDispatch::Routing::RouteWrapper.class_eval do
224
237
  class_attribute :assets_prefix
225
238
 
226
- if defined?(prepend) && ::Rails.version >= '4'
227
- prepend Sprockets::Rails::RouteWrapper
228
- else
229
- include Sprockets::Rails::RouteWrapper
230
- end
239
+ prepend Sprockets::Rails::RouteWrapper
231
240
 
232
241
  self.assets_prefix = config.assets.prefix
233
242
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sprockets-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.2
4
+ version: 3.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Peek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-12 00:00:00.000000000 Z
11
+ date: 2024-06-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sprockets
@@ -30,42 +30,42 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '4.0'
33
+ version: '6.1'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '4.0'
40
+ version: '6.1'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: activesupport
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '4.0'
47
+ version: '6.1'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '4.0'
54
+ version: '6.1'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: railties
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '4.0'
61
+ version: '6.1'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '4.0'
68
+ version: '6.1'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -117,10 +117,12 @@ files:
117
117
  - MIT-LICENSE
118
118
  - README.md
119
119
  - lib/sprockets/rails.rb
120
+ - lib/sprockets/rails/asset_url_processor.rb
120
121
  - lib/sprockets/rails/context.rb
121
122
  - lib/sprockets/rails/helper.rb
122
123
  - lib/sprockets/rails/quiet_assets.rb
123
124
  - lib/sprockets/rails/route_wrapper.rb
125
+ - lib/sprockets/rails/sourcemapping_url_processor.rb
124
126
  - lib/sprockets/rails/task.rb
125
127
  - lib/sprockets/rails/utils.rb
126
128
  - lib/sprockets/rails/version.rb
@@ -137,14 +139,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
137
139
  requirements:
138
140
  - - ">="
139
141
  - !ruby/object:Gem::Version
140
- version: 1.9.3
142
+ version: '2.5'
141
143
  required_rubygems_version: !ruby/object:Gem::Requirement
142
144
  requirements:
143
145
  - - ">="
144
146
  - !ruby/object:Gem::Version
145
147
  version: '0'
146
148
  requirements: []
147
- rubygems_version: 3.1.2
149
+ rubygems_version: 3.5.9
148
150
  signing_key:
149
151
  specification_version: 4
150
152
  summary: Sprockets Rails integration