lib/vite_ruby.rb in vite_ruby-3.9.0 vs lib/vite_ruby.rb in vite_ruby-3.9.1

- old
+ new

@@ -1,34 +1,34 @@ # frozen_string_literal: true -require 'logger' -require 'forwardable' -require 'pathname' -require 'socket' +require "logger" +require "forwardable" +require "pathname" +require "socket" -require 'zeitwerk' +require "zeitwerk" loader = Zeitwerk::Loader.for_gem -loader.ignore("#{ __dir__ }/install") -loader.ignore("#{ __dir__ }/tasks") -loader.ignore("#{ __dir__ }/exe") -loader.inflector.inflect('cli' => 'CLI') -loader.inflector.inflect('ssr' => 'SSR') -loader.inflector.inflect('io' => 'IO') +loader.ignore("#{__dir__}/install") +loader.ignore("#{__dir__}/tasks") +loader.ignore("#{__dir__}/exe") +loader.inflector.inflect("cli" => "CLI") +loader.inflector.inflect("ssr" => "SSR") +loader.inflector.inflect("io" => "IO") loader.setup class ViteRuby # Internal: Prefix used for environment variables that modify the configuration. - ENV_PREFIX = 'VITE_RUBY' + ENV_PREFIX = "VITE_RUBY" # Internal: Companion libraries for Vite Ruby, and their target framework. COMPANION_LIBRARIES = { - 'vite_rails' => 'rails', - 'vite_hanami' => 'hanami', - 'vite_padrino' => 'padrino', - 'jekyll-vite' => 'jekyll', - 'vite_rails_legacy' => 'rails', - 'vite_plugin_legacy' => 'rack', + "vite_rails" => "rails", + "vite_hanami" => "hanami", + "vite_padrino" => "padrino", + "jekyll-vite" => "jekyll", + "vite_rails_legacy" => "rails", + "vite_plugin_legacy" => "rack", } class << self extend Forwardable @@ -44,26 +44,26 @@ instance.manifest.refresh end # Internal: Loads all available rake tasks. def install_tasks - load File.expand_path('tasks/vite.rake', __dir__) + load File.expand_path("tasks/vite.rake", __dir__) end # Internal: Creates a new instance with the specified options. def reload_with(**config_options) @instance = new(**config_options) end # Internal: Detects if the application has installed a framework-specific # variant of Vite Ruby. def framework_libraries - COMPANION_LIBRARIES.map { |name, framework| + COMPANION_LIBRARIES.filter_map { |name, framework| if library = Gem.loaded_specs[name] [framework, library] end - }.compact + } end end attr_writer :logger @@ -88,11 +88,11 @@ return @running if defined?(@running) && Time.now - @running_checked_at < 1 begin Socket.tcp(config.host, config.port, connect_timeout: config.dev_server_connect_timeout).close @running = true - rescue StandardError + rescue @running = false ensure @running_checked_at = Time.now end end @@ -105,13 +105,13 @@ @env ||= ENV.select { |key, _| key.start_with?(ENV_PREFIX) } end # Public: The proxy for assets should only run in development mode. def run_proxy? - config.mode == 'development' || (config.mode == 'test' && !ENV['CI']) - rescue StandardError => error - logger.error("Failed to check mode for Vite: #{ error.message }") + config.mode == "development" || (config.mode == "test" && !ENV["CI"]) + rescue => error + logger.error("Failed to check mode for Vite: #{error.message}") false end # Internal: Executes the vite binary. def run(argv, **options) @@ -147,6 +147,6 @@ def manifest @manifest ||= ViteRuby::Manifest.new(self) end end -require 'vite_ruby/version' +require "vite_ruby/version"