svelte-on-rails 2.1.0 → 2.1.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: 6fae4c4bf2119aa220d24e012f464136310c2409da41c1c13efd28dfc66c6221
4
- data.tar.gz: 931d743b51f07cb28581c93f347499cca8ca4fdf31d6a8c0ac078c90f4446e11
3
+ metadata.gz: 4002f622be27b2cee89f360cb18d02f063f4918208ecf433aeb85eee3e1b8ad3
4
+ data.tar.gz: f91206ad19b1e982f583300036c00ae5061a2096cf6bf20ce4eaea9de2ca989f
5
5
  SHA512:
6
- metadata.gz: 0cfc39709d7a9e4936aacba08b80d8f159146c8a58a08fe4d760bd75b311339608514fc480bf240044f872255cc3dd081fa5c6c8f5e5b787255613b70c70267f
7
- data.tar.gz: 5b9931cd49aa1115078f8406a85e3b6c28fe3645b9414ed42ace6bc3ac561c74936b04b355ad5e68d9701c55fd3fb219bb73915e5bab819415235a73c512f8c0
6
+ metadata.gz: f90f6082c7c97d672ca15c4c8d8c5c0576edb253ca35d02ca5857227365ccf52b1c4947aa28479aefd36351496a427a02976f0395e98ef63076b1d8a609c25c7
7
+ data.tar.gz: afbd7c72cd186de0451e26f0216dcd310d92d277ec5bc7072bb1e61c67fcd483265cf5c598e5edeb99bc3afb392f66873c26aedd43753e2d365459c4223e3c3f
data/README.md CHANGED
@@ -79,8 +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.
82
+ - actual node installed.
83
83
  - if `nvm` is installed it gets the path to the node-binary from there.
84
+ - When `.nvmrc` is present on projects root, it is respected
84
85
  - If node is not included on the PATH you can configure your node path by environment variable `SVELTE_ON_RAILS_NODE_BIN`
85
86
 
86
87
  ## Installation from cero ⚙️
@@ -2,7 +2,6 @@ require "svelte_on_rails/configuration"
2
2
  require "svelte_on_rails/view_helpers"
3
3
  require "svelte_on_rails/renderer/renderer"
4
4
  require "svelte_on_rails/lib/utils"
5
- require "svelte_on_rails/lib/initializable"
6
5
  require "svelte_on_rails/railtie" if defined?(Rails)
7
6
 
8
7
  # installer
@@ -108,14 +108,26 @@ module SvelteOnRails
108
108
  n = ENV['SVELTE_ON_RAILS_NODE_BIN'] || 'node'
109
109
 
110
110
  if n == 'node'
111
-
112
111
  nvm_installed = false
113
112
  nvm_dir = ENV['NVM_DIR'] || File.expand_path('~/.nvm')
114
113
  nvm_installed ||= File.exist?("#{nvm_dir}/nvm.sh")
115
114
 
116
115
  if nvm_installed
117
- # Use NVM_DIR if set, otherwise default to ~/.nvm
118
- command = "[ -s \"#{nvm_dir}/nvm.sh\" ] && . \"#{nvm_dir}/nvm.sh\" && nvm which current"
116
+ # Check for .nvmrc in the project root
117
+ project_root = rails_root || Dir.pwd
118
+ nvmrc_path = File.join(project_root, '.nvmrc')
119
+ use_nvmrc = File.exist?(nvmrc_path)
120
+
121
+ if use_nvmrc
122
+ # Read the version from .nvmrc
123
+ node_version = File.read(nvmrc_path).strip
124
+ # Ensure NVM is sourced and use the version from .nvmrc
125
+ command = "[ -s \"#{nvm_dir}/nvm.sh\" ] && . \"#{nvm_dir}/nvm.sh\" && nvm use #{node_version} > /dev/null 2>&1 && nvm which #{node_version}"
126
+ else
127
+ # Fallback to current NVM version
128
+ command = "[ -s \"#{nvm_dir}/nvm.sh\" ] && . \"#{nvm_dir}/nvm.sh\" && nvm which current"
129
+ end
130
+
119
131
  node_path, status = Open3.capture2("bash -lc '#{command}'")
120
132
 
121
133
  # Only update n if the command succeeded and output is non-empty
@@ -125,12 +137,12 @@ module SvelteOnRails
125
137
 
126
138
  # Validate node_bin
127
139
  unless n && !n.empty? && system("#{n} --version > /dev/null 2>&1")
128
- 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."
140
+ 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 or ensure a valid .nvmrc file is present."
129
141
  end
130
142
 
131
143
  n
132
144
  rescue StandardError => e
133
- raise "Failed to detect Node.js binary: «#{e.message}». Ensure Node.js is installed and accessible, or set SVELTE_ON_RAILS_NODE_BIN."
145
+ raise "Failed to detect Node.js binary: «#{e.message}». Ensure Node.js is installed and accessible, or set SVELTE_ON_RAILS_NODE_BIN. If using .nvmrc, ensure the specified version is installed via NVM."
134
146
  end
135
147
  end
136
148
 
@@ -59,59 +59,55 @@ module SvelteOnRails
59
59
  def self.precompile(last_mtime = nil)
60
60
  config = SvelteOnRails::Configuration.instance
61
61
 
62
- Dir.chdir(config.rails_root) do
62
+ # run build
63
63
 
64
- # run build
64
+ cmd = "#{config.rails_root.join('node_modules', '.bin', 'vite')} build --config vite-ssr.config.ts"
65
65
 
66
- cmd = "./node_modules/.bin/vite build --config vite-ssr.config.ts"
66
+ stdout, stderr, status = Open3.capture3(cmd)
67
67
 
68
- stdout, stderr, status = Open3.capture3(cmd)
68
+ warnings = stderr.to_s.split("\n")
69
+ errors_matcher = Regexp.new('(Could not resolve|failed to resolve)')
70
+ error_lines = warnings.select { |e| e.match(errors_matcher) }
71
+ have_error = error_lines.present? || status.to_s.match(/exit 1/)
69
72
 
70
- warnings = stderr.to_s.split("\n")
71
- errors_matcher = Regexp.new('(Could not resolve|failed to resolve)')
72
- error_lines = warnings.select { |e| e.match(errors_matcher) }
73
- have_error = error_lines.present? || status.to_s.match(/exit 1/)
73
+ # error handling
74
74
 
75
- # error handling
75
+ if stderr.present?
76
76
 
77
- if stderr.present?
77
+ red_background = "\033[97;41m"
78
+ light_blue_background = "\033[30;106m"
79
+ clear_colors = "\033[0m"
78
80
 
79
- red_background = "\033[97;41m"
80
- light_blue_background = "\033[30;106m"
81
- clear_colors = "\033[0m"
81
+ msg = " +++ #{have_error ? 'ERROR' : 'WARNING'} compiling Svelte components#{have_error ? ' failed' : ''} («#{cmd}») +++ "
82
+ puts "#{have_error ? red_background : light_blue_background}#{msg}#{clear_colors}"
82
83
 
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}"
84
+ warnings.each do |e|
85
+ if e.match(errors_matcher)
86
+ red_font = "\033[31m"
87
+ puts "#{red_background} #{clear_colors}#{red_font} #{e}#{clear_colors}"
97
88
  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
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"
89
+ puts "#{light_blue_background} #{clear_colors}#{e}"
107
90
  end
91
+ end
108
92
 
93
+ if have_error
94
+ puts "#{red_background} +++ End of error message +++ #{clear_colors}"
95
+ else
96
+ puts "#{light_blue_background} +++ End of compiling warnings +++ #{clear_colors}"
109
97
  end
98
+ puts "#{have_error ? red_background : light_blue_background} +++ Run «npm run build:ssr» on the console to see the original error message +++ #{clear_colors}"
110
99
 
111
- puts stdout
100
+ if have_error
101
+ cl_str = if error_lines.present?
102
+ "#{error_lines.join("\n")}\n\n"
103
+ end
104
+ 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"
105
+ end
112
106
 
113
107
  end
114
108
 
109
+ puts stdout
110
+
115
111
  unless Dir.exist?(config.ssr_dist_folder)
116
112
  raise "Could not find dist folder: #{config.ssr_dist_folder}"
117
113
  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: 2.1.0
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Sedlmair
@@ -41,7 +41,6 @@ files:
41
41
  - lib/svelte_on_rails/installer/utils.rb
42
42
  - lib/svelte_on_rails/installer/vite.rb
43
43
  - lib/svelte_on_rails/lib/development_utils.rb
44
- - lib/svelte_on_rails/lib/initializable.rb
45
44
  - lib/svelte_on_rails/lib/utils.rb
46
45
  - lib/svelte_on_rails/railtie.rb
47
46
  - lib/svelte_on_rails/renderer/render.js
@@ -1,17 +0,0 @@
1
- module SvelteOnRails
2
-
3
- module Lib
4
- module Initializable
5
- def initialize(filename, base_path: SvelteOnRails::Configuration.instance.components_folder_full)
6
-
7
- fn = (filename.match(/\.svelte$/) ? filename[0..-8] : filename)
8
- @svelte_file = base_path + filename
9
- @svelte_filename = filename
10
- cnf = SvelteOnRails::Configuration.instance
11
- cf = cnf.dist_folder + cnf.components_folder + fn
12
- @compiled_file = cf.to_s
13
-
14
- end
15
- end
16
- end
17
- end