svelte-on-rails 14.4.0 → 14.5.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 +4 -4
- data/lib/svelte-on-rails.rb +1 -2
- data/lib/svelte_on_rails/lib/fallback_renderer.rb +89 -0
- data/lib/svelte_on_rails/lib/metrics.rb +2 -0
- data/lib/svelte_on_rails/lib/utils.rb +14 -0
- data/lib/svelte_on_rails/lib/view_helper_support.rb +32 -5
- data/lib/svelte_on_rails/ssr_server.rb +21 -14
- data/lib/svelte_on_rails/view_helpers.rb +45 -32
- metadata +2 -2
- data/lib/svelte_on_rails/renderer/renderer.rb +0 -64
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d12a749b2285a777b0f61a381785f60a076e089b19cf1849d71ca4481460546a
|
|
4
|
+
data.tar.gz: 4c8d743ad0a80a6e64a4c3273e0c0b0360faf01f2f5c9497f8eb9aee4cc99540
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cc42096e49e80ef471749fe347e79ad5caef7c0824ddd38571dbf898936c8e93130a595073ce654f4380de5834070017c6dbda1c3dc8b55f6495e4eb08c96214
|
|
7
|
+
data.tar.gz: 14887f7e4edbe5c2078378cdb45f735099bc2cced66f1a74d25b800ce2a53ec7e906572976f41098f1846041f3522f5579e2b5a7af4d0b889e7d80317b4be62e
|
data/lib/svelte-on-rails.rb
CHANGED
|
@@ -7,8 +7,8 @@ require "svelte_on_rails/ssr_server"
|
|
|
7
7
|
|
|
8
8
|
require "svelte_on_rails/railtie" if defined?(Rails)
|
|
9
9
|
|
|
10
|
-
require "svelte_on_rails/renderer/renderer"
|
|
11
10
|
|
|
11
|
+
require "svelte_on_rails/lib/fallback_renderer"
|
|
12
12
|
require "svelte_on_rails/lib/utils"
|
|
13
13
|
require "svelte_on_rails/lib/metrics"
|
|
14
14
|
require "svelte_on_rails/lib/log_patch"
|
|
@@ -33,7 +33,6 @@ require 'generators/showcase_generator'
|
|
|
33
33
|
|
|
34
34
|
require 'digest/xxhash'
|
|
35
35
|
require 'benchmark'
|
|
36
|
-
#require 'faraday'
|
|
37
36
|
|
|
38
37
|
module SvelteOnRails
|
|
39
38
|
class << self
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
module SvelteOnRails
|
|
2
|
+
module Lib
|
|
3
|
+
class FallbackRenderer
|
|
4
|
+
|
|
5
|
+
require 'open3'
|
|
6
|
+
require 'base64'
|
|
7
|
+
require 'json'
|
|
8
|
+
|
|
9
|
+
def self.render(paths, props, debug)
|
|
10
|
+
utils = SvelteOnRails::Lib::Utils
|
|
11
|
+
cnf = SvelteOnRails::Configuration.instance
|
|
12
|
+
mn = cnf.manifest(debug, paths[:name])
|
|
13
|
+
manifest = mn[paths[:path]]
|
|
14
|
+
|
|
15
|
+
if manifest.nil?
|
|
16
|
+
raise "[SOR] #{paths[:file_basename]}: ERROR: No manifest found!\nAvailable keys in current manifest.json are:\n\n+++\n • #{cnf.manifest.keys.join("\n • ")}\n+++\n."
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
cmd = [
|
|
20
|
+
cnf.node_bin_path,
|
|
21
|
+
cnf.rails_root.join('node_modules/@csedl/svelte-on-rails/src/ssr/render.js'),
|
|
22
|
+
cnf.assets_folder_path.join(manifest['file'])
|
|
23
|
+
].join(' ')
|
|
24
|
+
|
|
25
|
+
stdout, stderr, status = Open3.capture3(
|
|
26
|
+
cmd,
|
|
27
|
+
stdin_data: props.to_json,
|
|
28
|
+
chdir: cnf.rails_root,
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
ary = stdout.split('$$ResponseSeparator$$')
|
|
32
|
+
|
|
33
|
+
js = JSON.parse(ary.second || {})
|
|
34
|
+
if js['status'] == 'SUCCESS'
|
|
35
|
+
|
|
36
|
+
htm = js['html'].delete_prefix("<!--[-->").delete_suffix("<!--]-->")
|
|
37
|
+
|
|
38
|
+
{
|
|
39
|
+
success: true,
|
|
40
|
+
html: htm,
|
|
41
|
+
head: js['head'],
|
|
42
|
+
}
|
|
43
|
+
else
|
|
44
|
+
|
|
45
|
+
utils = SvelteOnRails::Lib::Utils
|
|
46
|
+
utils.error_log(
|
|
47
|
+
"RENDER #{paths[:file_basename]}.svelte",
|
|
48
|
+
[
|
|
49
|
+
"command:\n#{cmd}",
|
|
50
|
+
"stdout:\n#{stdout.split('$$ResponseSeparator$$').first.strip}",
|
|
51
|
+
"stderr:\n#{stderr.strip}",
|
|
52
|
+
]
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
{ success: false }
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# unless ary.length == 2 || (JSON.parse(ary.second) rescue true)
|
|
59
|
+
# utils = SvelteOnRails::Lib::Utils
|
|
60
|
+
# utils.error_log(
|
|
61
|
+
# "RENDER #{paths[:file_basename]}.svelte",
|
|
62
|
+
# [
|
|
63
|
+
# "command:\n#{cmd}",
|
|
64
|
+
# "stdout:\n#{stdout}",
|
|
65
|
+
# "stderr:\n#{stderr}",
|
|
66
|
+
# ]
|
|
67
|
+
# )
|
|
68
|
+
# return { success: false }
|
|
69
|
+
# end
|
|
70
|
+
|
|
71
|
+
# begin
|
|
72
|
+
#
|
|
73
|
+
# raw_response = JSON.parse(ary[1])
|
|
74
|
+
#
|
|
75
|
+
# htm = raw_response['html'].delete_prefix("<!--[-->").delete_suffix("<!--]-->")
|
|
76
|
+
#
|
|
77
|
+
# return {
|
|
78
|
+
# success: true,
|
|
79
|
+
# html: htm,
|
|
80
|
+
# head: raw_response['head'],
|
|
81
|
+
# }
|
|
82
|
+
#
|
|
83
|
+
# rescue => e
|
|
84
|
+
# raise "MY_ERR => #{e}\n\n+++\n#{e.backtrace.join("\n")}\n+++"
|
|
85
|
+
# end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
@@ -93,6 +93,20 @@ module SvelteOnRails
|
|
|
93
93
|
0.0
|
|
94
94
|
end
|
|
95
95
|
end
|
|
96
|
+
|
|
97
|
+
def self.error_log(title, messages)
|
|
98
|
+
sep_char = '='
|
|
99
|
+
sep_line = sep_char*100
|
|
100
|
+
inner_sep = '-'*100
|
|
101
|
+
puts sep_line
|
|
102
|
+
puts "ERROR: #{title}"
|
|
103
|
+
puts sep_line
|
|
104
|
+
puts messages.join("\n#{inner_sep}\n")
|
|
105
|
+
puts sep_line
|
|
106
|
+
puts "END #{title.downcase}"
|
|
107
|
+
puts sep_line
|
|
108
|
+
$stdout.flush
|
|
109
|
+
end
|
|
96
110
|
end
|
|
97
111
|
end
|
|
98
112
|
end
|
|
@@ -23,17 +23,33 @@ module SvelteOnRails
|
|
|
23
23
|
|
|
24
24
|
if !@conf.manifest_json_path.exist? ||
|
|
25
25
|
!@conf.dev_module_map_path.exist? ||
|
|
26
|
-
|
|
26
|
+
|
|
27
|
+
@conf.build_status['mtime'].to_f != @utils.manifest_file_mtime ||
|
|
28
|
+
# if a developer has run build from the console, we must update the build-status object
|
|
29
|
+
# this is importand for having reliable error-messages
|
|
30
|
+
|
|
31
|
+
(!@conf.build_status['passed'] && !@conf.request_metrics[:build_failed])
|
|
32
|
+
# when build has failed the developer sees the error message
|
|
33
|
+
# at this point it is importand to see the build-error in the logs
|
|
34
|
+
# but only ONCE for a request, so we check metrics too
|
|
35
|
+
|
|
27
36
|
run_vite_build
|
|
37
|
+
|
|
38
|
+
return unless @conf.build_status['passed']
|
|
28
39
|
end
|
|
29
40
|
|
|
30
|
-
|
|
41
|
+
# now we are sure to have a valid manifest
|
|
42
|
+
# and are able to collect the dependend source files,
|
|
43
|
+
# check theyr mtime
|
|
44
|
+
# and run a build if something has changed (is only the case if the build above not was run)
|
|
31
45
|
ensure_valid_component_and_manifest!(component)
|
|
32
|
-
|
|
33
46
|
if @conf.component_mtime_changed?(component_paths[:path], debug?, component_paths[:file_basename])
|
|
34
47
|
run_vite_build
|
|
35
48
|
end
|
|
36
49
|
|
|
50
|
+
# finally, validate the given options
|
|
51
|
+
validate_options
|
|
52
|
+
|
|
37
53
|
end
|
|
38
54
|
|
|
39
55
|
if @conf.configs[:cache_warmer] && caching
|
|
@@ -118,9 +134,12 @@ module SvelteOnRails
|
|
|
118
134
|
@cached_content.html_safe
|
|
119
135
|
else
|
|
120
136
|
msg = "Rendered"
|
|
137
|
+
@skip_caching = false
|
|
121
138
|
@conf.debug_log(debug?, component_paths[:name], "rendered and stored to cache (key: «#{cache_key}»)") do
|
|
122
139
|
r = view_context.instance_eval(&block)
|
|
123
|
-
@
|
|
140
|
+
unless @skip_caching
|
|
141
|
+
@conf.redis_instance.set(cache_key, r)
|
|
142
|
+
end
|
|
124
143
|
r
|
|
125
144
|
end
|
|
126
145
|
end
|
|
@@ -140,7 +159,15 @@ module SvelteOnRails
|
|
|
140
159
|
|
|
141
160
|
def set_request_metrics(action_key)
|
|
142
161
|
|
|
143
|
-
if @conf.watch_changes? &&
|
|
162
|
+
if @conf.watch_changes? &&
|
|
163
|
+
![
|
|
164
|
+
:build,
|
|
165
|
+
:build_failed,
|
|
166
|
+
:render_failed,
|
|
167
|
+
:from_cache,
|
|
168
|
+
:empty,
|
|
169
|
+
:rendered
|
|
170
|
+
].include?(action_key)
|
|
144
171
|
raise "[SOR] set_request_metrics: invalid action_key"
|
|
145
172
|
end
|
|
146
173
|
|
|
@@ -106,20 +106,27 @@ module SvelteOnRails
|
|
|
106
106
|
shorten_logfile
|
|
107
107
|
|
|
108
108
|
raw_response = parse_body_json(response)
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
109
|
+
if raw_response['status'] == 'SUCCESS'
|
|
110
|
+
htm = raw_response['html'].to_s.delete_prefix("<!--[-->").delete_suffix("<!--]-->")
|
|
111
|
+
|
|
112
|
+
{
|
|
113
|
+
success: true,
|
|
114
|
+
html: htm,
|
|
115
|
+
head: raw_response['head'].to_s,
|
|
116
|
+
}
|
|
117
|
+
else
|
|
118
|
+
utils = SvelteOnRails::Lib::Utils
|
|
119
|
+
utils.error_log(
|
|
120
|
+
"Render #{component[:file_basename]}.svelte",
|
|
121
|
+
[
|
|
122
|
+
raw_response['errorLog'].join("\n")
|
|
123
|
+
]
|
|
124
|
+
)
|
|
125
|
+
{
|
|
126
|
+
success: false,
|
|
127
|
+
}
|
|
128
|
+
end
|
|
129
|
+
|
|
123
130
|
end
|
|
124
131
|
|
|
125
132
|
def parse_body_json(response_string)
|
|
@@ -16,7 +16,7 @@ module SvelteOnRails
|
|
|
16
16
|
|
|
17
17
|
if support.ssr?
|
|
18
18
|
if config.watch_changes? && !config.build_status['passed']
|
|
19
|
-
|
|
19
|
+
build_failed_tag(support, wrapper_html, props)
|
|
20
20
|
elsif caching
|
|
21
21
|
support.set_request_metrics(:from_cache)
|
|
22
22
|
support.render_cached(self) do
|
|
@@ -38,28 +38,22 @@ module SvelteOnRails
|
|
|
38
38
|
|
|
39
39
|
if support.ssr?
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
ssr_result = if !support.conf.build_status['passed']
|
|
44
|
-
wrapper_style = 'color: white; background-color: red; padding: 10px; border-radius: 10px; display:inline-block; font-size:22px;'
|
|
45
|
-
html = <<~HTML
|
|
46
|
-
<strong style="#{wrapper_style}">
|
|
47
|
-
<p style="margin:4px;">Vite build failed.</p>
|
|
48
|
-
<p style="margin:4px;">Please run «npm run build:ssr» to fix.</p>
|
|
49
|
-
</strong>
|
|
50
|
-
HTML
|
|
51
|
-
{
|
|
52
|
-
html: html.html_safe,
|
|
53
|
-
head: ''.html_safe
|
|
54
|
-
}
|
|
55
|
-
elsif SvelteOnRails::SsrServer.instance.alive?
|
|
41
|
+
ssr_result = if SvelteOnRails::SsrServer.instance.alive?
|
|
56
42
|
SvelteOnRails::SsrServer.instance.render(support.component_paths, props, support.debug?)
|
|
57
43
|
else
|
|
58
|
-
SvelteOnRails::
|
|
44
|
+
SvelteOnRails::Lib::FallbackRenderer.render(support.component_paths, props, support.debug?)
|
|
59
45
|
end
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
46
|
+
|
|
47
|
+
if ssr_result[:success]
|
|
48
|
+
support.set_request_metrics(:rendered)
|
|
49
|
+
content_tag(:div, support.tag_attributes(html_options, props)) do
|
|
50
|
+
concat(ssr_result[:head].html_safe)
|
|
51
|
+
concat(ssr_result[:html].html_safe)
|
|
52
|
+
end
|
|
53
|
+
else
|
|
54
|
+
support.set_request_metrics(:render_failed)
|
|
55
|
+
support.instance_variable_set(:@skip_caching, true)
|
|
56
|
+
render_failed_tag(support, html_options, props)
|
|
63
57
|
end
|
|
64
58
|
|
|
65
59
|
else
|
|
@@ -76,26 +70,45 @@ module SvelteOnRails
|
|
|
76
70
|
content_tag(:div, support.tag_attributes(html_options, props)) {}
|
|
77
71
|
end
|
|
78
72
|
|
|
79
|
-
def
|
|
73
|
+
def build_failed_tag(support, html_options, props)
|
|
80
74
|
|
|
81
|
-
support.set_request_metrics(:empty)
|
|
75
|
+
# support.set_request_metrics(:empty)
|
|
82
76
|
|
|
83
77
|
content_tag(:div, support.tag_attributes(html_options, props)) do
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
'font-size:16px',
|
|
90
|
-
'font-weight:bold',
|
|
91
|
-
'border:3px solid white'
|
|
92
|
-
]
|
|
93
|
-
content_tag(:span, style: style.join(';')) do
|
|
78
|
+
content_tag(
|
|
79
|
+
:span,
|
|
80
|
+
class: 'svelte-on-rails-render-error',
|
|
81
|
+
style: failed_tag_style
|
|
82
|
+
) do
|
|
94
83
|
'BUILD FAILED'
|
|
95
84
|
end
|
|
96
85
|
end
|
|
97
86
|
end
|
|
98
87
|
|
|
88
|
+
def render_failed_tag(support, html_options, props)
|
|
89
|
+
content_tag(:div, support.tag_attributes(html_options, props)) do
|
|
90
|
+
content_tag(
|
|
91
|
+
:span,
|
|
92
|
+
class: 'svelte-on-rails-render-error',
|
|
93
|
+
style: failed_tag_style
|
|
94
|
+
) do
|
|
95
|
+
'RENDER FAILED'
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def failed_tag_style
|
|
101
|
+
[
|
|
102
|
+
'background-color:red',
|
|
103
|
+
'color:white',
|
|
104
|
+
'padding:8px',
|
|
105
|
+
'border-radius:8px',
|
|
106
|
+
'font-size:16px',
|
|
107
|
+
'font-weight:bold',
|
|
108
|
+
'border:3px solid white'
|
|
109
|
+
].join(';')
|
|
110
|
+
end
|
|
111
|
+
|
|
99
112
|
def calling_view_dir
|
|
100
113
|
rails_views_path = Rails.root.join('app', 'views').to_s
|
|
101
114
|
raw_path_full = caller_locations.find do |loc|
|
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: 14.
|
|
4
|
+
version: 14.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Christian Sedlmair
|
|
@@ -99,6 +99,7 @@ files:
|
|
|
99
99
|
- lib/svelte_on_rails/installer/utils.rb
|
|
100
100
|
- lib/svelte_on_rails/lib/cache_warmer.rb
|
|
101
101
|
- lib/svelte_on_rails/lib/development_utils.rb
|
|
102
|
+
- lib/svelte_on_rails/lib/fallback_renderer.rb
|
|
102
103
|
- lib/svelte_on_rails/lib/log_patch.rb
|
|
103
104
|
- lib/svelte_on_rails/lib/metrics.rb
|
|
104
105
|
- lib/svelte_on_rails/lib/to_svelte_labels.rb
|
|
@@ -108,7 +109,6 @@ files:
|
|
|
108
109
|
- lib/svelte_on_rails/lib/view_helper_support.rb
|
|
109
110
|
- lib/svelte_on_rails/lib/watch_asset_changes.rb
|
|
110
111
|
- lib/svelte_on_rails/railtie.rb
|
|
111
|
-
- lib/svelte_on_rails/renderer/renderer.rb
|
|
112
112
|
- lib/svelte_on_rails/ssr_server.rb
|
|
113
113
|
- lib/svelte_on_rails/turbo_stream.rb
|
|
114
114
|
- lib/svelte_on_rails/view_helpers.rb
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
module SvelteOnRails
|
|
2
|
-
class
|
|
3
|
-
Renderer
|
|
4
|
-
|
|
5
|
-
require 'open3'
|
|
6
|
-
require 'base64'
|
|
7
|
-
require 'json'
|
|
8
|
-
|
|
9
|
-
def self.render(paths, props, debug)
|
|
10
|
-
utils = SvelteOnRails::Lib::Utils
|
|
11
|
-
cnf = SvelteOnRails::Configuration.instance
|
|
12
|
-
mn = cnf.manifest(debug, paths[:name])
|
|
13
|
-
manifest = mn[paths[:path]]
|
|
14
|
-
|
|
15
|
-
if manifest.nil?
|
|
16
|
-
raise "[SOR] #{paths[:file_basename]}: ERROR: No manifest found!\nAvailable keys in current manifest.json are:\n\n+++\n • #{cnf.manifest.keys.join("\n • ")}\n+++\n."
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
cmd = [
|
|
20
|
-
cnf.node_bin_path,
|
|
21
|
-
cnf.rails_root.join('node_modules/@csedl/svelte-on-rails/src/ssr/render.js'),
|
|
22
|
-
cnf.assets_folder_path.join(manifest['file'])
|
|
23
|
-
].join(' ')
|
|
24
|
-
|
|
25
|
-
stdout, stderr, status = Open3.capture3(
|
|
26
|
-
cmd,
|
|
27
|
-
stdin_data: props.to_json,
|
|
28
|
-
chdir: cnf.rails_root,
|
|
29
|
-
)
|
|
30
|
-
|
|
31
|
-
ary = stdout.split('$$ResponseSeparator$$')
|
|
32
|
-
ary_t = ary.first.split('<time>')
|
|
33
|
-
start = ary_t.first.to_f
|
|
34
|
-
completed = ary_t.last.to_f
|
|
35
|
-
cnf.debug_log(debug, paths[:name], "Render Server-side (#{(completed - start).round(2)}ms)")
|
|
36
|
-
|
|
37
|
-
unless ary.length == 2
|
|
38
|
-
raise "[SOR] #{paths[:name]}: RENDER ERROR\n\ncommand:\n+++\n#{cmd}\n+++\n\nstdout:\n+++\n#{stdout}+++\n\n\nstderr:\n+++\n#{stderr}+++"
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
begin
|
|
42
|
-
|
|
43
|
-
unless status.to_s.match(/^pid [0-9]+ exit 0$/)
|
|
44
|
-
cmp = "#{paths[:path]} was returned «#{status.to_s}»\n\n"
|
|
45
|
-
msg = "#{cmp}output from render.js (stderr) =>\n+++\n" + stderr + "+++\n\nRender Svelte Server-side =>\n#{cmd}\n\n"
|
|
46
|
-
utils.puts_warning(msg)
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
raw_response = JSON.parse(ary[1])
|
|
50
|
-
|
|
51
|
-
htm = raw_response['html'].delete_prefix("<!--[-->").delete_suffix("<!--]-->")
|
|
52
|
-
|
|
53
|
-
return {
|
|
54
|
-
html: htm,
|
|
55
|
-
head: raw_response['head'],
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
rescue => e
|
|
59
|
-
raise "MY_ERR => #{e}\n\n+++\n#{e.backtrace.join("\n")}\n+++"
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
end
|
|
64
|
-
end
|