wasmify-rails 0.1.2 → 0.1.4

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: 67904120ba3d147d07ad14d5e15c6f9faf06eb43f3c93d132326407581be4ad7
4
- data.tar.gz: c88da10a277060fcda66faa34f1334dc246870d4ab0d32655772d0b05ed534a2
3
+ metadata.gz: d34168c0b9ab6af658deb9e91559fc45ff5d17bb7d015ef8859c216ab9736b41
4
+ data.tar.gz: 7049aa93891ea2fde7f911ed87d5f0356f01f99769b77a430aae69dd9db2b8c4
5
5
  SHA512:
6
- metadata.gz: 78a1328a1ee3339968a6715b1482012f77dff692b69a55062a7c0eb1c460a7c631c617149a863eac7771c5dcccbd3673fa4fb18ca916005e215615db50bea210
7
- data.tar.gz: f128859e3c1f7e5ab2eee405afe71e7a5bd9fd593cfe88dae69cf6dd91f70b837c2bfe42364b95da2a1d60507776e28123dc7389a48231f720a5b9acbd599f80
6
+ metadata.gz: 43003eafb292715b34a9360426a2f8cd4bc572f8ce9f0494a19999abe48487fa766656bfa6da57bfa3a9e1ab74bb2b1e41db9191208015a85699364e1a9eda29
7
+ data.tar.gz: 8879ab43592abc34a0675d7e80763e9030b86cd2145535ec26fe0446465379d0c10f3a7c685d47b4a8165abe6e94714987ad8774ff3e16ce781abaea21699a35
data/CHANGELOG.md CHANGED
@@ -2,6 +2,18 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 0.1.4
6
+
7
+ - Improve `wasmify:install`.
8
+
9
+ Make it work with the `rails new` app without any manual steps.
10
+
11
+ ## 0.1.3
12
+
13
+ - Check if `cookieStore` is available and only manipulate cookies if it is.
14
+
15
+ - Add `skipWaiting()` to the server worker to force the new version to take over.
16
+
5
17
  ## 0.1.2
6
18
 
7
19
  - Add cache support to Rack handler.
data/README.md CHANGED
@@ -31,6 +31,8 @@ The script will tweak you configuration files and create a couple of new ones:
31
31
 
32
32
  - `config/wasmify.yml` — this is a configuration file for different _wasmify_ commands (see below).
33
33
 
34
+ It also adds the `wasm` group to your Gemfile (see below on that).
35
+
34
36
  ### Step 2: `bin/rails wasmify:build:core`
35
37
 
36
38
  Now, it's time to build a ruby.wasm with all your project dependencies (from the Gemfile). This is gonna be a base Wasm module
@@ -57,7 +59,9 @@ end
57
59
  ...
58
60
  ```
59
61
 
60
- **NOTE:** If you use `ruby file: ".ruby-version"` in your Gemfile, you should probably configure the Ruby version for Wasm platform
62
+ We try to mark gems as wasm-compatible during the `wasmify:install` phase, but it's likely that you will need to adjust the Gemfile manually.
63
+
64
+ If you use `ruby file: ".ruby-version"` in your Gemfile, you should probably configure the Ruby version for Wasm platform
61
65
  a bit differently (since patch versions might not match). For example:
62
66
 
63
67
  ```ruby
@@ -68,6 +72,12 @@ else
68
72
  end
69
73
  ```
70
74
 
75
+ Or just disable the Ruby version check for the Wasm platform:
76
+
77
+ ```ruby
78
+ ruby file: ".ruby-version" unless RUBY_PLATFORM =~ /wasm/
79
+ ```
80
+
71
81
  Now, try to run the following command:
72
82
 
73
83
  ```sh
@@ -155,6 +165,8 @@ Here is an example app:
155
165
 
156
166
  This gem provides a variety of _adapters_ and plugins to make your Rails application Wasm-compatible:
157
167
 
168
+ - `Kernel#on_wasm?`: a convenient predicate method to check if the code is running in the Wasm environment.
169
+
158
170
  - Active Record
159
171
 
160
172
  - `sqlite3_wasm` adapter: work with `sqlite3` Wasm just like with a regular SQLite database.
@@ -1,3 +1,14 @@
1
+ # Stub: SQLite3::ForkSafety.suppress_warnings!
2
+ module SQLite3
3
+ class BusyException < StandardError
4
+ end
5
+
6
+ module ForkSafety
7
+ def self.suppress_warnings!
8
+ end
9
+ end
10
+ end
11
+
1
12
  require "active_record/connection_adapters/sqlite3_adapter"
2
13
 
3
14
  module SQLite3
@@ -106,6 +117,8 @@ module ActiveRecord
106
117
  @rows
107
118
  end
108
119
 
120
+ def column_count = columns.size
121
+
109
122
  def execute
110
123
  return if @rows
111
124
 
@@ -54,25 +54,87 @@ class Wasmify::InstallGenerator < Rails::Generators::Base
54
54
 
55
55
  # Disable bootsnap if any
56
56
  inject_into_file "config/boot.rb", after: /require ['"]bootsnap\/setup['"]/ do
57
+ %q( unless ENV["RAILS_ENV"] == "wasm")
58
+ end
59
+ end
60
+
61
+ def disable_ruby_version_check_in_gemfile
62
+ inject_into_file "Gemfile", after: /^ruby[^#\n]+/ do
57
63
  " unless RUBY_PLATFORM =~ /wasm/"
58
64
  end
59
65
  end
60
66
 
61
67
  def add_tzinfo_data_to_gemfile
68
+ # First, comment out the existing tzinfo-data gem declaration
69
+ comment_lines "Gemfile", /^gem ['"]tzinfo-data['"]/
70
+
62
71
  append_to_file "Gemfile", <<~RUBY
63
72
 
64
73
  group :wasm do
65
74
  gem "tzinfo-data"
66
75
  end
67
76
  RUBY
77
+ end
68
78
 
69
- run "bundle install"
79
+ KNOWN_NO_WASM_GEMS = %w[
80
+ bootsnap
81
+ puma
82
+ sqlite3
83
+ activerecord-enhancedsqlite3-adapter
84
+ pg
85
+ mysql2
86
+ redis
87
+ solid_cable
88
+ solid_queue
89
+ solid_cache
90
+ jsbundling-rails
91
+ cssbundling-rails
92
+ thruster
93
+ kamal
94
+ byebug
95
+ web-console
96
+ listen
97
+ spring
98
+ debug
99
+ ].freeze
100
+
101
+ def add_wasm_group_to_gemfile
102
+ # This is a very straightforward implementation:
103
+ # - scan the Gemfile for _root_ dependencies (not within groups)
104
+ # - add `group: [:default, :wasm]` to those not from the exclude list
105
+
106
+ top_gems = []
107
+
108
+ File.read("Gemfile").then do |gemfile|
109
+ gemfile.scan(/^gem ['"]([^'"]+)['"](.*)$/).each do |match|
110
+ gem_name = match.first
111
+ top_gems << gem_name unless match.last&.include?(":wasm")
112
+ end
113
+ end
114
+
115
+ gems_to_include = top_gems - KNOWN_NO_WASM_GEMS
116
+
117
+ return if gems_to_include.empty?
118
+
119
+ regexp = /^gem ['"](?:#{gems_to_include.join("|")})['"][^#\n]*/
120
+
121
+ gsub_file "Gemfile", regexp do |match|
122
+ match << ", group: [:default, :wasm]"
123
+ end
124
+ end
125
+
126
+ def fix_solid_queeue_production_config
127
+ inject_into_file "config/environments/production.rb", after: %r{config.solid_queue.connects_to = [^#\n]+} do
128
+ " if config.respond_to?(:solid_queue)"
129
+ end
70
130
  end
71
131
 
72
132
  def finish
133
+ run "bundle install"
134
+
73
135
  say_status :info, "✅ The application is prepared for Wasm-ificaiton!\n\n" \
74
136
  "Next steps are:\n" \
75
- " - Gemfile: Add `group: [:default, :wasm]` to the dependencies required in Wasm runtime" \
137
+ " - Check your Gemfile: add `group: [:default, :wasm]` to the dependencies required in Wasm runtime" \
76
138
  " - Run `bin/rails wasmify:build:core:verify` to see if the bundle compiles"
77
139
  end
78
140
  end
@@ -10,7 +10,7 @@
10
10
  "preview": "vite preview"
11
11
  },
12
12
  "devDependencies": {
13
- "vite": "^5.4.7",
13
+ "vite": "^4.4.5",
14
14
  "vite-plugin-pwa": "^0.20.5"
15
15
  },
16
16
  "dependencies": {
@@ -71,7 +71,7 @@ self.addEventListener("activate", (event) => {
71
71
 
72
72
  self.addEventListener("install", (event) => {
73
73
  console.log("[rails-web] Install Service Worker");
74
- event.waitUntil(installApp());
74
+ event.waitUntil(installApp().then(() => self.skipWaiting()));
75
75
  });
76
76
 
77
77
  const rackHandler = new RackHandler(initVM, { assumeSSL: true });
@@ -2,6 +2,11 @@
2
2
 
3
3
  module Wasmify
4
4
  module Rails
5
+ RUBY_VERSION_TO_WASM_RUBY_VERSION = {
6
+ "3.3" => "3.3.3",
7
+ "3.2" => "3.2.4"
8
+ }
9
+
5
10
  class Configuration
6
11
  attr_reader :pack_directories, :exclude_gems, :ruby_version,
7
12
  :tmp_dir, :output_dir,
@@ -29,12 +34,16 @@ module Wasmify
29
34
  end
30
35
  end
31
36
 
37
+ def ruby_version = @ruby_version ||= ruby_version_from_file || "3.3"
38
+
32
39
  private
33
40
 
34
41
  def ruby_version_from_file
35
42
  return unless File.file?(::Rails.root.join(".ruby-version"))
36
43
 
37
- File.read(::Rails.root.join(".ruby-version")).strip
44
+ File.read(::Rails.root.join(".ruby-version")).strip.match(/(\d+\.\d+(?:\.d+)?)/).then do |matches|
45
+ matches[1] if matches
46
+ end
38
47
  end
39
48
  end
40
49
  end
@@ -14,7 +14,7 @@ namespace :wasmify do
14
14
  desc "Build ruby.wasm with all dependencies"
15
15
  task :build do
16
16
  unless ENV["BUNDLE_ONLY"] == "wasm"
17
- next spawn("BUNDLE_ONLY=wasm bundle exec rails wasmify:build").then { Process.wait(_1) }
17
+ next spawn("RAILS_ENV=wasm BUNDLE_ONLY=wasm bundle exec rails wasmify:build").then { Process.wait(_1) }
18
18
  end
19
19
 
20
20
  require "wasmify/rails/builder"
@@ -27,7 +27,7 @@ namespace :wasmify do
27
27
  desc "Build ruby.wasm with all dependencies but JS shim (to use with wasmtime)"
28
28
  task :core do
29
29
  unless ENV["BUNDLE_ONLY"] == "wasm"
30
- next spawn("BUNDLE_ONLY=wasm bundle exec rails wasmify:build:core").then { Process.wait(_1) }
30
+ next spawn("RAILS_ENV=wasm BUNDLE_ONLY=wasm bundle exec rails wasmify:build:core").then { Process.wait(_1) }
31
31
  end
32
32
 
33
33
  require "wasmify/rails/builder"
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Wasmify
4
4
  module Rails # :nodoc:
5
- VERSION = "0.1.2"
5
+ VERSION = "0.1.4"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wasmify-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Dementyev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-09-26 00:00:00.000000000 Z
11
+ date: 2024-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties