browserslist 0.1.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 +7 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/LICENSE.txt +21 -0
- data/README.md +146 -0
- data/exe/browserslist +5 -0
- data/lib/browserslist/browsers.rb +92 -0
- data/lib/browserslist/cli.rb +74 -0
- data/lib/browserslist/configuration.rb +22 -0
- data/lib/browserslist/generator.rb +43 -0
- data/lib/browserslist/rake.rb +15 -0
- data/lib/browserslist/version.rb +5 -0
- data/lib/browserslist.rb +27 -0
- metadata +59 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 9e1ce91dfa243f4772858fff74007ef575b06a20b2ea01376f93efb468551df6
|
|
4
|
+
data.tar.gz: 1833f0572f2e06925a13d81d3d01a3a47166b2e1bbe9e130aad6b3f043fa8a3f
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: df291f6fe75afd776f77e1701df632a789c885b060ea85fa37d2ac7fa6db9219d08b95504e9064c9ab53cca5a07d3e71bc831a299224910ed58ebc45e1116e70
|
|
7
|
+
data.tar.gz: 8895668fed04949e9bbcd62b02c54c570b26c342516c09b568b01deba01ecbb41538c3f675d2c190ad669334ce956e1201a594ce534e53a5923cb752e3378507
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
|
9
|
+
nationality, personal appearance, race, caste, color, religion, or sexual
|
|
10
|
+
identity and orientation.
|
|
11
|
+
|
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
|
13
|
+
diverse, inclusive, and healthy community.
|
|
14
|
+
|
|
15
|
+
## Our Standards
|
|
16
|
+
|
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
|
18
|
+
community include:
|
|
19
|
+
|
|
20
|
+
* Demonstrating empathy and kindness toward other people
|
|
21
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
|
22
|
+
* Giving and gracefully accepting constructive feedback
|
|
23
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
|
24
|
+
and learning from the experience
|
|
25
|
+
* Focusing on what is best not just for us as individuals, but for the overall
|
|
26
|
+
community
|
|
27
|
+
|
|
28
|
+
Examples of unacceptable behavior include:
|
|
29
|
+
|
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or advances of
|
|
31
|
+
any kind
|
|
32
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
|
33
|
+
* Public or private harassment
|
|
34
|
+
* Publishing others' private information, such as a physical or email address,
|
|
35
|
+
without their explicit permission
|
|
36
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
37
|
+
professional setting
|
|
38
|
+
|
|
39
|
+
## Enforcement Responsibilities
|
|
40
|
+
|
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
|
44
|
+
or harmful.
|
|
45
|
+
|
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
|
49
|
+
decisions when appropriate.
|
|
50
|
+
|
|
51
|
+
## Scope
|
|
52
|
+
|
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
|
54
|
+
an individual is officially representing the community in public spaces.
|
|
55
|
+
Examples of representing our community include using an official email address,
|
|
56
|
+
posting via an official social media account, or acting as an appointed
|
|
57
|
+
representative at an online or offline event.
|
|
58
|
+
|
|
59
|
+
## Enforcement
|
|
60
|
+
|
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
62
|
+
reported to the community leaders responsible for enforcement at
|
|
63
|
+
[INSERT CONTACT METHOD].
|
|
64
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
|
65
|
+
|
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
|
67
|
+
reporter of any incident.
|
|
68
|
+
|
|
69
|
+
## Enforcement Guidelines
|
|
70
|
+
|
|
71
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
|
72
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
|
73
|
+
|
|
74
|
+
### 1. Correction
|
|
75
|
+
|
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
|
77
|
+
unprofessional or unwelcome in the community.
|
|
78
|
+
|
|
79
|
+
**Consequence**: A private, written warning from community leaders, providing
|
|
80
|
+
clarity around the nature of the violation and an explanation of why the
|
|
81
|
+
behavior was inappropriate. A public apology may be requested.
|
|
82
|
+
|
|
83
|
+
### 2. Warning
|
|
84
|
+
|
|
85
|
+
**Community Impact**: A violation through a single incident or series of
|
|
86
|
+
actions.
|
|
87
|
+
|
|
88
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
|
89
|
+
interaction with the people involved, including unsolicited interaction with
|
|
90
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
|
91
|
+
includes avoiding interactions in community spaces as well as external channels
|
|
92
|
+
like social media. Violating these terms may lead to a temporary or permanent
|
|
93
|
+
ban.
|
|
94
|
+
|
|
95
|
+
### 3. Temporary Ban
|
|
96
|
+
|
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
|
98
|
+
sustained inappropriate behavior.
|
|
99
|
+
|
|
100
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
|
101
|
+
communication with the community for a specified period of time. No public or
|
|
102
|
+
private interaction with the people involved, including unsolicited interaction
|
|
103
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
|
104
|
+
Violating these terms may lead to a permanent ban.
|
|
105
|
+
|
|
106
|
+
### 4. Permanent Ban
|
|
107
|
+
|
|
108
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
|
109
|
+
standards, including sustained inappropriate behavior, harassment of an
|
|
110
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
|
111
|
+
|
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within the
|
|
113
|
+
community.
|
|
114
|
+
|
|
115
|
+
## Attribution
|
|
116
|
+
|
|
117
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
|
118
|
+
version 2.1, available at
|
|
119
|
+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
|
120
|
+
|
|
121
|
+
Community Impact Guidelines were inspired by
|
|
122
|
+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
|
123
|
+
|
|
124
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
|
125
|
+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
|
126
|
+
[https://www.contributor-covenant.org/translations][translations].
|
|
127
|
+
|
|
128
|
+
[homepage]: https://www.contributor-covenant.org
|
|
129
|
+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
|
130
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
|
131
|
+
[FAQ]: https://www.contributor-covenant.org/faq
|
|
132
|
+
[translations]: https://www.contributor-covenant.org/translations
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 hschne
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# Browserslist Ruby
|
|
2
|
+
|
|
3
|
+
Bring [browserslist](https://github.com/browserslist/browserslist) to Ruby. Use your existing browserslist config and convert it to a Ruby hash for use with [Rails allowed browsers](https://github.com/rails/rails/pull/50505).
|
|
4
|
+
|
|
5
|
+
```ruby
|
|
6
|
+
allow_browser versions: Browserslist.browsers
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
Add `browserslist` to your `Gemfile`:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
bundle add browserslist
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
### Generating a Browserslist
|
|
20
|
+
|
|
21
|
+
`browserslist-rb` reads from a `.browserslist.json` file that must be generated upfront or at build time. This gem ships with a generator that requires `npm/npx` to be installed. If you generate the file upfront you must make sure it's available at runtime.
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
# Generate default .browserslist.json file
|
|
25
|
+
bundle exec browserslist generate
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
#### Build-Time Generation
|
|
29
|
+
|
|
30
|
+
For Rails applications using modern bundlers, you can generate the browserslist file at build time, depending on your tooling.
|
|
31
|
+
|
|
32
|
+
<details>
|
|
33
|
+
<summary>Vite Ruby</summary>
|
|
34
|
+
|
|
35
|
+
Add to `vite.config.ts` using a plugin:
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
import { defineConfig } from 'vite'
|
|
39
|
+
import { execSync } from 'child_process'
|
|
40
|
+
|
|
41
|
+
export default defineConfig({
|
|
42
|
+
plugins: [
|
|
43
|
+
{
|
|
44
|
+
name: 'browserslist-generator',
|
|
45
|
+
configResolved() {
|
|
46
|
+
execSync('npx browserslist --json > .browserslist.json')
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
})
|
|
51
|
+
```
|
|
52
|
+
</details>
|
|
53
|
+
|
|
54
|
+
<details>
|
|
55
|
+
<summary>esbuild</summary>
|
|
56
|
+
|
|
57
|
+
Use a build plugin in your esbuild configuration:
|
|
58
|
+
|
|
59
|
+
```javascript
|
|
60
|
+
require('esbuild').build({
|
|
61
|
+
plugins: [{
|
|
62
|
+
name: 'browserslist-generator',
|
|
63
|
+
setup(build) {
|
|
64
|
+
build.onStart(() => {
|
|
65
|
+
const browserslist = require('browserslist')
|
|
66
|
+
const fs = require('fs')
|
|
67
|
+
fs.writeFileSync('./.browserslist.json', JSON.stringify(browserslist()))
|
|
68
|
+
})
|
|
69
|
+
}
|
|
70
|
+
}]
|
|
71
|
+
})
|
|
72
|
+
```
|
|
73
|
+
</details>
|
|
74
|
+
|
|
75
|
+
<details>
|
|
76
|
+
<summary>Asset Precompilation</summary>
|
|
77
|
+
|
|
78
|
+
You may use the built-in rake task to hook into your asset precompilation process. First require the Rake tasks, then enhance your asset precompilation. Add this to your `lib/tasks/assets.rake`:
|
|
79
|
+
|
|
80
|
+
```ruby
|
|
81
|
+
require 'browserslist/rake'
|
|
82
|
+
|
|
83
|
+
Rake::Task['assets:precompile'].enhance(['browserslist:update'])
|
|
84
|
+
```
|
|
85
|
+
</details>
|
|
86
|
+
|
|
87
|
+
### Using the API
|
|
88
|
+
|
|
89
|
+
Once you have generated your browserslist file, the gem provides a hash of minimum required browser versions:
|
|
90
|
+
|
|
91
|
+
```ruby
|
|
92
|
+
Browserslist.browsers
|
|
93
|
+
# => {chrome: 119.0, firefox: 128.0, edge: 138.0, safari: 18.4, opera: 80.0, ie: false}
|
|
94
|
+
```
|
|
95
|
+
For example with Rails 8.0+ allowed browsers:
|
|
96
|
+
|
|
97
|
+
```ruby
|
|
98
|
+
allow_browser versions: Browserslist.browsers
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
You may preview the resulting hash using
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
bundle exec browserslist browsers
|
|
105
|
+
# => {chrome: 119.0, firefox: 128.0, edge: 138.0, safari: 18.4, opera: 80.0, ie: false}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
## Configuration
|
|
110
|
+
|
|
111
|
+
Configure the gem like so:
|
|
112
|
+
|
|
113
|
+
```ruby
|
|
114
|
+
Browserslist.configure do |config|
|
|
115
|
+
# Set custom file path
|
|
116
|
+
config.file_path = ".browserslist.json"
|
|
117
|
+
|
|
118
|
+
# Enable/disable strict mode
|
|
119
|
+
# When strict mode is enabled, missing browsers hash value will be set to false, which in conjunction with `allow_browser` means they will be forbidden from accessing your application.
|
|
120
|
+
config.strict = true
|
|
121
|
+
end
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Browser Support
|
|
125
|
+
|
|
126
|
+
The gem supports these browsers:
|
|
127
|
+
- **Chrome** (`chrome`, `and_chr`)
|
|
128
|
+
- **Firefox** (`firefox`, `and_ff`)
|
|
129
|
+
- **Safari** (`safari`, `ios_saf`)
|
|
130
|
+
- **Edge** (`edge`)
|
|
131
|
+
- **Opera** (`opera`, `op_mob`)
|
|
132
|
+
- **Internet Explorer** (`ie`)
|
|
133
|
+
|
|
134
|
+
## Development
|
|
135
|
+
|
|
136
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt.
|
|
137
|
+
|
|
138
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
|
139
|
+
|
|
140
|
+
## Contributing
|
|
141
|
+
|
|
142
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/hschne/browserslist-rb.
|
|
143
|
+
|
|
144
|
+
## License
|
|
145
|
+
|
|
146
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/exe/browserslist
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "json"
|
|
4
|
+
|
|
5
|
+
module Browserslist
|
|
6
|
+
class Browsers
|
|
7
|
+
def self.parse(content = nil)
|
|
8
|
+
new.parse(content)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def parse(content = nil)
|
|
12
|
+
content ||= file_contents
|
|
13
|
+
return {} if content.nil?
|
|
14
|
+
|
|
15
|
+
parse_content(content)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def file_contents
|
|
19
|
+
file_path = Browserslist.configuration.file_path
|
|
20
|
+
|
|
21
|
+
unless File.exist?(file_path)
|
|
22
|
+
puts "Warning: Browserslist file '#{file_path}' not found. Run 'browserslist:update' to generate it."
|
|
23
|
+
return nil
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
File.read(file_path)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def parse_content(file_content)
|
|
32
|
+
parsed_json = JSON.parse(file_content)
|
|
33
|
+
browser_list = parsed_json["browsers"]
|
|
34
|
+
|
|
35
|
+
result = {}
|
|
36
|
+
browser_list.each do |browser_version|
|
|
37
|
+
browser, version = browser_version.split(" ", 2)
|
|
38
|
+
next unless browser && version
|
|
39
|
+
|
|
40
|
+
normalized_browser = normalize_browser_name(browser)
|
|
41
|
+
next if normalized_browser.nil?
|
|
42
|
+
|
|
43
|
+
clean_version = extract_min_version(version)
|
|
44
|
+
gem_version = Gem::Version.new(clean_version)
|
|
45
|
+
|
|
46
|
+
if result[normalized_browser].nil? || gem_version < Gem::Version.new(result[normalized_browser].to_s)
|
|
47
|
+
result[normalized_browser] = gem_version.version.to_f
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
add_missing_browsers_if_strict(result)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def add_missing_browsers_if_strict(result)
|
|
55
|
+
return result unless Browserslist.configuration.strict
|
|
56
|
+
|
|
57
|
+
all_browsers = [:chrome, :firefox, :safari, :edge, :opera, :ie]
|
|
58
|
+
|
|
59
|
+
all_browsers.each do |browser|
|
|
60
|
+
result[browser] = false unless result.key?(browser)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
result
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def normalize_browser_name(browser)
|
|
67
|
+
case browser
|
|
68
|
+
when "chrome", "and_chr"
|
|
69
|
+
:chrome
|
|
70
|
+
when "firefox", "and_ff"
|
|
71
|
+
:firefox
|
|
72
|
+
when "safari", "ios_saf"
|
|
73
|
+
:safari
|
|
74
|
+
when "edge"
|
|
75
|
+
:edge
|
|
76
|
+
when "opera", "op_mob"
|
|
77
|
+
:opera
|
|
78
|
+
when "ie"
|
|
79
|
+
:ie
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def extract_min_version(version_string)
|
|
84
|
+
if version_string.include?("-")
|
|
85
|
+
min_version, _max_version = version_string.split("-", 2)
|
|
86
|
+
min_version
|
|
87
|
+
else
|
|
88
|
+
version_string
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "optparse"
|
|
4
|
+
|
|
5
|
+
module Browserslist
|
|
6
|
+
class Cli
|
|
7
|
+
def initialize(argv)
|
|
8
|
+
@argv = argv.dup
|
|
9
|
+
@options = {}
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def run
|
|
13
|
+
parser.parse!(@argv)
|
|
14
|
+
|
|
15
|
+
case @argv[0]
|
|
16
|
+
when "generate", nil
|
|
17
|
+
generate_command
|
|
18
|
+
when "browsers"
|
|
19
|
+
browsers_command
|
|
20
|
+
else
|
|
21
|
+
puts "Unknown command: #{@argv[0]}"
|
|
22
|
+
puts parser.help
|
|
23
|
+
exit 1
|
|
24
|
+
end
|
|
25
|
+
rescue Browserslist::Error => e
|
|
26
|
+
puts "Error: #{e.message}"
|
|
27
|
+
exit 1
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
def parser
|
|
33
|
+
@parser ||= OptionParser.new do |opts|
|
|
34
|
+
opts.banner = <<~BANNER
|
|
35
|
+
Usage: browserslist [command] [options]
|
|
36
|
+
|
|
37
|
+
Commands:
|
|
38
|
+
generate [query] Generate .browserslist.json file
|
|
39
|
+
browsers Show supported browsers (from existing file)
|
|
40
|
+
|
|
41
|
+
Options:
|
|
42
|
+
BANNER
|
|
43
|
+
|
|
44
|
+
opts.on("-f", "--file PATH", "Output file path (default: .browserslist.json)") do |path|
|
|
45
|
+
@options[:file_path] = path
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
opts.on("-h", "--help", "Show this help") do
|
|
49
|
+
puts opts
|
|
50
|
+
exit
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def generate_command
|
|
56
|
+
query = @argv[1]
|
|
57
|
+
@options[:query] = query if query
|
|
58
|
+
|
|
59
|
+
file_path = Browserslist.generate(@options)
|
|
60
|
+
puts "Generated browserslist file: #{file_path}"
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def browsers_command
|
|
64
|
+
browsers = Browserslist.browsers
|
|
65
|
+
|
|
66
|
+
if browsers.empty?
|
|
67
|
+
puts "No browsers found. Run 'browserslist generate' first."
|
|
68
|
+
exit 1
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
puts browsers.inspect
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Browserslist
|
|
4
|
+
class Configuration
|
|
5
|
+
DEFAULT_FILE_PATH = ".browserslist.json"
|
|
6
|
+
|
|
7
|
+
attr_accessor :file_path, :strict
|
|
8
|
+
|
|
9
|
+
def initialize
|
|
10
|
+
@file_path = DEFAULT_FILE_PATH
|
|
11
|
+
@strict = true
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def self.instance
|
|
15
|
+
@instance ||= new
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def self.configure
|
|
19
|
+
yield(instance) if block_given?
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "open3"
|
|
4
|
+
|
|
5
|
+
module Browserslist
|
|
6
|
+
class Generator
|
|
7
|
+
def self.generate(options = {})
|
|
8
|
+
new.generate(options)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def generate(options = {})
|
|
12
|
+
query = options[:query]
|
|
13
|
+
file_path = options[:file_path] || Browserslist.configuration.file_path
|
|
14
|
+
|
|
15
|
+
output = fetch_browserslist_data(query)
|
|
16
|
+
File.write(file_path, output)
|
|
17
|
+
file_path
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
def fetch_browserslist_data(query = nil)
|
|
23
|
+
check_npx_availability!
|
|
24
|
+
|
|
25
|
+
cmd = ["npx", "browserslist", "--json"]
|
|
26
|
+
cmd << query if query
|
|
27
|
+
|
|
28
|
+
stdout, stderr, status = Open3.capture3(*cmd)
|
|
29
|
+
|
|
30
|
+
if status.success?
|
|
31
|
+
stdout.strip
|
|
32
|
+
else
|
|
33
|
+
raise Error, "Failed to run browserslist: #{stderr}"
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def check_npx_availability!
|
|
38
|
+
return if system("which npx > /dev/null 2>&1")
|
|
39
|
+
|
|
40
|
+
raise Error, "npx is not available. Please install Node.js and npm."
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../browserslist"
|
|
4
|
+
|
|
5
|
+
namespace :browserslist do
|
|
6
|
+
desc "Generate .browserslist.json file"
|
|
7
|
+
task :update do
|
|
8
|
+
file_path = Browserslist.generate
|
|
9
|
+
puts "Generated browserslist file: #{file_path}"
|
|
10
|
+
rescue Browserslist::Error => e
|
|
11
|
+
puts "Error: #{e.message}"
|
|
12
|
+
exit 1
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
data/lib/browserslist.rb
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "browserslist/version"
|
|
4
|
+
require_relative "browserslist/configuration"
|
|
5
|
+
require_relative "browserslist/cli"
|
|
6
|
+
require_relative "browserslist/browsers"
|
|
7
|
+
require_relative "browserslist/generator"
|
|
8
|
+
|
|
9
|
+
module Browserslist
|
|
10
|
+
class Error < StandardError; end
|
|
11
|
+
|
|
12
|
+
def self.configuration
|
|
13
|
+
Configuration.instance
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.configure(&block)
|
|
17
|
+
Configuration.configure(&block)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def self.browsers
|
|
21
|
+
@browsers ||= Browsers.parse
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def self.generate(options = {})
|
|
25
|
+
Generator.generate(options)
|
|
26
|
+
end
|
|
27
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: browserslist
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- hschne
|
|
8
|
+
bindir: exe
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies: []
|
|
12
|
+
description: Bring browserslist to Ruby. Use your existing browserslist config and
|
|
13
|
+
convert it to a Ruby hash for use with Rails allowed browsers or other browser support
|
|
14
|
+
detection.
|
|
15
|
+
email:
|
|
16
|
+
- hello@hansschnedlitz.com
|
|
17
|
+
executables:
|
|
18
|
+
- browserslist
|
|
19
|
+
extensions: []
|
|
20
|
+
extra_rdoc_files: []
|
|
21
|
+
files:
|
|
22
|
+
- CHANGELOG.md
|
|
23
|
+
- CODE_OF_CONDUCT.md
|
|
24
|
+
- LICENSE.txt
|
|
25
|
+
- README.md
|
|
26
|
+
- exe/browserslist
|
|
27
|
+
- lib/browserslist.rb
|
|
28
|
+
- lib/browserslist/browsers.rb
|
|
29
|
+
- lib/browserslist/cli.rb
|
|
30
|
+
- lib/browserslist/configuration.rb
|
|
31
|
+
- lib/browserslist/generator.rb
|
|
32
|
+
- lib/browserslist/rake.rb
|
|
33
|
+
- lib/browserslist/version.rb
|
|
34
|
+
homepage: https://github.com/hschne/browserslist-rb
|
|
35
|
+
licenses:
|
|
36
|
+
- MIT
|
|
37
|
+
metadata:
|
|
38
|
+
allowed_push_host: https://rubygems.org
|
|
39
|
+
homepage_uri: https://github.com/hschne/browserslist-rb
|
|
40
|
+
source_code_uri: https://github.com/hschne/browserslist-rb
|
|
41
|
+
changelog_uri: https://github.com/hschne/browserslist-rb/blob/main/CHANGELOG.md
|
|
42
|
+
rdoc_options: []
|
|
43
|
+
require_paths:
|
|
44
|
+
- lib
|
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
46
|
+
requirements:
|
|
47
|
+
- - ">="
|
|
48
|
+
- !ruby/object:Gem::Version
|
|
49
|
+
version: 3.1.0
|
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
requirements: []
|
|
56
|
+
rubygems_version: 3.6.7
|
|
57
|
+
specification_version: 4
|
|
58
|
+
summary: Bring browserslist to Ruby
|
|
59
|
+
test_files: []
|