sprockets-rails 3.2.1 → 3.4.2
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/README.md +15 -4
- data/lib/sprockets/rails/asset_url_processor.rb +17 -0
- data/lib/sprockets/rails/helper.rb +16 -7
- data/lib/sprockets/rails/sourcemapping_url_processor.rb +54 -0
- data/lib/sprockets/rails/task.rb +0 -1
- data/lib/sprockets/rails/version.rb +1 -1
- data/lib/sprockets/railtie.rb +22 -7
- metadata +16 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 73feab57944f69ac95583179fd64af5d7e927b6e352260ce8d061e95b2dbdfd8
|
4
|
+
data.tar.gz: 4cec001efd7cd64ee755114ccdaa80dac093abf39efd0e982223329508e3ddb1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 551eeb4f6d09b58157c6fbe2797f4e7ec69dde50cb9a160862e75cd2fe73063e1935582e3bf69533a835d3045d8562ce73de636caa89320e0d1a8b19cb875326
|
7
|
+
data.tar.gz: 2ea2f80c41a29207772023a344a5404d0aeae3c32987c5dae511f7941637a3ac744e02d66681d667e1b583fe91b2b606c43ab708436766cf708a76408628cb42
|
data/README.md
CHANGED
@@ -86,7 +86,7 @@ When enabled, fingerprints will be added to asset filenames.
|
|
86
86
|
|
87
87
|
**`config.assets.debug`**
|
88
88
|
|
89
|
-
Enable
|
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
|
@@ -138,7 +142,7 @@ The following plugins provide some extras for the Sprockets Asset Pipeline.
|
|
138
142
|
* [coffee-rails](https://github.com/rails/coffee-rails)
|
139
143
|
* [sass-rails](https://github.com/rails/sass-rails)
|
140
144
|
|
141
|
-
**NOTE** That these plugins are optional. The core coffee-script, sass, less, uglify, (
|
145
|
+
**NOTE** That these plugins are optional. The core coffee-script, sass, less, uglify, (and many more) features are built into Sprockets itself. Many of these plugins only provide generators and extra helpers. You can probably get by without them.
|
142
146
|
|
143
147
|
|
144
148
|
## Changes from Rails 3.x
|
@@ -150,6 +154,15 @@ The following plugins provide some extras for the Sprockets Asset Pipeline.
|
|
150
154
|
* `config.assets.manifest` (if used) must now include the manifest filename, e.g. `Rails.root.join('config/manifest.json')`. It cannot be a directory.
|
151
155
|
* Two cleanup tasks: `rake assets:clean` is now a safe cleanup that only removes older assets that are no longer used, while `rake assets:clobber` nukes the entire `public/assets` directory. The clean task allows for rolling deploys that may still be linking to an old asset while the new assets are being built.
|
152
156
|
|
157
|
+
### But what if I want sprockets to generate non-digest assets?
|
158
|
+
|
159
|
+
You have several options:
|
160
|
+
|
161
|
+
* Use the [non-digest-assets gem](https://github.com/mvz/non-digest-assets).
|
162
|
+
* Use the [sprockets-redirect gem](https://github.com/sikachu/sprockets-redirect).
|
163
|
+
* Use the [smart_assets gem](https://github.com/zarqman/smart_assets).
|
164
|
+
* Create [a rake task](https://github.com/rails/sprockets-rails/issues/49#issuecomment-20535134) to pre-generate a non-digest version in `public/`.
|
165
|
+
|
153
166
|
## Experimental
|
154
167
|
|
155
168
|
### [SRI](http://www.w3.org/TR/SRI/) support
|
@@ -187,6 +200,4 @@ Sprockets Rails is released under the [MIT License](MIT-LICENSE).
|
|
187
200
|
|
188
201
|
## Code Status
|
189
202
|
|
190
|
-
* [](http://travis-ci.org/rails/sprockets-rails)
|
191
203
|
* [](http://badge.fury.io/rb/sprockets-rails)
|
192
|
-
* [](https://gemnasium.com/rails/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
|
@@ -7,15 +7,16 @@ module Sprockets
|
|
7
7
|
module Rails
|
8
8
|
module Helper
|
9
9
|
class AssetNotFound < StandardError; end
|
10
|
+
class AssetNotPrecompiled < StandardError; end
|
10
11
|
|
11
|
-
class
|
12
|
+
class AssetNotPrecompiledError < AssetNotPrecompiled
|
12
13
|
include Sprockets::Rails::Utils
|
13
14
|
def initialize(source)
|
14
15
|
msg =
|
15
16
|
if using_sprockets4?
|
16
17
|
"Asset `#{ source }` was not declared to be precompiled in production.\n" +
|
17
18
|
"Declare links to your assets in `app/assets/config/manifest.js`.\n\n" +
|
18
|
-
" //= link #{ source }\n" +
|
19
|
+
" //= link #{ source }\n\n" +
|
19
20
|
"and restart your server"
|
20
21
|
else
|
21
22
|
"Asset was not declared to be precompiled in production.\n" +
|
@@ -57,7 +58,7 @@ module Sprockets
|
|
57
58
|
end
|
58
59
|
|
59
60
|
def self.extended(obj)
|
60
|
-
obj.class_eval do
|
61
|
+
obj.singleton_class.class_eval do
|
61
62
|
attr_accessor(*VIEW_ACCESSORS)
|
62
63
|
|
63
64
|
remove_method :assets_environment
|
@@ -79,7 +80,7 @@ module Sprockets
|
|
79
80
|
if asset_path = resolve_asset_path(path, debug)
|
80
81
|
File.join(assets_prefix || "/", legacy_debug_path(asset_path, debug))
|
81
82
|
else
|
82
|
-
message = "The asset #{ path.inspect } is not present in the asset pipeline
|
83
|
+
message = "The asset #{ path.inspect } is not present in the asset pipeline.\n"
|
83
84
|
raise AssetNotFound, message unless unknown_asset_fallback
|
84
85
|
|
85
86
|
if respond_to?(:public_compute_asset_path)
|
@@ -351,8 +352,16 @@ module Sprockets
|
|
351
352
|
end
|
352
353
|
|
353
354
|
private
|
354
|
-
|
355
|
-
|
355
|
+
if RUBY_VERSION >= "2.7"
|
356
|
+
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
357
|
+
def find_asset(path, options = {})
|
358
|
+
@env[path, **options]
|
359
|
+
end
|
360
|
+
RUBY
|
361
|
+
else
|
362
|
+
def find_asset(path, options = {})
|
363
|
+
@env[path, options]
|
364
|
+
end
|
356
365
|
end
|
357
366
|
|
358
367
|
def precompiled?(path)
|
@@ -360,7 +369,7 @@ module Sprockets
|
|
360
369
|
end
|
361
370
|
|
362
371
|
def raise_unless_precompiled_asset(path)
|
363
|
-
raise Helper::
|
372
|
+
raise Helper::AssetNotPrecompiledError.new(path) if @check_precompiled_asset && !precompiled?(path)
|
364
373
|
end
|
365
374
|
end
|
366
375
|
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
|
data/lib/sprockets/rails/task.rb
CHANGED
data/lib/sprockets/railtie.rb
CHANGED
@@ -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'
|
@@ -76,7 +79,8 @@ module Sprockets
|
|
76
79
|
" //= link_tree ../images\n" +
|
77
80
|
" //= link_directory ../javascripts .js\n" +
|
78
81
|
" //= link_directory ../stylesheets .css\n" +
|
79
|
-
"and restart your server"
|
82
|
+
"and restart your server\n\n" +
|
83
|
+
"For more information see: https://github.com/rails/sprockets/blob/070fc01947c111d35bb4c836e9bb71962a8e0595/UPGRADING.md#manifestjs"
|
80
84
|
super msg
|
81
85
|
end
|
82
86
|
end
|
@@ -93,12 +97,13 @@ module Sprockets
|
|
93
97
|
end
|
94
98
|
|
95
99
|
config.assets = OrderedOptions.new
|
96
|
-
config.assets._blocks
|
97
|
-
config.assets.paths
|
98
|
-
config.assets.precompile
|
99
|
-
config.assets.prefix
|
100
|
-
config.assets.manifest
|
101
|
-
config.assets.quiet
|
100
|
+
config.assets._blocks = []
|
101
|
+
config.assets.paths = []
|
102
|
+
config.assets.precompile = []
|
103
|
+
config.assets.prefix = "/assets"
|
104
|
+
config.assets.manifest = nil
|
105
|
+
config.assets.quiet = false
|
106
|
+
config.assets.resolve_assets_in_css_urls = true
|
102
107
|
|
103
108
|
initializer :set_default_precompile do |app|
|
104
109
|
if using_sprockets4?
|
@@ -115,6 +120,16 @@ module Sprockets
|
|
115
120
|
end
|
116
121
|
end
|
117
122
|
|
123
|
+
initializer :asset_url_processor do |app|
|
124
|
+
if app.config.assets.resolve_assets_in_css_urls
|
125
|
+
Sprockets.register_postprocessor "text/css", ::Sprockets::Rails::AssetUrlProcessor
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
initializer :asset_sourcemap_url_processor do |app|
|
130
|
+
Sprockets.register_postprocessor "application/javascript", ::Sprockets::Rails::SourcemappingUrlProcessor
|
131
|
+
end
|
132
|
+
|
118
133
|
config.assets.version = ""
|
119
134
|
config.assets.debug = false
|
120
135
|
config.assets.compile = true
|
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
|
4
|
+
version: 3.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua Peek
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-12-11 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: '
|
33
|
+
version: '5.2'
|
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: '
|
40
|
+
version: '5.2'
|
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: '
|
47
|
+
version: '5.2'
|
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: '
|
54
|
+
version: '5.2'
|
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: '
|
61
|
+
version: '5.2'
|
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: '
|
68
|
+
version: '5.2'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rake
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,7 +108,7 @@ dependencies:
|
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
-
description:
|
111
|
+
description:
|
112
112
|
email: josh@joshpeek.com
|
113
113
|
executables: []
|
114
114
|
extensions: []
|
@@ -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
|
@@ -129,7 +131,7 @@ homepage: https://github.com/rails/sprockets-rails
|
|
129
131
|
licenses:
|
130
132
|
- MIT
|
131
133
|
metadata: {}
|
132
|
-
post_install_message:
|
134
|
+
post_install_message:
|
133
135
|
rdoc_options: []
|
134
136
|
require_paths:
|
135
137
|
- lib
|
@@ -137,16 +139,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
137
139
|
requirements:
|
138
140
|
- - ">="
|
139
141
|
- !ruby/object:Gem::Version
|
140
|
-
version:
|
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
|
-
|
148
|
-
|
149
|
-
signing_key:
|
149
|
+
rubygems_version: 3.2.32
|
150
|
+
signing_key:
|
150
151
|
specification_version: 4
|
151
152
|
summary: Sprockets Rails integration
|
152
153
|
test_files: []
|