vite_ruby 3.9.0 → 3.9.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -19,20 +19,20 @@ class ViteRuby::Manifest
19
19
  #
20
20
  # Raises an error if the resource could not be found in the manifest.
21
21
  def path_for(name, **options)
22
- lookup!(name, **options).fetch('file')
22
+ lookup!(name, **options).fetch("file")
23
23
  end
24
24
 
25
25
  # Public: Returns scripts, imported modules, and stylesheets for the specified
26
26
  # entrypoint files.
27
27
  def resolve_entries(*names, **options)
28
28
  entries = names.map { |name| lookup!(name, **options) }
29
- script_paths = entries.map { |entry| entry.fetch('file') }
29
+ script_paths = entries.map { |entry| entry.fetch("file") }
30
30
 
31
- imports = dev_server_running? ? [] : entries.flat_map { |entry| entry['imports'] }.compact.uniq
31
+ imports = dev_server_running? ? [] : entries.flat_map { |entry| entry["imports"] }.compact
32
32
  {
33
33
  scripts: script_paths,
34
- imports: imports.map { |entry| entry.fetch('file') }.uniq,
35
- stylesheets: dev_server_running? ? [] : (entries + imports).flat_map { |entry| entry['css'] }.compact.uniq,
34
+ imports: imports.filter_map { |entry| entry.fetch("file") }.uniq,
35
+ stylesheets: dev_server_running? ? [] : (entries + imports).flat_map { |entry| entry["css"] }.compact.uniq,
36
36
  }
37
37
  end
38
38
 
@@ -43,7 +43,7 @@ class ViteRuby::Manifest
43
43
 
44
44
  # Public: The path from where the browser can download the Vite HMR client.
45
45
  def vite_client_src
46
- prefix_asset_with_host('@vite/client') if dev_server_running?
46
+ prefix_asset_with_host("@vite/client") if dev_server_running?
47
47
  end
48
48
 
49
49
  # Public: The content of the preamble needed by the React Refresh plugin.
@@ -51,7 +51,7 @@ class ViteRuby::Manifest
51
51
  if dev_server_running?
52
52
  <<~REACT_REFRESH
53
53
  <script type="module">
54
- #{ react_preamble_code }
54
+ #{react_preamble_code}
55
55
  </script>
56
56
  REACT_REFRESH
57
57
  end
@@ -61,7 +61,7 @@ class ViteRuby::Manifest
61
61
  def react_preamble_code
62
62
  if dev_server_running?
63
63
  <<~REACT_PREAMBLE_CODE
64
- import RefreshRuntime from '#{ prefix_asset_with_host('@react-refresh') }'
64
+ import RefreshRuntime from '#{prefix_asset_with_host("@react-refresh")}'
65
65
  RefreshRuntime.injectIntoGlobalHook(window)
66
66
  window.$RefreshReg$ = () => {}
67
67
  window.$RefreshSig$ = () => (type) => type
@@ -95,7 +95,7 @@ protected
95
95
  private
96
96
 
97
97
  # Internal: The prefix used by Vite.js to request files with an absolute path.
98
- FS_PREFIX = '/@fs/'
98
+ FS_PREFIX = "/@fs/"
99
99
 
100
100
  extend Forwardable
101
101
 
@@ -110,7 +110,7 @@ private
110
110
  # Internal: Finds the specified entry in the manifest.
111
111
  def find_manifest_entry(name)
112
112
  if dev_server_running?
113
- { 'file' => prefix_vite_asset(name) }
113
+ {"file" => prefix_vite_asset(name)}
114
114
  else
115
115
  manifest[name]
116
116
  end
@@ -128,19 +128,21 @@ private
128
128
 
129
129
  # Internal: Loads and merges the manifest files, resolving the asset paths.
130
130
  def load_manifest
131
- files = config.manifest_paths
132
- files.map { |path| JSON.parse(path.read) }.inject({}, &:merge).tap(&method(:resolve_references))
131
+ config.manifest_paths
132
+ .map { |path| JSON.parse(path.read) }
133
+ .inject({}, &:merge)
134
+ .tap { |manifest| resolve_references(manifest) }
133
135
  end
134
136
 
135
137
  # Internal: Scopes an asset to the output folder in public, as a path.
136
138
  def prefix_vite_asset(path)
137
- File.join(vite_asset_origin || '/', config.public_output_dir, path)
139
+ File.join(vite_asset_origin || "/", config.public_output_dir, path)
138
140
  end
139
141
 
140
142
  # Internal: Prefixes an asset with the `asset_host` for tags that do not use
141
143
  # the framework tag helpers.
142
144
  def prefix_asset_with_host(path)
143
- File.join(vite_asset_origin || config.asset_host || '/', config.public_output_dir, path)
145
+ File.join(vite_asset_origin || config.asset_host || "/", config.public_output_dir, path)
144
146
  end
145
147
 
146
148
  # Internal: The origin of assets managed by Vite.
@@ -151,11 +153,11 @@ private
151
153
  # Internal: Resolves the paths that reference a manifest entry.
152
154
  def resolve_references(manifest)
153
155
  manifest.each_value do |entry|
154
- entry['file'] = prefix_vite_asset(entry['file'])
156
+ entry["file"] = prefix_vite_asset(entry["file"])
155
157
  %w[css assets].each do |key|
156
158
  entry[key] = entry[key].map { |path| prefix_vite_asset(path) } if entry[key]
157
159
  end
158
- entry['imports']&.map! { |name| manifest.fetch(name) }
160
+ entry["imports"]&.map! { |name| manifest.fetch(name) }
159
161
  end
160
162
  end
161
163
 
@@ -164,7 +166,7 @@ private
164
166
  return resolve_virtual_entry(name) if type == :virtual
165
167
 
166
168
  name = with_file_extension(name.to_s, type)
167
- raise ArgumentError, "Asset names can not be relative. Found: #{ name }" if name.start_with?('.')
169
+ raise ArgumentError, "Asset names can not be relative. Found: #{name}" if name.start_with?(".")
168
170
 
169
171
  # Explicit path, relative to the source_code_dir.
170
172
  name.sub(%r{^~/(.+)$}) { return Regexp.last_match(1) }
@@ -173,7 +175,7 @@ private
173
175
  name.sub(%r{^/(.+)$}) { return resolve_absolute_entry(Regexp.last_match(1)) }
174
176
 
175
177
  # Sugar: Prefix with the entrypoints dir if the path is not nested.
176
- name.include?('/') ? name : File.join(config.entrypoints_dir, name)
178
+ name.include?("/") ? name : File.join(config.entrypoints_dir, name)
177
179
  end
178
180
 
179
181
  # Internal: Entry names in the manifest are relative to the Vite.js.
@@ -194,7 +196,7 @@ private
194
196
  # Internal: Adds a file extension to the file name, unless it already has one.
195
197
  def with_file_extension(name, entry_type)
196
198
  if File.extname(name).empty? && (ext = extension_for_type(entry_type))
197
- "#{ name }.#{ ext }"
199
+ "#{name}.#{ext}"
198
200
  else
199
201
  name
200
202
  end
@@ -203,9 +205,9 @@ private
203
205
  # Internal: Allows to receive :javascript and :stylesheet as :type in helpers.
204
206
  def extension_for_type(entry_type)
205
207
  case entry_type
206
- when :javascript then 'js'
207
- when :stylesheet then 'css'
208
- when :typescript then 'ts'
208
+ when :javascript then "js"
209
+ when :stylesheet then "css"
210
+ when :typescript then "ts"
209
211
  else entry_type
210
212
  end
211
213
  end
@@ -10,22 +10,22 @@ class ViteRuby::MissingEntrypointError < ViteRuby::Error
10
10
  def initialize(file_name:, last_build:, manifest:, config:)
11
11
  @file_name, @last_build, @manifest, @config = file_name, last_build, manifest, config
12
12
  super <<~MSG
13
- Vite Ruby can't find #{ file_name } in the manifests.
13
+ Vite Ruby can't find #{file_name} in the manifests.
14
14
 
15
15
  Possible causes:
16
- #{ possible_causes(last_build) }
16
+ #{possible_causes(last_build)}
17
17
  :troubleshooting:
18
- #{ "Manifest files found:\n#{ config.manifest_paths.map { |path| " #{ path.relative_path_from(config.root) }" }.join("\n") }\n" if last_build.success }
19
- #{ "Content in your manifests:\n#{ JSON.pretty_generate(manifest) }\n" if last_build.success }
20
- #{ "Last build in #{ config.mode } mode:\n#{ last_build.to_json }\n" if last_build.success }
18
+ #{"Manifest files found:\n#{config.manifest_paths.map { |path| " #{path.relative_path_from(config.root)}" }.join("\n")}\n" if last_build.success}
19
+ #{"Content in your manifests:\n#{JSON.pretty_generate(manifest)}\n" if last_build.success}
20
+ #{"Last build in #{config.mode} mode:\n#{last_build.to_json}\n" if last_build.success}
21
21
  MSG
22
22
  end
23
23
 
24
24
  def possible_causes(last_build)
25
25
  if last_build.success == false
26
26
  FAILED_BUILD_CAUSES
27
- .sub(':mode:', config.mode)
28
- .sub(':errors:', last_build.errors.to_s.gsub(/^(?!$)/, ' '))
27
+ .sub(":mode:", config.mode)
28
+ .sub(":errors:", last_build.errors.to_s.gsub(/^(?!$)/, " "))
29
29
  elsif config.auto_build
30
30
  DEFAULT_CAUSES
31
31
  else
@@ -7,7 +7,7 @@ class ViteRuby::MissingExecutableError < ViteRuby::Error
7
7
  ❌ The vite binary is not available. Have you installed the npm packages?
8
8
 
9
9
  :troubleshooting:
10
- #{ error }
10
+ #{error}
11
11
  MSG
12
12
  end
13
13
  end
@@ -12,7 +12,7 @@ class ViteRuby::Runner
12
12
  cmd = command_for(argv)
13
13
  return Kernel.exec(*cmd) if exec
14
14
 
15
- log_or_noop = ->(line) { logger.info('vite') { line } } unless config.hide_build_console_output
15
+ log_or_noop = ->(line) { logger.info("vite") { line } } unless config.hide_build_console_output
16
16
  ViteRuby::IO.capture(*cmd, chdir: config.root, with_output: log_or_noop)
17
17
  }
18
18
  rescue Errno::ENOENT => error
@@ -28,10 +28,10 @@ private
28
28
  # Internal: Returns an Array with the command to run.
29
29
  def command_for(args)
30
30
  [config.to_env(env)].tap do |cmd|
31
- exec_args, vite_args = args.partition { |arg| arg.start_with?('--node-options') }
31
+ exec_args, vite_args = args.partition { |arg| arg.start_with?("--node-options") }
32
32
  cmd.push(*vite_executable(*exec_args))
33
33
  cmd.push(*vite_args)
34
- cmd.push('--mode', config.mode) unless args.include?('--mode') || args.include?('-m')
34
+ cmd.push("--mode", config.mode) unless args.include?("--mode") || args.include?("-m")
35
35
  end
36
36
  end
37
37
 
@@ -41,13 +41,13 @@ private
41
41
  return [bin_path] if bin_path && File.exist?(bin_path)
42
42
 
43
43
  x = case config.package_manager
44
- when 'npm' then %w[npx]
45
- when 'pnpm' then %w[pnpm exec]
46
- when 'bun' then %w[bun x --bun]
47
- when 'yarn' then %w[yarn]
48
- else raise ArgumentError, "Unknown package manager #{ config.package_manager.inspect }"
44
+ when "npm" then %w[npx]
45
+ when "pnpm" then %w[pnpm exec]
46
+ when "bun" then %w[bun x --bun]
47
+ when "yarn" then %w[yarn]
48
+ else raise ArgumentError, "Unknown package manager #{config.package_manager.inspect}"
49
49
  end
50
50
 
51
- [*x, *exec_args, 'vite']
51
+ [*x, *exec_args, "vite"]
52
52
  end
53
53
  end
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ViteRuby
4
- VERSION = '3.9.0'
4
+ VERSION = "3.9.1"
5
5
 
6
6
  # Internal: Versions used by default when running `vite install`.
7
- DEFAULT_VITE_VERSION = '^5.0.0'
8
- DEFAULT_PLUGIN_VERSION = '^5.1.0'
7
+ DEFAULT_VITE_VERSION = "^5.0.0"
8
+ DEFAULT_PLUGIN_VERSION = "^5.1.0"
9
9
  end
data/lib/vite_ruby.rb CHANGED
@@ -1,32 +1,32 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'logger'
4
- require 'forwardable'
5
- require 'pathname'
6
- require 'socket'
3
+ require "logger"
4
+ require "forwardable"
5
+ require "pathname"
6
+ require "socket"
7
7
 
8
- require 'zeitwerk'
8
+ require "zeitwerk"
9
9
  loader = Zeitwerk::Loader.for_gem
10
- loader.ignore("#{ __dir__ }/install")
11
- loader.ignore("#{ __dir__ }/tasks")
12
- loader.ignore("#{ __dir__ }/exe")
13
- loader.inflector.inflect('cli' => 'CLI')
14
- loader.inflector.inflect('ssr' => 'SSR')
15
- loader.inflector.inflect('io' => 'IO')
10
+ loader.ignore("#{__dir__}/install")
11
+ loader.ignore("#{__dir__}/tasks")
12
+ loader.ignore("#{__dir__}/exe")
13
+ loader.inflector.inflect("cli" => "CLI")
14
+ loader.inflector.inflect("ssr" => "SSR")
15
+ loader.inflector.inflect("io" => "IO")
16
16
  loader.setup
17
17
 
18
18
  class ViteRuby
19
19
  # Internal: Prefix used for environment variables that modify the configuration.
20
- ENV_PREFIX = 'VITE_RUBY'
20
+ ENV_PREFIX = "VITE_RUBY"
21
21
 
22
22
  # Internal: Companion libraries for Vite Ruby, and their target framework.
23
23
  COMPANION_LIBRARIES = {
24
- 'vite_rails' => 'rails',
25
- 'vite_hanami' => 'hanami',
26
- 'vite_padrino' => 'padrino',
27
- 'jekyll-vite' => 'jekyll',
28
- 'vite_rails_legacy' => 'rails',
29
- 'vite_plugin_legacy' => 'rack',
24
+ "vite_rails" => "rails",
25
+ "vite_hanami" => "hanami",
26
+ "vite_padrino" => "padrino",
27
+ "jekyll-vite" => "jekyll",
28
+ "vite_rails_legacy" => "rails",
29
+ "vite_plugin_legacy" => "rack",
30
30
  }
31
31
 
32
32
  class << self
@@ -46,7 +46,7 @@ class ViteRuby
46
46
 
47
47
  # Internal: Loads all available rake tasks.
48
48
  def install_tasks
49
- load File.expand_path('tasks/vite.rake', __dir__)
49
+ load File.expand_path("tasks/vite.rake", __dir__)
50
50
  end
51
51
 
52
52
  # Internal: Creates a new instance with the specified options.
@@ -57,11 +57,11 @@ class ViteRuby
57
57
  # Internal: Detects if the application has installed a framework-specific
58
58
  # variant of Vite Ruby.
59
59
  def framework_libraries
60
- COMPANION_LIBRARIES.map { |name, framework|
60
+ COMPANION_LIBRARIES.filter_map { |name, framework|
61
61
  if library = Gem.loaded_specs[name]
62
62
  [framework, library]
63
63
  end
64
- }.compact
64
+ }
65
65
  end
66
66
  end
67
67
 
@@ -90,7 +90,7 @@ class ViteRuby
90
90
  begin
91
91
  Socket.tcp(config.host, config.port, connect_timeout: config.dev_server_connect_timeout).close
92
92
  @running = true
93
- rescue StandardError
93
+ rescue
94
94
  @running = false
95
95
  ensure
96
96
  @running_checked_at = Time.now
@@ -107,9 +107,9 @@ class ViteRuby
107
107
 
108
108
  # Public: The proxy for assets should only run in development mode.
109
109
  def run_proxy?
110
- config.mode == 'development' || (config.mode == 'test' && !ENV['CI'])
111
- rescue StandardError => error
112
- logger.error("Failed to check mode for Vite: #{ error.message }")
110
+ config.mode == "development" || (config.mode == "test" && !ENV["CI"])
111
+ rescue => error
112
+ logger.error("Failed to check mode for Vite: #{error.message}")
113
113
  false
114
114
  end
115
115
 
@@ -149,4 +149,4 @@ class ViteRuby
149
149
  end
150
150
  end
151
151
 
152
- require 'vite_ruby/version'
152
+ require "vite_ruby/version"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vite_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.9.0
4
+ version: 3.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Máximo Mussini
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-10-11 00:00:00.000000000 Z
11
+ date: 2024-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-cli
@@ -44,6 +44,20 @@ dependencies:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
46
  version: '1.6'
47
+ - !ruby/object:Gem::Dependency
48
+ name: mutex_m
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
47
61
  - !ruby/object:Gem::Dependency
48
62
  name: rack-proxy
49
63
  requirement: !ruby/object:Gem::Requirement
@@ -222,8 +236,9 @@ homepage: https://github.com/ElMassimo/vite_ruby
222
236
  licenses:
223
237
  - MIT
224
238
  metadata:
225
- source_code_uri: https://github.com/ElMassimo/vite_ruby/tree/vite_ruby@3.9.0/vite_ruby
226
- changelog_uri: https://github.com/ElMassimo/vite_ruby/blob/vite_ruby@3.9.0/vite_ruby/CHANGELOG.md
239
+ source_code_uri: https://github.com/ElMassimo/vite_ruby/tree/vite_ruby@3.9.1/vite_ruby
240
+ changelog_uri: https://github.com/ElMassimo/vite_ruby/blob/vite_ruby@3.9.1/vite_ruby/CHANGELOG.md
241
+ rubygems_mfa_required: 'true'
227
242
  post_install_message: "Thanks for installing Vite Ruby!\n\nIf you upgraded the gem
228
243
  manually, please run:\n\tbundle exec vite upgrade"
229
244
  rdoc_options: []
@@ -240,7 +255,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
240
255
  - !ruby/object:Gem::Version
241
256
  version: '0'
242
257
  requirements: []
243
- rubygems_version: 3.3.7
258
+ rubygems_version: 3.5.16
244
259
  signing_key:
245
260
  specification_version: 4
246
261
  summary: Use Vite in Ruby and bring joy to your JavaScript experience