wasmify-rails 0.1.3 → 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: 683d693ae789d6a5681cbab9e6f66f8a8fbd52a23d4dc440ff78d14e13c3085d
4
- data.tar.gz: e8c18abb0382cbec70d562debbf4f16d82eeece71c9dcdb0a82f916216c3f7a5
3
+ metadata.gz: d34168c0b9ab6af658deb9e91559fc45ff5d17bb7d015ef8859c216ab9736b41
4
+ data.tar.gz: 7049aa93891ea2fde7f911ed87d5f0356f01f99769b77a430aae69dd9db2b8c4
5
5
  SHA512:
6
- metadata.gz: d7aafd09c3e716080f96efa987aeb1825ab5307be9cc1dae32e657f30a4f40314fd65e4ec610b8f271c40b3cd7ad0c951eff9be5cc9e3cd80456edaedec19a6c
7
- data.tar.gz: 44619a0600d773ecd96e9f012b0245d6567e5d140b04397577560665ae5b49a9f7983755431f644274ebdb6dc76a3e33c91bf37eee5da56d8e4bfdc8f70a9e9b
6
+ metadata.gz: 43003eafb292715b34a9360426a2f8cd4bc572f8ce9f0494a19999abe48487fa766656bfa6da57bfa3a9e1ab74bb2b1e41db9191208015a85699364e1a9eda29
7
+ data.tar.gz: 8879ab43592abc34a0675d7e80763e9030b86cd2145535ec26fe0446465379d0c10f3a7c685d47b4a8165abe6e94714987ad8774ff3e16ce781abaea21699a35
data/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
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
+
5
11
  ## 0.1.3
6
12
 
7
13
  - Check if `cookieStore` is available and only manipulate cookies if it is.
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
@@ -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": {
@@ -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.3"
5
+ VERSION = "0.1.4"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wasmify-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Dementyev