autoprefixer-rails 8.6.5 → 9.6.5
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 +4 -4
- data/.github/FUNDING.yml +1 -0
- data/.standard.yml +1 -0
- data/.travis.yml +7 -24
- data/CHANGELOG.md +130 -0
- data/Gemfile +10 -1
- data/README.md +27 -27
- data/Rakefile +25 -20
- data/autoprefixer-rails.gemspec +21 -17
- data/lib/autoprefixer-rails.rb +16 -13
- data/lib/autoprefixer-rails/processor.rb +71 -141
- data/lib/autoprefixer-rails/railtie.rb +6 -6
- data/lib/autoprefixer-rails/sprockets.rb +9 -9
- data/lib/autoprefixer-rails/version.rb +1 -1
- data/lib/rake/autoprefixer_tasks.rb +4 -4
- data/spec/app/Rakefile +1 -1
- data/spec/app/app/controllers/css_controller.rb +1 -1
- data/spec/app/config.ru +1 -1
- data/spec/app/config/application.rb +6 -4
- data/spec/app/config/boot.rb +2 -2
- data/spec/app/config/environment.rb +2 -2
- data/spec/app/config/initializers/secret_token.rb +1 -1
- data/spec/app/config/routes.rb +1 -1
- data/spec/autoprefixer_spec.rb +46 -37
- data/spec/processor_spec.rb +16 -5
- data/spec/rails_spec.rb +12 -22
- data/spec/railtie_spec.rb +9 -9
- data/spec/spec_helper.rb +5 -5
- data/vendor/autoprefixer.js +58511 -15781
- metadata +13 -17
- data/mini_racer.gemfile +0 -16
- data/shared.gemfile +0 -7
- data/spec/app/config/initializers/compress.rb +0 -1
- data/spec/compass/config.rb +0 -34
- data/spec/compass/sass/screen.scss +0 -3
- data/spec/compass_spec.rb +0 -21
- data/sprockets3.gemfile +0 -9
- data/sprockets4.gemfile +0 -9
@@ -1,15 +1,14 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "pathname"
|
2
|
+
require "execjs"
|
3
|
+
require "json"
|
4
4
|
|
5
5
|
IS_SECTION = /^\s*\[(.+)\]\s*$/
|
6
6
|
|
7
7
|
module AutoprefixerRails
|
8
8
|
# Ruby to JS wrapper for Autoprefixer processor instance
|
9
9
|
class Processor
|
10
|
-
|
11
|
-
|
12
|
-
@params = params || { }
|
10
|
+
def initialize(params = {})
|
11
|
+
@params = params || {}
|
13
12
|
end
|
14
13
|
|
15
14
|
# Process `css` and return result.
|
@@ -18,85 +17,79 @@ module AutoprefixerRails
|
|
18
17
|
# * `from` with input CSS file name. Will be used in error messages.
|
19
18
|
# * `to` with output CSS file name.
|
20
19
|
# * `map` with true to generate new source map or with previous map.
|
21
|
-
def process(css, opts = {
|
20
|
+
def process(css, opts = {})
|
22
21
|
opts = convert_options(opts)
|
23
22
|
|
24
23
|
apply_wrapper =
|
25
|
-
"(function(opts, pluginOpts) {"
|
26
|
-
"return eval(process.apply(this, opts, pluginOpts));"
|
24
|
+
"(function(opts, pluginOpts) {" \
|
25
|
+
"return eval(process.apply(this, opts, pluginOpts));" \
|
27
26
|
"})"
|
28
27
|
|
29
|
-
|
30
|
-
|
31
|
-
from:
|
32
|
-
to:
|
33
|
-
map:
|
28
|
+
plugin_opts = params_with_browsers(opts[:from]).merge(opts)
|
29
|
+
process_opts = {
|
30
|
+
from: plugin_opts.delete(:from),
|
31
|
+
to: plugin_opts.delete(:to),
|
32
|
+
map: plugin_opts.delete(:map),
|
34
33
|
}
|
35
34
|
|
36
35
|
begin
|
37
|
-
result = runtime.call(apply_wrapper, [css,
|
36
|
+
result = runtime.call(apply_wrapper, [css, process_opts, plugin_opts])
|
38
37
|
rescue ExecJS::ProgramError => e
|
39
|
-
contry_error =
|
40
|
-
|
41
|
-
|
38
|
+
contry_error = "BrowserslistError: " \
|
39
|
+
"Country statistics is not supported " \
|
40
|
+
"in client-side build of Browserslist"
|
42
41
|
if e.message == contry_error
|
43
|
-
raise
|
44
|
-
|
42
|
+
raise "Country statistics is not supported in AutoprefixerRails. " \
|
43
|
+
"Use Autoprefixer with webpack or other Node.js builder."
|
45
44
|
else
|
46
45
|
raise e
|
47
46
|
end
|
48
47
|
end
|
49
48
|
|
50
|
-
Result.new(result[
|
49
|
+
Result.new(result["css"], result["map"], result["warnings"])
|
51
50
|
end
|
52
51
|
|
53
52
|
# Return, which browsers and prefixes will be used
|
54
53
|
def info
|
55
|
-
runtime.eval("autoprefixer(#{
|
54
|
+
runtime.eval("autoprefixer(#{js_params}).info()")
|
56
55
|
end
|
57
56
|
|
58
57
|
# Parse Browserslist config
|
59
58
|
def parse_config(config)
|
60
|
-
sections = {
|
61
|
-
current =
|
62
|
-
config.gsub(/#[^\n]*/,
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
59
|
+
sections = {"defaults" => []}
|
60
|
+
current = "defaults"
|
61
|
+
config.gsub(/#[^\n]*/, "")
|
62
|
+
.split(/\n/)
|
63
|
+
.map(&:strip)
|
64
|
+
.reject(&:empty?)
|
65
|
+
.each do |line|
|
66
|
+
if IS_SECTION =~ line
|
67
|
+
current = line.match(IS_SECTION)[1].strip
|
68
|
+
sections[current] ||= []
|
69
|
+
else
|
70
|
+
sections[current] << line
|
71
|
+
end
|
72
|
+
end
|
74
73
|
sections
|
75
74
|
end
|
76
75
|
|
77
76
|
private
|
78
77
|
|
79
78
|
def params_with_browsers(from = nil)
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
from = '.'
|
85
|
-
end
|
79
|
+
from ||= if defined?(Rails) && Rails.respond_to?(:root) && Rails.root
|
80
|
+
Rails.root.join("app/assets/stylesheets").to_s
|
81
|
+
else
|
82
|
+
"."
|
86
83
|
end
|
87
84
|
|
88
85
|
params = @params
|
89
|
-
if
|
86
|
+
if !params.key?(:browsers) && !params.key?(:overrideBrowserslist) && from
|
90
87
|
file = find_config(from)
|
91
88
|
if file
|
92
|
-
env = params[:env].to_s ||
|
89
|
+
env = params[:env].to_s || "development"
|
93
90
|
config = parse_config(file)
|
94
91
|
params = params.dup
|
95
|
-
|
96
|
-
params[:browsers] = config[env]
|
97
|
-
else
|
98
|
-
params[:browsers] = config['defaults']
|
99
|
-
end
|
92
|
+
params[:overrideBrowserslist] = (config[env] || config["defaults"])
|
100
93
|
end
|
101
94
|
end
|
102
95
|
|
@@ -105,18 +98,18 @@ module AutoprefixerRails
|
|
105
98
|
|
106
99
|
# Convert params to JS string and add browsers from Browserslist config
|
107
100
|
def js_params
|
108
|
-
|
109
|
-
params_with_browsers.map { |k, v| "#{k}: #{v.inspect}"}.join(
|
110
|
-
|
101
|
+
"{ " +
|
102
|
+
params_with_browsers.map { |k, v| "#{k}: #{v.inspect}"}.join(", ") +
|
103
|
+
" }"
|
111
104
|
end
|
112
105
|
|
113
106
|
# Convert ruby_options to jsOptions
|
114
107
|
def convert_options(opts)
|
115
|
-
converted = {
|
108
|
+
converted = {}
|
116
109
|
|
117
110
|
opts.each_pair do |name, value|
|
118
|
-
if
|
119
|
-
name = name.to_s.gsub(/_\w/) { |i| i.
|
111
|
+
if /_/ =~ name
|
112
|
+
name = name.to_s.gsub(/_\w/) { |i| i.delete("_").upcase }.to_sym
|
120
113
|
end
|
121
114
|
value = convert_options(value) if value.is_a? Hash
|
122
115
|
converted[name] = value
|
@@ -130,11 +123,11 @@ module AutoprefixerRails
|
|
130
123
|
path = Pathname(file).expand_path
|
131
124
|
|
132
125
|
while path.parent != path
|
133
|
-
config1 = path.join(
|
134
|
-
return config1.read if config1.exist?
|
126
|
+
config1 = path.join("browserslist")
|
127
|
+
return config1.read if config1.exist? && !config1.directory?
|
135
128
|
|
136
|
-
config2 = path.join(
|
137
|
-
return config2.read if config2.exist?
|
129
|
+
config2 = path.join(".browserslistrc")
|
130
|
+
return config2.read if config2.exist? && !config1.directory?
|
138
131
|
|
139
132
|
path = path.parent
|
140
133
|
end
|
@@ -145,9 +138,23 @@ module AutoprefixerRails
|
|
145
138
|
# Lazy load for JS library
|
146
139
|
def runtime
|
147
140
|
@runtime ||= begin
|
148
|
-
if ExecJS.eval(
|
149
|
-
|
150
|
-
|
141
|
+
if ExecJS.eval("typeof Uint8Array") != "function"
|
142
|
+
if ExecJS.runtime.name.start_with?("therubyracer")
|
143
|
+
raise "ExecJS::RubyRacerRuntime is not supported. " \
|
144
|
+
"Please replace therubyracer with mini_racer " \
|
145
|
+
"in your Gemfile or use Node.js as ExecJS runtime."
|
146
|
+
else
|
147
|
+
raise "#{ExecJS.runtime.name} runtime does’t support ES6. " \
|
148
|
+
"Please update or replace your current ExecJS runtime."
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
if ExecJS.runtime == ExecJS::Runtimes::Node
|
153
|
+
version = ExecJS.runtime.eval("process.version")
|
154
|
+
first = version.match(/^v(\d+)/)[1].to_i
|
155
|
+
if first < 6
|
156
|
+
raise "Autoprefixer doesn’t support Node #{version}. Update it."
|
157
|
+
end
|
151
158
|
end
|
152
159
|
|
153
160
|
ExecJS.compile(build_js)
|
@@ -159,90 +166,13 @@ module AutoprefixerRails
|
|
159
166
|
@@js ||= begin
|
160
167
|
root = Pathname(File.dirname(__FILE__))
|
161
168
|
path = root.join("../../vendor/autoprefixer.js")
|
162
|
-
path.read
|
169
|
+
path.read
|
163
170
|
end
|
164
171
|
end
|
165
172
|
|
166
|
-
def polyfills
|
167
|
-
<<-JS
|
168
|
-
if (typeof Uint8Array === "undefined")
|
169
|
-
global.Uint8Array = Array;
|
170
|
-
if (typeof ArrayBuffer === "undefined")
|
171
|
-
global.ArrayBuffer = Array;
|
172
|
-
if (typeof Set === "undefined") {
|
173
|
-
global.Set = function (values) { this.values = values }
|
174
|
-
global.Set.prototype = {
|
175
|
-
has: function (i) { return this.values.indexOf(i) !== -1 }
|
176
|
-
}
|
177
|
-
}
|
178
|
-
if (typeof Map === "undefined") {
|
179
|
-
global.Map = function () { this.data = { } }
|
180
|
-
global.Map.prototype = {
|
181
|
-
set: function (k, v) { this.data[k] = v },
|
182
|
-
get: function (k) { return this.data[k] },
|
183
|
-
has: function (k) {
|
184
|
-
return Object.keys(this.data).indexOf(k) !== -1
|
185
|
-
},
|
186
|
-
}
|
187
|
-
}
|
188
|
-
Math.log2 = Math.log2 ||
|
189
|
-
function(x) { return Math.log(x) * Math.LOG2E; };
|
190
|
-
Math.sign = Math.sign ||
|
191
|
-
function(x) {
|
192
|
-
x = +x;
|
193
|
-
if (x === 0 || isNaN(x)) return Number(x);
|
194
|
-
return x > 0 ? 1 : -1;
|
195
|
-
};
|
196
|
-
Array.prototype.fill = Array.prototype.fill ||
|
197
|
-
function(value) {
|
198
|
-
var O = Object(this);
|
199
|
-
var len = O.length >>> 0;
|
200
|
-
var start = arguments[1];
|
201
|
-
var relativeStart = start >> 0;
|
202
|
-
var k = relativeStart < 0 ?
|
203
|
-
Math.max(len + relativeStart, 0) :
|
204
|
-
Math.min(relativeStart, len);
|
205
|
-
var end = arguments[2];
|
206
|
-
var relativeEnd = end === undefined ?
|
207
|
-
len : end >> 0;
|
208
|
-
var final = relativeEnd < 0 ?
|
209
|
-
Math.max(len + relativeEnd, 0) :
|
210
|
-
Math.min(relativeEnd, len);
|
211
|
-
while (k < final) {
|
212
|
-
O[k] = value;
|
213
|
-
k++;
|
214
|
-
}
|
215
|
-
return O;
|
216
|
-
};
|
217
|
-
if (!Object.assign) {
|
218
|
-
Object.assign = function(target, firstSource) {
|
219
|
-
var to = Object(target);
|
220
|
-
for (var i = 1; i < arguments.length; i++) {
|
221
|
-
var nextSource = arguments[i];
|
222
|
-
if (nextSource === undefined || nextSource === null) continue;
|
223
|
-
var keysArray = Object.keys(Object(nextSource));
|
224
|
-
for (var n = 0, len = keysArray.length; n < len; n++) {
|
225
|
-
var nextKey = keysArray[n];
|
226
|
-
var desc = Object.getOwnPropertyDescriptor(nextSource, nextKey);
|
227
|
-
if (desc !== undefined && desc.enumerable) {
|
228
|
-
to[nextKey] = nextSource[nextKey];
|
229
|
-
}
|
230
|
-
}
|
231
|
-
}
|
232
|
-
return to;
|
233
|
-
}
|
234
|
-
}
|
235
|
-
if (!Array.isView) {
|
236
|
-
Array.isView = function () {
|
237
|
-
return false
|
238
|
-
}
|
239
|
-
}
|
240
|
-
JS
|
241
|
-
end
|
242
|
-
|
243
173
|
# Return processor JS with some extra methods
|
244
174
|
def build_js
|
245
|
-
|
175
|
+
"var global = this;" + read_js + process_proxy
|
246
176
|
end
|
247
177
|
|
248
178
|
# Return JS code for process method proxy
|
@@ -1,20 +1,20 @@
|
|
1
|
-
require
|
1
|
+
require "yaml"
|
2
2
|
|
3
3
|
begin
|
4
4
|
module AutoprefixedRails
|
5
5
|
class Railtie < ::Rails::Railtie
|
6
6
|
rake_tasks do |app|
|
7
|
-
require
|
8
|
-
Rake::AutoprefixerTasks.new(
|
7
|
+
require "rake/autoprefixer_tasks"
|
8
|
+
Rake::AutoprefixerTasks.new(config) if defined? app.assets
|
9
9
|
end
|
10
10
|
|
11
|
-
if config.respond_to?(:assets)
|
11
|
+
if config.respond_to?(:assets) && !config.assets.nil?
|
12
12
|
config.assets.configure do |env|
|
13
13
|
AutoprefixerRails.install(env, config)
|
14
14
|
end
|
15
15
|
else
|
16
16
|
initializer :setup_autoprefixer, group: :all do |app|
|
17
|
-
if defined?
|
17
|
+
if defined?(app.assets) && !app.assets.nil?
|
18
18
|
AutoprefixerRails.install(app.assets, config)
|
19
19
|
end
|
20
20
|
end
|
@@ -25,7 +25,7 @@ begin
|
|
25
25
|
params = {}
|
26
26
|
|
27
27
|
roots.each do |root|
|
28
|
-
file = File.join(root,
|
28
|
+
file = File.join(root, "config/autoprefixer.yml")
|
29
29
|
|
30
30
|
if File.exist?(file)
|
31
31
|
parsed = ::YAML.load_file(file)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "pathname"
|
2
2
|
|
3
3
|
module AutoprefixerRails
|
4
4
|
# Register autoprefixer postprocessor in Sprockets and fix common issues
|
@@ -16,11 +16,11 @@ module AutoprefixerRails
|
|
16
16
|
|
17
17
|
# Add prefixes to `css`
|
18
18
|
def self.run(filename, css)
|
19
|
-
output = filename.chomp(File.extname(filename)) +
|
19
|
+
output = filename.chomp(File.extname(filename)) + ".css"
|
20
20
|
result = @processor.process(css, from: filename, to: output)
|
21
21
|
|
22
22
|
result.warnings.each do |warning|
|
23
|
-
|
23
|
+
warn "autoprefixer: #{warning}"
|
24
24
|
end
|
25
25
|
|
26
26
|
result.css
|
@@ -29,10 +29,10 @@ module AutoprefixerRails
|
|
29
29
|
# Register postprocessor in Sprockets depend on issues with other gems
|
30
30
|
def self.install(env)
|
31
31
|
if ::Sprockets::VERSION.to_f < 4
|
32
|
-
env.register_postprocessor(
|
32
|
+
env.register_postprocessor("text/css",
|
33
33
|
::AutoprefixerRails::Sprockets)
|
34
34
|
else
|
35
|
-
env.register_bundle_processor(
|
35
|
+
env.register_bundle_processor("text/css",
|
36
36
|
::AutoprefixerRails::Sprockets)
|
37
37
|
end
|
38
38
|
end
|
@@ -40,18 +40,18 @@ module AutoprefixerRails
|
|
40
40
|
# Register postprocessor in Sprockets depend on issues with other gems
|
41
41
|
def self.uninstall(env)
|
42
42
|
if ::Sprockets::VERSION.to_f < 4
|
43
|
-
env.unregister_postprocessor(
|
43
|
+
env.unregister_postprocessor("text/css",
|
44
44
|
::AutoprefixerRails::Sprockets)
|
45
45
|
else
|
46
|
-
env.unregister_bundle_processor(
|
46
|
+
env.unregister_bundle_processor("text/css",
|
47
47
|
::AutoprefixerRails::Sprockets)
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
51
|
# Sprockets 2 API new and render
|
52
|
-
def initialize(filename
|
52
|
+
def initialize(filename)
|
53
53
|
@filename = filename
|
54
|
-
@source =
|
54
|
+
@source = yield
|
55
55
|
end
|
56
56
|
|
57
57
|
# Sprockets 2 API new and render
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "rake"
|
2
|
+
require "rake/tasklib"
|
3
|
+
require "autoprefixer-rails"
|
4
4
|
|
5
5
|
module Rake
|
6
6
|
# Define task to inspect Autoprefixer browsers, properties and values.
|
@@ -18,7 +18,7 @@ module Rake
|
|
18
18
|
|
19
19
|
def define
|
20
20
|
namespace :autoprefixer do
|
21
|
-
desc
|
21
|
+
desc "Show selected browsers and prefixed CSS properties and values"
|
22
22
|
task :info do
|
23
23
|
puts @processor.info
|
24
24
|
end
|
data/spec/app/Rakefile
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
require File.expand_path(
|
1
|
+
require File.expand_path("../config/application", __FILE__)
|
2
2
|
App::Application.load_tasks
|
data/spec/app/config.ru
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
require ::File.expand_path(
|
1
|
+
require ::File.expand_path("../config/environment", __FILE__)
|
2
2
|
run App::Application
|
@@ -1,14 +1,16 @@
|
|
1
|
-
require File.expand_path(
|
1
|
+
require File.expand_path("../boot", __FILE__)
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "action_controller/railtie"
|
4
|
+
require "sprockets/railtie"
|
5
5
|
|
6
6
|
if defined?(Bundler)
|
7
|
-
Bundler.require(*Rails.groups(assets: %w
|
7
|
+
Bundler.require(*Rails.groups(assets: %w[development test]))
|
8
8
|
end
|
9
9
|
|
10
10
|
module App
|
11
11
|
class Application < Rails::Application
|
12
12
|
config.assets.enabled = true
|
13
|
+
config.sass.line_comments = false
|
14
|
+
config.sass.inline_source_maps = true
|
13
15
|
end
|
14
16
|
end
|