autoprefixer-rails 9.1.4 → 10.4.21.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.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +261 -0
  3. data/README.md +38 -36
  4. data/lib/autoprefixer-rails/processor.rb +73 -109
  5. data/lib/autoprefixer-rails/railtie.rb +20 -15
  6. data/lib/autoprefixer-rails/result.rb +2 -0
  7. data/lib/autoprefixer-rails/sprockets.rb +16 -14
  8. data/lib/autoprefixer-rails/version.rb +4 -2
  9. data/lib/autoprefixer-rails.rb +16 -13
  10. data/lib/rake/autoprefixer_tasks.rb +6 -4
  11. data/vendor/autoprefixer.js +73336 -57364
  12. metadata +45 -53
  13. data/.gitignore +0 -7
  14. data/.rspec +0 -1
  15. data/.travis.yml +0 -21
  16. data/Gemfile +0 -9
  17. data/Rakefile +0 -48
  18. data/autoprefixer-rails.gemspec +0 -28
  19. data/spec/app/.browserslistrc +0 -4
  20. data/spec/app/.gitignore +0 -2
  21. data/spec/app/Rakefile +0 -2
  22. data/spec/app/app/assets/config/manifest.js +0 -0
  23. data/spec/app/app/assets/stylesheets/evaluate.css.erb +0 -1
  24. data/spec/app/app/assets/stylesheets/loaded.sass +0 -2
  25. data/spec/app/app/assets/stylesheets/sass.sass +0 -1
  26. data/spec/app/app/assets/stylesheets/test.css +0 -3
  27. data/spec/app/app/assets/stylesheets/wrong.css +0 -2
  28. data/spec/app/app/controllers/application_controller.rb +0 -2
  29. data/spec/app/app/controllers/css_controller.rb +0 -6
  30. data/spec/app/config/application.rb +0 -14
  31. data/spec/app/config/autoprefixer.yml +0 -2
  32. data/spec/app/config/boot.rb +0 -2
  33. data/spec/app/config/environment.rb +0 -3
  34. data/spec/app/config/environments/test.rb +0 -9
  35. data/spec/app/config/initializers/compress.rb +0 -1
  36. data/spec/app/config/initializers/secret_token.rb +0 -1
  37. data/spec/app/config/routes.rb +0 -3
  38. data/spec/app/config.ru +0 -2
  39. data/spec/autoprefixer_spec.rb +0 -112
  40. data/spec/compass/config.rb +0 -34
  41. data/spec/compass/sass/screen.scss +0 -3
  42. data/spec/compass_spec.rb +0 -21
  43. data/spec/processor_spec.rb +0 -14
  44. data/spec/rails_spec.rb +0 -50
  45. data/spec/railtie_spec.rb +0 -29
  46. data/spec/spec_helper.rb +0 -16
  47. data/sprockets4.gemfile +0 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 72381f9de4e512b71885992f63926d7847f93cc4615a3548a9cb820ebbdbd629
4
- data.tar.gz: d203525e13d0ef4298c233c692c53d2d9066911637a30a164437fe03e507c47b
3
+ metadata.gz: 98cf66fc3bb54861918634d73791b05066bcdae4fd6ed8ccbc7b84377a89bccd
4
+ data.tar.gz: ec5365b78c0d14a23041d8909a4b7e44f5515dc3ca6e74e8f1721d9d6244d464
5
5
  SHA512:
6
- metadata.gz: e67e8daa4509eac017913f47ed26bd5b62b9de1ed4f7af202eb9a0df3430ac66984fbba1232795be8d1f09c1e491922f407338f7e07a452ef416fac19ea0ddd3
7
- data.tar.gz: 2a08e703aaccdbe1c3bf1299f13cbd4eb711c4003f374589227027eeee2c652d75d4de76d2032c91c7a26446410f0762f3af7e44aa57eb359d0dfdb1752ee4c2
6
+ metadata.gz: ae6e1c61d08568630bb2db7cf551472de0a47e90732d51188f2532c2f2c233aa425a5e6ef7f36aca1ce252bda73fc4277ef8a7cd1387c7dce4d84fa5b33b9985
7
+ data.tar.gz: 65f837e19562bcaf9e2c7ea19d5fdb761ac3176ca5deadd285d73fd9d82b869ed8b038abe9f1626ddd8b57c074c59b489a96d5f785dd83a6e35338d440618520
data/CHANGELOG.md CHANGED
@@ -1,4 +1,265 @@
1
1
  # Change Log
2
+ ## 10.4.21.0
3
+ * Fixed old `-moz-` prefix for `:placeholder-shown` (by @Marukome0743).
4
+ * Fixed `fit-content` prefix for Firefox.
5
+
6
+ ## 10.4.19.0
7
+ * Removed `end value has mixed support, consider using flex-end` warning
8
+ since `end`/`start` now have good support.
9
+ * Fixed removing `-webkit-box-orient` on `-webkit-line-clamp` (@Goodwine).
10
+ * Fixed `user-select: contain` prefixes.
11
+
12
+ ## 10.4.16.0
13
+ * Improved performance (by Romain Menke).
14
+
15
+ ## 10.4.15.0
16
+ * Improved startup time and reduced JS bundle size (by Kārlis Gaņģis).
17
+ * Fixed `::backdrop` prefixes (by 一丝).
18
+
19
+ ## 10.4.13.0
20
+ * Fixed missed prefixes on vendor prefixes in name of CSS Custom Property.
21
+ * Fixed support of unit-less zero angle in backgrounds (by 一丝).
22
+ * Fixed `text-decoration` prefixes by moving to MDN data (by Romain Menke).
23
+ * Fixed `unicode-bidi` prefixes by moving to MDN data.
24
+ * Fixed `css-unicode-bidi` issue from latest Can I Use.
25
+ * Do not print `color-adjust` warning if `print-color-adjust` also is in rule.
26
+
27
+ ## 10.4.7.0
28
+ * Fixed `print-color-adjust` support in Firefox.
29
+ * Fixed `print-color-adjust` support.
30
+ * Fixed `NaN` in grid (by @SukkaW).
31
+
32
+ ## 10.4.2.0
33
+ * Fixed missed `-webkit-` prefix for `width: stretch`.
34
+ * Fixed `::file-selector-button` data (by Luke Warlow).
35
+ * Ensure sprockets-rails is loaded before autoprefixer-rails (by Thomas Morgan)
36
+
37
+ ## 10.4.0.0
38
+ * Added `:autofill` support (by Luke Warlow).
39
+
40
+ ## 10.3.3.0
41
+ * Fixed `::file-selector-button` support (by Usman Yunusov).
42
+ * Fixed wrong `-moz-` prefix from `::file-selector-button` (by Usman Yunusov).
43
+
44
+ ## 10.3.1.0
45
+ * Added `::file-selector-button` support (by Luke Warlow).
46
+ * Fixed adding wrong prefixes to `content` (by Luke Warlow).
47
+ * Fix `ReferenceError: Can't find variable: URL` (#213)
48
+
49
+ ## 10.2.5.1
50
+ * Remove nodejs version check via ExecJS, to be compatible with 2.8.1 (#203)
51
+
52
+ ## 10.2.5.0
53
+ * Fixed `:` support in `@supports` (by Dmitry Semigradsky).
54
+ * Update Can I Use data.
55
+ * Lock to execjs < 2.8.0 for now (#203)
56
+
57
+ ## 10.2.4.0
58
+ * Fixed `transition-property` warnings (by @Sheraff).
59
+
60
+ ## 10.2.0.0 "Sub rosa"
61
+ * Added TypeScript definitions (by Dmitry Semigradsky).
62
+ * Fixed docs (by Florian Pellet).
63
+ * Update Can I Use data.
64
+ * Update postcss to 8.2.2
65
+
66
+ ## 10.1.0.0 "Pula"
67
+ * Fixed `Cannot read property 'proxyOf' of undefined` error (by Igor Kamyshev).
68
+ * Added `dpcm` unit support to `min-resolution: 2dppx` (by Robert Eisele).
69
+ * Fixed rational approximation in `min-resolution` (by Robert Eisele).
70
+
71
+ ## 10.0.3.0
72
+ * Fixed `substract` to `subtract` value for `mask-composite` (by Michelle Enos).
73
+ * Update Can I Use data
74
+
75
+ ## 10.0.2.0
76
+ * Removed -ms-user-select: all because IE and old Edge don’t support it.
77
+ * Fixed Grid Layout warning.
78
+ * Update Can I Use data
79
+
80
+ ## 10.0.1.3
81
+ * Fix `fileURL.replace is not a function` when reporting warnings (#194)
82
+
83
+ ## 10.0.1.2
84
+ * Workaround `existsSync not a function` (#193)
85
+
86
+ ## 10.0.1.1
87
+ * Update Can I Use data.
88
+ * Update postcss to 8.1.4
89
+ * Fix issue with source map (#190)
90
+
91
+ ## 10.0.1.0
92
+ * Update Can I Use data.
93
+ * Update autoprefixer to 10.0.1
94
+ * Update postcss to 8.1.1
95
+
96
+ ## 10.0.0.2
97
+ * Update postcss to 8.0.5
98
+ * Update browserslist & caniuse-lite
99
+
100
+ ## 10.0.0.1
101
+ * Improved error message for old environments.
102
+ * Reduced gem file size.
103
+
104
+ ## 10.0 “Alis volat propriis”
105
+ * Removed support for Node.js 6.x, 8.x, 11.x.
106
+ * Moved to PostCSS 8.
107
+
108
+ ## 9.8.6.5
109
+ * Fix `9.8.6.4` regression.
110
+
111
+ ## 9.8.6.4
112
+ * Remove deprecation warnings.
113
+
114
+ ## 9.8.6.3
115
+ * Fix deprecation warning for non-Rails environment.
116
+
117
+ ## 9.8.6.2
118
+ * Print deprecation warning only once.
119
+
120
+ ## 9.8.6.1
121
+ * Improve deprecated warnings.
122
+
123
+ ## 9.8.6
124
+ * Fixed `env` option.
125
+ * Added deprecation warning.
126
+
127
+ ## 9.8.5
128
+ * Improved Grid Layout warnings (by Daniel Tonon).
129
+
130
+ ## 9.8.4
131
+ * Reduce JS bundle size.
132
+
133
+ ## 9.8.3
134
+ * Update Can I Use data.
135
+
136
+ ## 9.8.2
137
+ * Update Can I Use data.
138
+
139
+ ## 9.8.1
140
+ * Replace `chalk` to `kleur` (by Luke Edwards).
141
+
142
+ ## 9.8 “Vigilo Confido”
143
+ * Add `:placeholder-shown` support (by Tanguy Krotoff).
144
+
145
+ ## 9.7.6
146
+ * Revert `-webkit-stretch` fix.
147
+
148
+ ## 9.7.5
149
+ * Fix `-webkit-stretch` support.
150
+ * Reduce gem file size.
151
+
152
+ ## 9.7.4
153
+ * Update Can I Use data.
154
+
155
+ ## 9.7.3
156
+ * Update Can I Use data.
157
+
158
+ ## 9.7.2
159
+ * Add `-ms-user-select: element` support.
160
+
161
+ ## 9.7.1
162
+ * Avoid unnecessary transitions in prefixed selectors (by Andrey Alexandrov).
163
+ * Fix `fit-content` for Firefox.
164
+
165
+ ## 9.7 “Ad Victoriam”
166
+ * Add `AUTOPREFIXER_GRID` env variable to enable Grid Layout polyfill for IE.
167
+ * Fix `Cannot read property 'grid' of undefined` error.
168
+
169
+ ## 9.6.5
170
+ * Fix selector prefixing (by Andrey Alexandrov).
171
+
172
+ ## 9.6.4
173
+ * Now the real fix for `'startsWith' of undefined` error.
174
+
175
+ ## 9.6.3
176
+ * Fix `Cannot read property 'startsWith' of undefined` error.
177
+
178
+ ## 9.6.2
179
+ * Fix false `Replace fill to stretch` warning.
180
+
181
+ ## 9.6.1.1
182
+ * Update Can I Use data.
183
+
184
+ ## 9.6.1
185
+ * Fix `-webkit-line-clamp` truncating multi-line text support.
186
+
187
+ ## 9.6 “Nunc id vides, nunc ne vides”
188
+ * Add warning-less `overrideBrowserslist` option.
189
+ * Add `text-orientation` support.
190
+ * Add `min-resolution: 2x` alias support.
191
+
192
+ ## 9.5.1.1
193
+ * Fix `register_postprocessor' for nil:NilClass` error.
194
+ * Update Can I Use data.
195
+
196
+ ## 9.5.1
197
+ * Fix `backdrop-filter` for Edge (by Oleh Aloshkin).
198
+ * Fix `min-resolution` media query support in Firefox < 16.
199
+
200
+ ## 9.5 “Draco dormiens nunquam titillandus”
201
+ * Add `mask-composite` support (by Semen Levenson).
202
+
203
+ ## 9.4.10.2
204
+ * Fix Ruby < 2.4 support (by Jack Ford).
205
+ * Update Can I Use data.
206
+
207
+ ## 9.4.10.1
208
+ * Fix non-Rails environments support (by Junya Ogura).
209
+ * Update Can I Use data.
210
+
211
+ ## 9.4.10
212
+ * Add warning for named Grid rows.
213
+
214
+ ## 9.4.9
215
+ * Fix `grid-template` and `@media` case (by Bogdan Dolin).
216
+
217
+ ## 9.4.8
218
+ * Fix `calc()` support in Grid gap.
219
+
220
+ ## 9.4.7
221
+ * Fix infinite loop on mismatched parens.
222
+
223
+ ## 9.4.6
224
+ * Fix warning text (by Albert Juhé Lluveras).
225
+
226
+ ## 9.4.5
227
+ * Fix `text-decoration-skip-ink` support.
228
+
229
+ ## 9.4.4
230
+ * Use `direction` value for `-ms-writing-mode` (by Denys Kniazevych).
231
+ * Fix warning text (by @zzzzBov).
232
+
233
+ ## 9.4.3
234
+ * Add warning to force `flex-start` instead of `start` (by Antoine du Hamel).
235
+
236
+ ## 9.4.2
237
+ * Fix Grid autoplacement warning.
238
+
239
+ ## 9.4.1
240
+ * Fix unnecessary Flexbox prefixes in Grid elements.
241
+
242
+ ## 9.4 “Advance Australia”
243
+ * Add Grid autoplacement for `-ms-` (by Bogdan Dolin).
244
+ * Improve warnings (by Daniel Tonon).
245
+ * Remove some unnecessary warnings for Grid (by Andrey Alexandrov).
246
+
247
+ ## 9.3.1
248
+ * Fix Grid prefixes with `repeat()` value (by Bogdan Dolin).
249
+
250
+ ## 9.3 “Labor omnia vincit”
251
+ * Add `place-self` support (by Bogdan Dolin).
252
+ * Fix Grid row/column span inheritance bug (by Bogdan Dolin).
253
+
254
+ ## 9.2.1
255
+ * Update Can I Use data.
256
+
257
+ ## 9.2 “Ony est glavnaya krepost”
258
+ * Add `/* autoprefixer grid: on */` control comment (by Andrey Alexandrov).
259
+ * Add duplicate `grid-area` support (by Bogdan Dolin).
260
+ * Fix `grid-gap` support for rules with different specifity (by Bogdan Dolin).
261
+ * Disable Grid in `@supports` at-rule with non-supported Grid features.
262
+ * Improve Grid warnings (by Daniel Tonon).
2
263
 
3
264
  ## 9.1.4
4
265
  * Fix `ExecJS` runtime test (by Patrice Chalin).
data/README.md CHANGED
@@ -5,17 +5,18 @@
5
5
  title="Autoprefixer logo by Anton Lovchikov">
6
6
 
7
7
  [Autoprefixer] is a tool to parse CSS and add vendor prefixes to CSS rules
8
- using values from the [Can I Use] database. This gem provides Ruby and Ruby on Rails
9
- integration with this JavaScript tool.
8
+ using values from the [Can I Use] database. This gem provides Ruby
9
+ and Ruby on Rails integration with this JavaScript tool.
10
10
 
11
11
  <a href="https://evilmartians.com/?utm_source=autoprefixer-rails">
12
12
  <img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg" alt="Sponsored by Evil Martians" width="236" height="54">
13
13
  </a>
14
14
 
15
- [Autoprefixer]: https://github.com/postcss/autoprefixer
16
- [Can I Use]: http://caniuse.com/
17
- [ci-img]: https://travis-ci.org/ai/autoprefixer-rails.svg
18
- [ci]: https://travis-ci.org/ai/autoprefixer-rails
15
+ [Autoprefixer]: https://github.com/postcss/autoprefixer
16
+ [Can I Use]: http://caniuse.com/
17
+ [PostCSS]: https://postcss.org/
18
+ [ci-img]: https://github.com/ai/autoprefixer-rails/actions/workflows/ci.yml/badge.svg
19
+ [ci]: https://github.com/ai/autoprefixer-rails/actions/workflows/ci.yml
19
20
 
20
21
  ## Differences
21
22
 
@@ -28,8 +29,17 @@ Autoprefixer Rails doesn’t support these Autoprefixer features:
28
29
 
29
30
  ## Usage
30
31
 
31
- Windows users should install [node.js](http://nodejs.org/).
32
- Autoprefixer Rails doesn’t work with old JScript in Windows.
32
+ Windows users should install [Node.js]. Autoprefixer Rails doesn’t work with
33
+ old JScript in Windows.
34
+
35
+ Autoprefixer Rails uses [ExecJS] that will use the best available JavaScript
36
+ runtime. Currently this gem is tested to work with Node.js version 10 and up
37
+ and with [mini_racer], but will not work with [therubyracer].
38
+
39
+ [Node.js]: http://nodejs.org/
40
+ [ExecJS]: https://github.com/rails/execjs
41
+ [mini_racer]: https://github.com/discourse/mini_racer
42
+ [therubyracer]: https://github.com/cowboyd/therubyracer
33
43
 
34
44
  ### Ruby on Rails
35
45
 
@@ -78,26 +88,15 @@ support to add vendor prefixes automatically using the Asset Pipeline:
78
88
  }
79
89
  ```
80
90
 
81
- If you need to specify browsers for your Rails project, you can save them to
82
-
83
- * `browserslist` and place it under `app/assets/stylesheets/`
84
- or any of its ancestor directories
85
-
86
- ```
87
- > 1%
88
- last 2 versions
89
- IE > 8 # comment
90
- ```
91
+ If you need to specify browsers for your Rails project, you can save them
92
+ to `.browserslistrc` and place it under `app/assets/stylesheets/`
93
+ or any of its ancestor directories
91
94
 
92
- * Or `config/autoprefixer.yml`
93
-
94
- ```yaml
95
- flexbox: no-2009
96
- browsers:
97
- - "> 1%"
98
- - "last 2 versions"
99
- - "IE > 8"
100
- ```
95
+ ```
96
+ > 1%
97
+ last 2 versions
98
+ IE > 8 # comment
99
+ ```
101
100
 
102
101
  See [Browserslist docs] for config format. But `> 5% in US` query is not
103
102
  supported in Rails, because of ExecJS limitations. You should migrate to webpack
@@ -145,12 +144,6 @@ require "autoprefixer-rails"
145
144
  prefixed = AutoprefixerRails.process(css, from: 'main.css').css
146
145
  ```
147
146
 
148
- You can specify browsers with the `browsers` option:
149
-
150
- ```ruby
151
- AutoprefixerRails.process(css, from: 'a.css', browsers: ['> 1%', 'ie 10']).css
152
- ```
153
-
154
147
  ### Compass
155
148
 
156
149
  You should consider using Gulp instead of Compass binary,
@@ -209,7 +202,7 @@ Autoprefixer will generate a source map if you set `map` option to `true` in
209
202
  `process` method.
210
203
 
211
204
  You must set input and output CSS files paths (by `from` and `to` options)
212
- to generate correct map.
205
+ to generate a correct map.
213
206
 
214
207
  ```ruby
215
208
  result = AutoprefixerRails.process(css,
@@ -219,11 +212,12 @@ result = AutoprefixerRails.process(css,
219
212
  ```
220
213
 
221
214
  Autoprefixer can also modify previous source map (for example, from Sass
222
- compilation). Just set original source map content (as string) to `map` option:
215
+ compilation). Just set original source map content (as string) as `prev`
216
+ in the `map` option.
223
217
 
224
218
  ```ruby
225
219
  result = AutoprefixerRails.process(css, {
226
- map: File.read('main.sass.css.map'),
220
+ map: { prev: File.read('main.sass.css.map') },
227
221
  from: 'main.sass.css',
228
222
  to: 'main.min.css')
229
223
 
@@ -235,3 +229,11 @@ to JS style, so you can use `map: { sources_content: false }`
235
229
  instead of camelcase `sourcesContent`.
236
230
 
237
231
  [PostCSS docs]: https://github.com/postcss/postcss#source-map-1
232
+
233
+
234
+ ## Security Contact
235
+
236
+ To report a security vulnerability, please use the [Tidelift security contact].
237
+ Tidelift will coordinate the fix and disclosure.
238
+
239
+ [Tidelift security contact]: https://tidelift.com/security
@@ -1,15 +1,18 @@
1
- require 'pathname'
2
- require 'execjs'
3
- require 'json'
1
+ # frozen_string_literal: true
4
2
 
5
- IS_SECTION = /^\s*\[(.+)\]\s*$/
3
+ require "pathname"
4
+ require "execjs"
5
+ require "json"
6
6
 
7
7
  module AutoprefixerRails
8
+ IS_SECTION = /^\s*\[(.+)\]\s*$/.freeze
9
+
8
10
  # Ruby to JS wrapper for Autoprefixer processor instance
9
11
  class Processor
12
+ SUPPORTED_RUNTIMES = [ExecJS::Runtimes::Node, ExecJS::Runtimes::MiniRacer]
10
13
 
11
- def initialize(params = { })
12
- @params = params || { }
14
+ def initialize(params = {})
15
+ @params = params || {}
13
16
  end
14
17
 
15
18
  # Process `css` and return result.
@@ -18,105 +21,87 @@ module AutoprefixerRails
18
21
  # * `from` with input CSS file name. Will be used in error messages.
19
22
  # * `to` with output CSS file name.
20
23
  # * `map` with true to generate new source map or with previous map.
21
- def process(css, opts = { })
24
+ def process(css, opts = {})
22
25
  opts = convert_options(opts)
23
26
 
24
- apply_wrapper =
25
- "(function(opts, pluginOpts) {" +
26
- "return eval(process.apply(this, opts, pluginOpts));" +
27
- "})"
28
-
29
- pluginOpts = params_with_browsers(opts[:from]).merge(opts)
30
- processOpts = {
31
- from: pluginOpts.delete(:from),
32
- to: pluginOpts.delete(:to),
33
- map: pluginOpts.delete(:map)
27
+ plugin_opts = params_with_browsers(opts[:from]).merge(opts)
28
+ process_opts = {
29
+ from: plugin_opts.delete(:from),
30
+ to: plugin_opts.delete(:to),
31
+ map: plugin_opts.delete(:map)
34
32
  }
35
33
 
36
34
  begin
37
- result = runtime.call(apply_wrapper, [css, processOpts, pluginOpts])
35
+ result = runtime.call("autoprefixer.process", css, process_opts, plugin_opts)
38
36
  rescue ExecJS::ProgramError => e
39
- contry_error = 'BrowserslistError: ' +
40
- 'Country statistics is not supported ' +
41
- 'in client-side build of Browserslist'
37
+ contry_error = "BrowserslistError: " \
38
+ "Country statistics are not supported " \
39
+ "in client-side build of Browserslist"
42
40
  if e.message == contry_error
43
- raise 'Country statistics is not supported in AutoprefixerRails. ' +
44
- 'Use Autoprefixer with webpack or other Node.js builder.'
41
+ raise "Country statistics is not supported in AutoprefixerRails. " \
42
+ "Use Autoprefixer with webpack or other Node.js builder."
45
43
  else
46
44
  raise e
47
45
  end
48
46
  end
49
47
 
50
- Result.new(result['css'], result['map'], result['warnings'])
48
+ Result.new(result["css"], result["map"], result["warnings"])
51
49
  end
52
50
 
53
51
  # Return, which browsers and prefixes will be used
54
52
  def info
55
- runtime.eval("autoprefixer(#{ js_params }).info()")
53
+ runtime.call("autoprefixer.info", params_with_browsers)
56
54
  end
57
55
 
58
56
  # Parse Browserslist config
59
57
  def parse_config(config)
60
- sections = { 'defaults' => [] }
61
- current = 'defaults'
62
- config.gsub(/#[^\n]*/, '')
58
+ sections = { "defaults" => [] }
59
+ current = "defaults"
60
+ config.gsub(/#[^\n]*/, "")
63
61
  .split(/\n/)
64
62
  .map(&:strip)
65
63
  .reject(&:empty?)
66
64
  .each do |line|
67
- if line =~ IS_SECTION
68
- current = line.match(IS_SECTION)[1].strip
69
- sections[current] ||= []
70
- else
71
- sections[current] << line
72
- end
73
- end
65
+ if IS_SECTION =~ line
66
+ current = line.match(IS_SECTION)[1].strip
67
+ sections[current] ||= []
68
+ else
69
+ sections[current] << line
70
+ end
71
+ end
74
72
  sections
75
73
  end
76
74
 
77
75
  private
78
76
 
79
77
  def params_with_browsers(from = nil)
80
- unless from
81
- if defined? Rails and Rails.respond_to?(:root) and Rails.root
82
- from = Rails.root.join('app/assets/stylesheets').to_s
83
- else
84
- from = '.'
85
- end
86
- end
78
+ from ||= if defined?(Rails) && Rails.respond_to?(:root) && Rails.root
79
+ Rails.root.join("app/assets/stylesheets").to_s
80
+ else
81
+ "."
82
+ end
87
83
 
88
84
  params = @params
89
- if not params.has_key?(:browsers) and from
85
+ if !params.key?(:browsers) && !params.key?(:overrideBrowserslist) && from
90
86
  file = find_config(from)
91
87
  if file
92
- env = params[:env].to_s || 'development'
88
+ env = params[:env].to_s || "development"
93
89
  config = parse_config(file)
94
90
  params = params.dup
95
- if config[env]
96
- params[:browsers] = config[env]
97
- else
98
- params[:browsers] = config['defaults']
99
- end
91
+ params[:overrideBrowserslist] = (config[env] || config["defaults"])
100
92
  end
101
93
  end
102
94
 
103
95
  params
104
96
  end
105
97
 
106
- # Convert params to JS string and add browsers from Browserslist config
107
- def js_params
108
- '{ ' +
109
- params_with_browsers.map { |k, v| "#{k}: #{v.inspect}"}.join(', ') +
110
- ' }'
111
- end
112
-
113
98
  # Convert ruby_options to jsOptions
114
99
  def convert_options(opts)
115
- converted = { }
100
+ converted = {}
116
101
 
117
102
  opts.each_pair do |name, value|
118
- if name =~ /_/
119
- name = name.to_s.gsub(/_\w/) { |i| i.gsub('_', '').upcase }.to_sym
103
+ if /_/ =~ name
104
+ name = name.to_s.gsub(/_\w/) { |i| i.delete("_").upcase }.to_sym
120
105
  end
121
106
  value = convert_options(value) if value.is_a? Hash
122
107
  converted[name] = value
@@ -130,11 +115,11 @@ module AutoprefixerRails
130
115
  path = Pathname(file).expand_path
131
116
 
132
117
  while path.parent != path
133
- config1 = path.join('browserslist')
134
- return config1.read if config1.exist? and not config1.directory?
118
+ config1 = path.join("browserslist")
119
+ return config1.read if config1.exist? && !config1.directory?
135
120
 
136
- config2 = path.join('.browserslistrc')
137
- return config2.read if config2.exist? and not config1.directory?
121
+ config2 = path.join(".browserslistrc")
122
+ return config2.read if config2.exist? && !config1.directory?
138
123
 
139
124
  path = path.parent
140
125
  end
@@ -145,57 +130,36 @@ module AutoprefixerRails
145
130
  # Lazy load for JS library
146
131
  def runtime
147
132
  @runtime ||= begin
148
- if ExecJS.eval('typeof Uint8Array') != 'function'
149
- if ExecJS.runtime.name.start_with?('therubyracer')
150
- raise "ExecJS::RubyRacerRuntime is not supported. " +
151
- "Please replace therubyracer with mini_racer " +
152
- "in your Gemfile or use Node.js as ExecJS runtime."
153
- else
154
- raise "#{ExecJS.runtime.name} runtime does’t support ES6. " +
155
- "Please update or replace your current ExecJS runtime."
156
- end
157
- end
158
-
159
- if ExecJS.runtime == ExecJS::Runtimes::Node
160
- version = ExecJS.runtime.eval('process.version')
161
- first = version.match(/^v(\d+)/)[1].to_i
162
- if first < 6
163
- raise "Autoprefixer doesn’t support Node #{ version }. Update it."
164
- end
165
- end
166
-
167
133
  ExecJS.compile(build_js)
134
+ rescue ExecJS::RuntimeError
135
+ # Only complain about unsupported runtimes when it failed to parse our script.
136
+
137
+ case ExecJS.runtime
138
+ when ExecJS::Runtimes::Node
139
+ node_command = ExecJS.runtime.send(:binary) rescue "Unknown"
140
+
141
+ raise <<~MSG
142
+ Your nodejs binary failed to load autoprefixer script file,
143
+ please check if you're running a supported version (10, 12, 14+)
144
+
145
+ ENV["PATH"] = #{ENV["PATH"]}
146
+ binary = #{node_command}
147
+ MSG
148
+ when *SUPPORTED_RUNTIMES
149
+ raise
150
+ else
151
+ raise <<~MSG
152
+ Your ExecJS runtime #{ExecJS.runtime.name} isn't supported by autoprefixer-rails,
153
+ please switch to #{SUPPORTED_RUNTIMES.map(&:name).join(' or ')}
154
+ MSG
155
+ end
168
156
  end
169
157
  end
170
158
 
171
- # Cache autoprefixer.js content
172
- def read_js
173
- @@js ||= begin
174
- root = Pathname(File.dirname(__FILE__))
175
- path = root.join("../../vendor/autoprefixer.js")
176
- path.read
177
- end
178
- end
179
-
180
- # Return processor JS with some extra methods
181
159
  def build_js
182
- 'var global = this;' + read_js + process_proxy
183
- end
184
-
185
- # Return JS code for process method proxy
186
- def process_proxy
187
- <<-JS
188
- var processor;
189
- var process = function() {
190
- var result = autoprefixer.process.apply(autoprefixer, arguments);
191
- var warns = result.warnings().map(function (i) {
192
- delete i.plugin;
193
- return i.toString();
194
- });
195
- var map = result.map ? result.map.toString() : null;
196
- return { css: result.css, map: map, warnings: warns };
197
- };
198
- JS
160
+ root = Pathname(File.dirname(__FILE__))
161
+ path = root.join("../../vendor/autoprefixer.js")
162
+ path.read
199
163
  end
200
164
  end
201
165
  end