svelte-on-rails 1.0.12 → 1.0.14

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 89b585de2264458769d479f27bcadc4080a8984b23e916cccd5d07876a30ea24
4
- data.tar.gz: 7255f6af6ee943e809b24ba6551730e05dd21b8279555c677f7be2346d47a0f1
3
+ metadata.gz: bff57a06d326d5d82c6723869221aa21a47cb5d26e13c2d12100962610240b94
4
+ data.tar.gz: 589902ba14fd77b3c094a92ce2396a0edb0d5bfb8e81f23bf2250953f9d89da2
5
5
  SHA512:
6
- metadata.gz: 3557343363ea9f1776a6766eadcb97a3d8e6376ac069b1daa764cd77aa87a2f04614c91f3ed0b9d16a549b4ca7651ad82716d4b2374fc222c6d649d1e1c538c3
7
- data.tar.gz: 4f301fb16a422e682e75ca9ebf09a207474346ff973140191d8e92226bc9b284c04eaa3c3662f6745b83637b6db83752c8b5b4dcfa35deaec71eaa0d0ad1d973
6
+ metadata.gz: 35ee591f318848ca0918280f4c633f36896f530a443f97ff6e02444877e6b9b677aeb0a139503a8296f3f47fbb528dc5b60cb277721237d68c5100e1b048267d
7
+ data.tar.gz: c119240c35a8a0c74d9606a7cc651f37bb8c107fa9e96d18d8b20ce2b68018fa630d6f3749bd0ecb594834fc5cdf742fc4e1d2c1bfc0095e18d4074b38c9b105
data/README.md CHANGED
@@ -4,7 +4,14 @@
4
4
 
5
5
  ---
6
6
 
7
- Svelte is the missing peace for ambitious Rails frontends.
7
+ Do you want to combine DHH's [vision](https://rubyonrails.org/2021/12/15/Rails-7-fulfilling-a-vision)
8
+ with modern front-end requirements?
9
+
10
+ Svelte.
11
+
12
+ Vite.
13
+
14
+ Nothing else.
8
15
 
9
16
  # Why Svelte?
10
17
 
@@ -14,12 +21,12 @@ On every app there are parts where you want it to shine. This is where Svelte co
14
21
  - Perfect addition to Stimulus
15
22
  - Easy to learn
16
23
  - Powerful
24
+ - Super fast
17
25
  - **Compared to Stimulus**
18
26
  - No more writing double logic of the initial HTML state
19
- - Stimulus is good for parts where you have simple and little javascript and lots of html
20
- - The more complexity, the more you will love svelte
27
+ - Stimulus is great for rails views with some javascript, but, complex parts: Svelte. Nothing else.
21
28
  - **Compared to React**
22
- - No Shadow dom
29
+ - No more shadow dom and all those packages that are supposed to improve performance (e.g. useCallback...)
23
30
  - Slimmer packages
24
31
  - Easier to learn
25
32
  - Faster
@@ -27,12 +34,15 @@ On every app there are parts where you want it to shine. This is where Svelte co
27
34
  Have a look at this entertaining video [rethinking reactivity](https://svelte.dev/blog/svelte-3-rethinking-reactivity)
28
35
  by Rich Harris, especially from 3:50 to 6:40 and his comparison to react.
29
36
 
30
- This all fits perfectly with the Rails way of minimalist javascript, but: Where we need it, we have it.
37
+ This all fits in perfectly with the Rails way of minimalist javascript,
38
+ but: Where needed, we want full power.
31
39
 
32
40
  # Features
33
41
 
34
- - 🤝 fully integrated with `assets:precompile`
35
- - 🚀 cero-config deployment
42
+ - 🤝 Fully integrated with `assets:precompile`
43
+ - 🚀 Cero-config deployment
44
+ - ✍️ Sophisticated error messages
45
+ - 😍 Contributor friendly
36
46
 
37
47
  # Known Issues
38
48
 
@@ -189,7 +199,7 @@ The most importand rule is to firstly check all npm packages installed and passi
189
199
  ## Check if it all works
190
200
 
191
201
  Server Side Rendering (SSR) is a parallel pipeline to client side rendering.
192
- Both should return the same html. And your global styles should be applied same way
202
+ Both should return the same HTML. And your global styles should be applied same way
193
203
  for both cases. For normal use cases this is.
194
204
 
195
205
  For check the **ssr pipeline** you can pass the options `ssr: true` and `hydrate: false`
@@ -59,35 +59,50 @@ module SvelteOnRails
59
59
  def self.precompile(last_mtime = nil)
60
60
  config = SvelteOnRails::Configuration.instance
61
61
 
62
- mtime = (File.exist?(config.ssr_dist_folder.join('last_mtime')) ? File.read(config.ssr_dist_folder.join('last_mtime')).to_f : 0.0)
63
-
64
62
  Dir.chdir(config.rails_root) do
65
63
 
66
64
  # run build
67
65
 
68
66
  cmd = "./node_modules/.bin/vite build --config vite-ssr.config.ts"
67
+
69
68
  stdout, stderr, status = Open3.capture3(cmd)
70
- mtime2 = (File.exist?(config.ssr_dist_folder.join('last_mtime')) ? File.read(config.ssr_dist_folder.join('last_mtime')).to_f : 0.0)
69
+
70
+ warnings = stderr.to_s.split("\n")
71
+ errors_matcher = Regexp.new('(Could not resolve)')
72
+ error_lines = warnings.select { |e| e.match(errors_matcher) }
73
+ have_error = error_lines.present? || status.to_s.match(/exit 1/)
71
74
 
72
75
  # error handling
73
76
 
74
77
  if stderr.present?
75
78
 
76
- nothing_done = mtime2 == mtime
77
- color = (nothing_done ? "\033[97;41m" : "\033[30;106m")
78
-
79
- msg = " +++ #{nothing_done ? 'ERROR' : 'WARNING'} compiling Svelte components#{nothing_done ? ' failed' : ''} («#{cmd}») +++ "
80
- puts "#{color}#{msg}\033[0m"
81
- errs = stderr.split("\n")
82
- errs.each { |e| puts "#{color} \033[0m #{e}" }
83
- puts "#{color} +++ End of error message +++ \033[0m"
84
- puts "#{color} +++ Run «npm run build:ssr» on the console to see the original error message +++ \033[0m"
85
-
86
- if nothing_done
87
- critical_lines = errs.select { |e| e.match(/Could not resolve/i) }
88
- cl_str = if critical_lines.present?
89
- "#{critical_lines.join("\n")}\n\n"
90
- end
79
+ red_background = "\033[97;41m"
80
+ light_blue_background = "\033[30;106m"
81
+ clear_colors = "\033[0m"
82
+
83
+ msg = " +++ #{have_error ? 'ERROR' : 'WARNING'} compiling Svelte components#{have_error ? ' failed' : ''} («#{cmd}») +++ "
84
+ puts "#{have_error ? red_background : light_blue_background}#{msg}#{clear_colors}"
85
+
86
+ warnings.each do |e|
87
+ if e.match(errors_matcher)
88
+ red_font = "\033[31m"
89
+ puts "#{red_background} #{clear_colors}#{red_font} #{e}#{clear_colors}"
90
+ else
91
+ puts "#{light_blue_background} #{clear_colors}#{e}"
92
+ end
93
+ end
94
+
95
+ if have_error
96
+ puts "#{red_background} +++ End of error message +++ #{clear_colors}"
97
+ else
98
+ puts "#{light_blue_background} +++ End of compiling warnings +++ #{clear_colors}"
99
+ end
100
+ puts "#{have_error ? red_background : light_blue_background} +++ Run «npm run build:ssr» on the console to see the original error message +++ #{clear_colors}"
101
+
102
+ if have_error
103
+ cl_str = if error_lines.present?
104
+ "#{error_lines.join("\n")}\n\n"
105
+ end
91
106
  raise "Svelte components compilation failed\n\n#{cl_str}Full message:\n+++\n#{stderr}+++\n\nYou can run «npm run build:ssr» on the console to see the original error message\n"
92
107
  end
93
108
 
@@ -104,6 +119,7 @@ module SvelteOnRails
104
119
  mtime_path = config.ssr_dist_folder.join('last_mtime')
105
120
  File.write(mtime_path, last_mtime.to_s)
106
121
  end
122
+
107
123
  end
108
124
 
109
125
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: svelte-on-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.12
4
+ version: 1.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Sedlmair
@@ -95,6 +95,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
95
  requirements: []
96
96
  rubygems_version: 3.6.7
97
97
  specification_version: 4
98
- summary: Rock-solid and seamless integration of Svelte Components into Rails views,
99
- based on vite_rails.
98
+ summary: Solid and seamless integration of Svelte Components into Rails views.
100
99
  test_files: []