Module: ViteRuby::CompatibilityCheck
- Defined in:
- lib/vite_ruby/compatibility_check.rb
Overview
Internal: Verifies that the installed vite-plugin-ruby version is compatible with the current version of vite_ruby.
This helps to prevent more subtle runtime errors if there is a mismatch in the manifest schema.
Class Method Summary collapse
-
.compatible_plugin?(npm_req, ruby_req) ⇒ Boolean
Internal: Returns true unless the check is performed and does not meet the requirement.
-
.raise_unless_satisfied(npm_req, ruby_req) ⇒ Object
Internal: Notifies the user of a possible incompatible plugin.
-
.verify_plugin_version(root) ⇒ Object
Public: Attempt to verify that the vite-plugin-ruby version is compatible.
Class Method Details
.compatible_plugin?(npm_req, ruby_req) ⇒ Boolean
Internal: Returns true unless the check is performed and does not meet the requirement.
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/vite_ruby/compatibility_check.rb', line 38 def compatible_plugin?(npm_req, ruby_req) npm_req, ruby_req = [npm_req, ruby_req] .map { |req| Gem::Requirement.new(req.sub("^", "~>")) } current_version = npm_req.requirements.first.second ruby_req.satisfied_by?(current_version) rescue true end |
.raise_unless_satisfied(npm_req, ruby_req) ⇒ Object
Internal: Notifies the user of a possible incompatible plugin.
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/vite_ruby/compatibility_check.rb', line 22 def raise_unless_satisfied(npm_req, ruby_req) unless compatible_plugin?(npm_req, ruby_req) raise ArgumentError, <<~ERROR vite-plugin-ruby@#{npm_req} might not be compatible with vite_ruby-#{ViteRuby::VERSION} You may disable this check if needed: https://vite-ruby.netlify.app/config/#skipcompatibilitycheck You may upgrade both by running: bundle exec vite upgrade ERROR end end |
.verify_plugin_version(root) ⇒ Object
Public: Attempt to verify that the vite-plugin-ruby version is compatible.
13 14 15 16 17 18 19 |
# File 'lib/vite_ruby/compatibility_check.rb', line 13 def verify_plugin_version(root) package = JSON.parse(root.join("package.json").read) rescue {} requirement = package.dig("devDependencies", "vite-plugin-ruby") || package.dig("dependencies", "vite-plugin-ruby") raise_unless_satisfied(requirement, ViteRuby::DEFAULT_PLUGIN_VERSION) end |