Skip to content

Commit d3aabd0

Browse files
committed
Release Ruby2JS 5.1 and announce in blog post
1 parent ff241e0 commit d3aabd0

File tree

19 files changed

+362
-176
lines changed

19 files changed

+362
-176
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## [Unreleased]
8+
## [5.1.0] - 2023-02-20
99

10+
- Many filters and other project features deprecated for future maintainability (see [blog announcement](https://www.ruby2js.com/updates/future-of-ruby2js/)).
11+
- The Vite and Rollup JS packages are looking for a new maintainer. Please let us know in the [community GitHub Discussions](https://github.com/ruby2js/ruby2js/discussions) if you'd like to contribute.
12+
- The Node version of Ruby2JS will require minimum version 14
1013
- Create a preset option to set sane default behavior [#178]
1114
- New configuration DSL and per-file magic comments [#182]
1215
- esbuild: change to use Ruby platform for Ruby2JS compilation [#183]

README.md

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,7 @@ Basic:
2020

2121
```ruby
2222
require 'ruby2js'
23-
puts Ruby2JS.convert("a={age:3}\na.age+=1")
24-
```
25-
26-
With filter:
27-
28-
```ruby
29-
require 'ruby2js/filter/functions'
30-
puts Ruby2JS.convert('"2A".to_i(16)')
31-
```
32-
33-
Host variable substitution:
34-
35-
```ruby
36-
puts Ruby2JS.convert("@name", ivars: {:@name => "Joe"})
37-
```
38-
39-
Enable ES2015 support:
40-
41-
```ruby
42-
puts Ruby2JS.convert('"#{a}"', eslevel: 2015)
23+
puts Ruby2JS.convert("a={age:3}\na.age+=1", preset: true)
4324
```
4425

4526
## Testing

Rakefile

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,6 @@ namespace :packages do
4040
sh "cp ../ruby2js/ruby2js.js #{npm_root}/@ruby2js/ruby2js/ruby2js.js"
4141
sh 'yarn test'
4242
end
43-
44-
Dir.chdir 'packages/webpack-loader' do
45-
npm_root = `npm root`.strip
46-
sh 'yarn install' unless File.exist? 'yarn.lock'
47-
sh "cp ../ruby2js/ruby2js.js #{npm_root}/@ruby2js/ruby2js/ruby2js.js"
48-
sh 'yarn prepare-release'
49-
sh 'yarn test'
50-
end
5143
end
5244
end
5345

docs/Rakefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
require "bridgetown"
1+
begin
2+
require "bridgetown"
23

3-
Bridgetown.load_tasks
4+
Bridgetown.load_tasks
5+
rescue LoadError => e
6+
puts "Warning: Bridgetown gem not available in this environment. (OK when compiling JS packages)"
7+
end
48

59
#
610
# Standard set of tasks, which you can customize if you wish:

docs/src/_docs/filters/esm.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,7 @@ this function returns `nil`, then no imports will be added.
108108
The esm filter is able to recognize if you are defining a class or function
109109
within the code itself and it won't add that import statement accordingly.
110110
If for some reason you wish to disable autoimports entirely on a file-by-file
111-
basis (for instance when using the Webpack loader), you can add a magic comment
112-
to the top of the code:
111+
basis, you can add a magic comment to the top of the code:
113112

114113
```ruby
115114
require "ruby2js/filter/esm"

docs/src/_docs/filters/matchall.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ top_section: Deprecations
55
category: matchall
66
---
77

8+
{% rendercontent "docs/note", type: "warning" %}
9+
This filter has been deprecated and will be removed in Ruby2JS 6.0.
10+
{% endrendercontent %}
11+
812
For ES level < 2020:
913

1014
* maps `str.matchAll(pattern).forEach {}` to

docs/src/_docs/index.md

Lines changed: 13 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,16 @@ require 'ruby2js'
2929
puts Ruby2JS.convert("a={age:3}\na.age+=1")
3030
```
3131

32-
With filter:
32+
With our recommended "preset" configuration:
3333

3434
```ruby
35-
require 'ruby2js/filter/functions'
36-
puts Ruby2JS.convert('"2A".to_i(16)')
35+
puts Ruby2JS.convert("a={age:3}\na.age+=1", preset: true)
36+
```
37+
38+
With just the functions filter:
39+
40+
```ruby
41+
puts Ruby2JS.convert('"2A".to_i(16)', filters: [:functions])
3742
```
3843

3944
Host variable substitution:
@@ -42,23 +47,17 @@ Host variable substitution:
4247
puts Ruby2JS.convert("@name", ivars: {:@name => "Joe"})
4348
```
4449

45-
Enable ES2015 support:
50+
Enable ES2021 support (default with the preset configuration):
4651

4752
```ruby
48-
puts Ruby2JS.convert('"#{a}"', eslevel: 2015)
53+
puts Ruby2JS.convert('"#{a}"', eslevel: 2020)
4954
```
5055

5156
{% rendercontent "docs/note" %}
5257
[Read more information](/docs/eslevels) on how ES level options affect the JS output.
5358
{% endrendercontent %}
5459

55-
Enable strict support:
56-
57-
```ruby
58-
puts Ruby2JS.convert('a=1', strict: true)
59-
```
60-
61-
Emit strict equality comparisons:
60+
Emit strict equality comparisons (aka `==` becomes `===`):
6261

6362
```ruby
6463
puts Ruby2JS.convert('a==1', comparison: :identity)
@@ -79,65 +78,7 @@ puts Ruby2JS.convert('class C; def initialize; @f=1; end; end',
7978

8079
{% rendercontent "docs/note", extra_margin: true %}
8180
Conversions can be explored interactively using the
82-
[demo](/docs/running-the-demo) provided. (**[Online Version](/demo)**)
81+
[demo](/docs/running-the-demo) provided. (**[Try It Online](/demo?preset=true)**)
8382
{% endrendercontent %}
8483

85-
## Create a Configuration
86-
87-
There are a number of [configuration options](/docs/options) available for both the converter itself as well as any filters you choose to add.
88-
89-
If you find yourself needing a centralized location to specify these options for your project, create an `rb2js.config.rb` file in your project root. Example:
90-
91-
```ruby
92-
require "ruby2js/filter/functions"
93-
require "ruby2js/filter/camelCase"
94-
require "ruby2js/filter/return"
95-
require "ruby2js/filter/esm"
96-
require "ruby2js/filter/tagged_templates"
97-
98-
require "json"
99-
100-
module Ruby2JS
101-
class Loader
102-
def self.options
103-
# Change the options for your configuration here:
104-
{
105-
eslevel: 2021,
106-
include: :class,
107-
underscored_private: true
108-
}
109-
end
110-
111-
def self.process(source)
112-
Ruby2JS.convert(source, self.options).to_s
113-
end
114-
115-
def self.process_with_source_map(source)
116-
conv = Ruby2JS.convert(source, self.options)
117-
{
118-
code: conv.to_s,
119-
sourceMap: conv.sourcemap
120-
}.to_json
121-
end
122-
end
123-
end
124-
```
125-
126-
Then you can simply require this file from inside your project.
127-
128-
```ruby
129-
# some_other_script.rb
130-
131-
require_relative "./rb2js.config"
132-
133-
ruby_code = <<~RUBY
134-
export toggle_menu_icon = ->(button) do
135-
button.query_selector_all(".icon").each do |item|
136-
item.class_list.toggle "not-shown"
137-
end
138-
button.query_selector(".icon:not(.not-shown)").class_list.add("shown")
139-
end
140-
RUBY
141-
142-
js_code = Ruby2JS::Loader.process(ruby_code)
143-
```
84+
Continue to the next page to learn all about how to use the "preset" configuration or build your own.

docs/src/_docs/integrations.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ category: integrations
66
---
77

88
{% rendercontent "docs/note", type: "warning" %}
9-
Heads up: we're in the process of consolidating our supported tech stack. Going forward we'll primarily focus on frontend code compiled via esbuild, which can work in Rails, Bridgetown, and other web projects. (And of course you can build more elaborate solutions using the [CLI](/docs/cli) or direct Ruby API.)
9+
Heads up: we're in the process of consolidating our supported tech stack. Going forward we'll primarily focus on [frontend code compiled via esbuild](https://github.com/ruby2js/ruby2js/tree/master/packages/esbuild-plugin), which can work in Rails, Bridgetown, and other web projects. (And of course you can build more elaborate solutions using the [CLI](/docs/cli) or direct Ruby API.) [Read the announcement for further details.](/updates/future-of-ruby2js/)
1010
{% endrendercontent %}
1111

1212
# Ruby back-end servers

0 commit comments

Comments
 (0)