sprockets-rails 3.3.0 → 3.4.2
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
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
|
@@ -1,14 +1,16 @@
|
|
1
1
|
module Sprockets
|
2
2
|
module Rails
|
3
|
-
#
|
3
|
+
# Resolve assets referenced in CSS `url()` calls and replace them with the digested paths
|
4
4
|
class AssetUrlProcessor
|
5
|
-
REGEX = /url\(\s*["']?(?!(?:\#|data|http))([^"'\s)]+)\s*["']?\)/
|
6
|
-
|
5
|
+
REGEX = /url\(\s*["']?(?!(?:\#|data|http))(?<relativeToCurrentDir>\.\/)?(?<path>[^"'\s)]+)\s*["']?\)/
|
7
6
|
def self.call(input)
|
8
7
|
context = input[:environment].context_class.new(input)
|
9
|
-
data = input[:data].gsub(REGEX)
|
8
|
+
data = input[:data].gsub(REGEX) do |_match|
|
9
|
+
path = Regexp.last_match[:path]
|
10
|
+
"url(#{context.asset_path(path)})"
|
11
|
+
end
|
10
12
|
|
11
|
-
|
13
|
+
context.metadata.merge(data: data)
|
12
14
|
end
|
13
15
|
end
|
14
16
|
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/railtie.rb
CHANGED
@@ -6,6 +6,7 @@ require 'active_support/core_ext/numeric/bytes'
|
|
6
6
|
require 'sprockets'
|
7
7
|
|
8
8
|
require 'sprockets/rails/asset_url_processor'
|
9
|
+
require 'sprockets/rails/sourcemapping_url_processor'
|
9
10
|
require 'sprockets/rails/context'
|
10
11
|
require 'sprockets/rails/helper'
|
11
12
|
require 'sprockets/rails/quiet_assets'
|
@@ -96,12 +97,13 @@ module Sprockets
|
|
96
97
|
end
|
97
98
|
|
98
99
|
config.assets = OrderedOptions.new
|
99
|
-
config.assets._blocks
|
100
|
-
config.assets.paths
|
101
|
-
config.assets.precompile
|
102
|
-
config.assets.prefix
|
103
|
-
config.assets.manifest
|
104
|
-
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
|
105
107
|
|
106
108
|
initializer :set_default_precompile do |app|
|
107
109
|
if using_sprockets4?
|
@@ -119,7 +121,13 @@ module Sprockets
|
|
119
121
|
end
|
120
122
|
|
121
123
|
initializer :asset_url_processor do |app|
|
122
|
-
|
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
|
123
131
|
end
|
124
132
|
|
125
133
|
config.assets.version = ""
|
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.
|
4
|
+
version: 3.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua Peek
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sprockets
|
@@ -122,6 +122,7 @@ files:
|
|
122
122
|
- lib/sprockets/rails/helper.rb
|
123
123
|
- lib/sprockets/rails/quiet_assets.rb
|
124
124
|
- lib/sprockets/rails/route_wrapper.rb
|
125
|
+
- lib/sprockets/rails/sourcemapping_url_processor.rb
|
125
126
|
- lib/sprockets/rails/task.rb
|
126
127
|
- lib/sprockets/rails/utils.rb
|
127
128
|
- lib/sprockets/rails/version.rb
|
@@ -145,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
145
146
|
- !ruby/object:Gem::Version
|
146
147
|
version: '0'
|
147
148
|
requirements: []
|
148
|
-
rubygems_version: 3.2.
|
149
|
+
rubygems_version: 3.2.32
|
149
150
|
signing_key:
|
150
151
|
specification_version: 4
|
151
152
|
summary: Sprockets Rails integration
|