svelte-on-rails 2.0.0 → 2.0.2

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: a0e1e1cb1a95e07c184fb9b943315765340d46690f2c6a66f0041aaa233fbc19
4
- data.tar.gz: 0b93fc9a113b43b5b997e81f912535015415d66e1e6dd480129a5f28091d227b
3
+ metadata.gz: '0595a01f21a83a1c3a7bf6642015c37b4c20da914c1ff120169748af5925671d'
4
+ data.tar.gz: 2f07f7525487eff68c481ebb83f709f4731755ccd097df0d8f2e9f62cc33b888
5
5
  SHA512:
6
- metadata.gz: 4801f3526444fbc17446bfb06270eae0cf8962be0c1c07c51d3a4b166c0ef2376b3fa73532b3629f18d99e296df9b34b55b34287a9bea6e77dcf194b01ea5adc
7
- data.tar.gz: 5641533b5e6625231c1a5803e5d2cf75c1e0b1f3749d44e0cb43176b60b0cf03437ade435fb50013b997e5d8b5252ebb42b4946084e416123c1dc5c2d6af7ccb
6
+ metadata.gz: 0f27dfc80fe5d610e0c30dffec9113470472f8cde869da180fe15723f6f497dfab5afa97597b4b896f39845b667c283cbd45e45f9cc42b56808cf0fcf131a00b
7
+ data.tar.gz: 05dfd0aeccf917ad9a40d7b846066fae6d017709df5bf67824ddd1a96f3e931007c4fdba01daeed35220d32141b230bebff800b8ed8ebecbca658d3758c3c07e
data/README.md CHANGED
@@ -79,6 +79,9 @@ If you have issues, please open one, and contributors are welcome!
79
79
  - turbo (recommended / [how to install turbo on rails](https://github.com/hotwired/turbo-rails?tab=readme-ov-file#installation))
80
80
  - if you use special packages (like pug) that requires commonjs, you may need
81
81
  - npm on latest versions
82
+ - node installed.
83
+ - If node is not included on the PATH you can configure your node path by environment variable `SVELTE_ON_RAILS_NODE_BIN`
84
+ - it checks for `nvm` and if installed, gets the node path from there.
82
85
 
83
86
  ## Installation from cero ⚙️
84
87
 
@@ -103,6 +103,35 @@ module SvelteOnRails
103
103
  :vite_rails
104
104
  end
105
105
 
106
+ def node_bin_path
107
+ @node_bin_path ||= begin
108
+ n = ENV['SVELTE_ON_RAILS_NODE_BIN'] || 'node'
109
+
110
+ if n == 'node'
111
+ # Check if NVM is installed
112
+ nvm_check, status = Open3.capture2('command -v nvm')
113
+ if status.success? && !nvm_check.strip.empty?
114
+ # Use NVM_DIR if set, otherwise default to ~/.nvm
115
+ nvm_dir = ENV['NVM_DIR'] || File.expand_path('~/.nvm')
116
+ command = "[ -s \"#{nvm_dir}/nvm.sh\" ] && . \"#{nvm_dir}/nvm.sh\" && nvm which current"
117
+ node_path, status = Open3.capture2("bash -lc '#{command}'")
118
+
119
+ # Only update n if the command succeeded and output is non-empty
120
+ n = node_path.strip if status.success? && !node_path.strip.empty?
121
+ end
122
+ end
123
+
124
+ # Validate node_bin
125
+ unless n && !n.empty? && system("#{n} --version > /dev/null 2>&1")
126
+ raise "Node.js not found at '#{n || 'unknown'}'. Please configure SVELTE_ON_RAILS_NODE_BIN (e.g., to ~/.nvm/versions/node/vX.Y.Z/bin/node) or ensure 'node' is in the PATH. If using NVM, run `nvm alias default <version>` to set a default version."
127
+ end
128
+
129
+ n
130
+ rescue StandardError => e
131
+ raise "Failed to detect Node.js binary: #{e.message}. Ensure Node.js is installed and accessible, or set SVELTE_ON_RAILS_NODE_BIN."
132
+ end
133
+ end
134
+
106
135
  private
107
136
 
108
137
  def load_yaml_config
@@ -125,11 +125,21 @@ module SvelteOnRails
125
125
  def self.puts_error(text)
126
126
  red_background = "\033[97;41m"
127
127
  clear_colors = "\033[0m"
128
+ puts "#{red_background} ERROR #{clear_colors}"
128
129
  text.split("\n").each do |line|
129
130
  puts "#{red_background} #{clear_colors} #{line}"
130
131
  end
131
132
  end
132
133
 
134
+ def self.puts_warning(text)
135
+ black_background = "\033[97;40m"
136
+ clear_colors = "\033[0m"
137
+ puts "#{black_background} [svelte-on-rails] WARNING #{clear_colors}"
138
+ text.split("\n").each do |line|
139
+ puts "#{black_background} #{clear_colors} #{line}"
140
+ end
141
+ end
142
+
133
143
  end
134
144
  end
135
145
  end
@@ -6,6 +6,11 @@ module SvelteOnRails
6
6
  def initialize(component_name, base_path: SvelteOnRails::Configuration.instance.components_folder_full)
7
7
 
8
8
  config = SvelteOnRails::Configuration.instance
9
+
10
+ unless system("#{config.node_bin_path} --version > /dev/null 2>&1")
11
+ raise "Node.js not found at '#{config.node_bin_path}'. Please configure SvelteOnRails.node_bin (e.g., to ~/.nvm/versions/node/vX.Y.Z/bin/node) or ensure 'node' is in the PATH. If using NVM, run `nvm which default` to find the path."
12
+ end
13
+
9
14
  if !Dir.exist?(config.ssr_dist_folder) || config.watch_changes?
10
15
  SvelteOnRails::Lib::Utils.watch_changes_and_precompile
11
16
  end
@@ -21,28 +26,33 @@ module SvelteOnRails
21
26
  require 'base64'
22
27
  require 'json'
23
28
  utils = SvelteOnRails::Lib::Utils
29
+ cnf = SvelteOnRails::Configuration.instance
24
30
 
25
31
  cmd = [
26
- 'node',
27
- '/Users/christian/projects-gmbh/gems/svelte-on-rails/svelte-on-rails-gem/lib/svelte_on_rails/renderer/render.js',
32
+ cnf.node_bin_path,
33
+ File.join(utils.gem_app_dir, 'renderer', 'render.js'),
28
34
  @component_files[:compiled_file] + '.js',
29
35
  SvelteOnRails::Configuration.instance.rails_root
30
36
  ].join(' ')
31
37
 
32
38
  stdout, stderr, status = Open3.capture3(cmd, stdin_data: props.to_json, chdir: utils.gem_app_dir)
33
39
 
40
+
34
41
  unless status.to_s.match(/^pid [0-9]+ exit 0$/)
35
- cmp = "#{@component_files[:svelte_filename]} could not be rendered Server-side\n\n"
36
- msg = "#{cmp}Error output from render.js (stderr) =>\n+++\n" + stderr + "+++\n\nRender Svelte Server-side =>\n#{cmd}\n\n"
37
- utils.puts_error(msg)
42
+ cmp = "#{@component_files[:svelte_filename]} was returned «#{status.to_s}»\n\n"
43
+ msg = "#{cmp}output from render.js (stderr) =>\n+++\n" + stderr + "+++\n\nRender Svelte Server-side =>\n#{cmd}\n\n"
44
+ utils.puts_warning(msg)
38
45
  end
39
46
 
47
+
40
48
  begin
41
49
  res = JSON.parse(stdout)
42
50
  css_file = @component_files[:compiled_file] + '.css'
43
51
  if File.exist?(css_file)
44
52
  res['css'] = File.read(css_file)
45
53
  end
54
+
55
+
46
56
  return res
47
57
  rescue JSON::ParserError => e
48
58
  raise "Render Svelte Server-side: Expected JSON, got: «#{stdout}»"
@@ -46,8 +46,8 @@ module SvelteOnRails
46
46
  # set up html
47
47
 
48
48
  options[:class] = options[:class].to_s + ' svelte-component'
49
- #options[:class] += ' please-hydrate-me-svelte-on-rails' if hydrate
50
49
  options[:data] ||= {}
50
+ options[:data][:svelte_status] = 'do-not-hydrate-me' unless hydrate
51
51
  options[:data][:props] = props.to_json
52
52
  options[:data][:svelte_component] = "/#{conf.components_folder + filename}"
53
53
  options[:data][:controller] = 'svelte-on-rails'
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: 2.0.0
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Sedlmair