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 +4 -4
- data/README.md +2 -1
- data/lib/svelte-on-rails.rb +0 -1
- data/lib/svelte_on_rails/configuration.rb +17 -5
- data/lib/svelte_on_rails/lib/utils.rb +33 -37
- metadata +1 -2
- data/lib/svelte_on_rails/lib/initializable.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4002f622be27b2cee89f360cb18d02f063f4918208ecf433aeb85eee3e1b8ad3
|
4
|
+
data.tar.gz: f91206ad19b1e982f583300036c00ae5061a2096cf6bf20ce4eaea9de2ca989f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 ⚙️
|
data/lib/svelte-on-rails.rb
CHANGED
@@ -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
|
-
#
|
118
|
-
|
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
|
-
|
62
|
+
# run build
|
63
63
|
|
64
|
-
|
64
|
+
cmd = "#{config.rails_root.join('node_modules', '.bin', 'vite')} build --config vite-ssr.config.ts"
|
65
65
|
|
66
|
-
|
66
|
+
stdout, stderr, status = Open3.capture3(cmd)
|
67
67
|
|
68
|
-
|
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
|
-
|
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
|
-
|
75
|
+
if stderr.present?
|
76
76
|
|
77
|
-
|
77
|
+
red_background = "\033[97;41m"
|
78
|
+
light_blue_background = "\033[30;106m"
|
79
|
+
clear_colors = "\033[0m"
|
78
80
|
|
79
|
-
|
80
|
-
|
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
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
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}
|
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
|
-
|
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.
|
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
|