svelte-on-rails 2.0.1 → 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: e16a769e38b976e345c081f5a3ad9547fc3ed2e0ac9fdfeda0e0bba81d0647af
4
- data.tar.gz: 50d9fc3536eeaa32fd44e58d24f50911eb3d9253bc9398d3eefb1116dcad4f6d
3
+ metadata.gz: '0595a01f21a83a1c3a7bf6642015c37b4c20da914c1ff120169748af5925671d'
4
+ data.tar.gz: 2f07f7525487eff68c481ebb83f709f4731755ccd097df0d8f2e9f62cc33b888
5
5
  SHA512:
6
- metadata.gz: def95c897b35752847a3d4a4262ac164baa0a99907fa27990c4c1c9da98b2aade7f006d33cbbd6b61d659be16851da158509d0cd27d520613c5cf52c2efb7317
7
- data.tar.gz: 31b782e4fb8823b7ac30eafd1aa11fcf7bad00e6816ccdaaa1fdc2b08b2bd60c5ac7d804a0d3f9a7c5571b0708514ef30bdedcf28a4e50969e433641b31a767e
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
@@ -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,10 +26,11 @@ 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(' ')
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.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Sedlmair