vite_ruby 3.8.3 → 3.9.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '09fd7e3c2f393a6a0b6db2fae56e366c29e7bb6a91c95428775eb6d452966f4f'
4
- data.tar.gz: 77a546baec0fbb12d3fa6ff82b02feed2786cf839447b3702b6863343589ed83
3
+ metadata.gz: 55db4ef1d378ff6bb8997a0397e0fa54cf965e8daa38acbd62385f5240a662c1
4
+ data.tar.gz: 4a40c9bbff8ca9c31437c11f26cc28205e7e4f9d78d776e096dbd85cc609d971
5
5
  SHA512:
6
- metadata.gz: 0fe718c389ba233b810f4fb02c5ab2f782847678bb0e04b105b276f01606c9332a8b23a9827f6ad4ec80734099f8ea514a448a1f53b81c0e7028514bd287c92c
7
- data.tar.gz: b9d5f3cd34084c1ad1c54bd4301dd86cc18fba5301a673e91ac67fc4c45c777370b1b3d4bb31d0f3588770a221ff844baf5d1680e4efdecd86ad45e45c699243
6
+ metadata.gz: 780e4335344468afca8e6244788731fdb3c51936609873fb8fa56b31109b120f3ccdd5a6c4b3ce7067135624dec4e146d1236eec2e300e52a74dda2a5cc8f542
7
+ data.tar.gz: 3e36a40cfd918be439dd550d42e4276013fe97cd6d7d8f651fecb4763a32bcbc9566eaf5368c992ddf29103a6e6de51f8b8ecb184a323a8c3bbe6654fbed9b4a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,21 @@
1
+ ## [3.9.1](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.9.0...vite_ruby@3.9.1) (2024-11-21)
2
+
3
+
4
+ ### Performance Improvements
5
+
6
+ * avoid calling `uniq` on array of hashes ([3e6ad00](https://github.com/ElMassimo/vite_ruby/commit/3e6ad001be6baacdec0597d33bc220d4242521af)), closes [#416](https://github.com/ElMassimo/vite_ruby/issues/416)
7
+
8
+
9
+
10
+ # [3.9.0](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.8.3...vite_ruby@3.9.0) (2024-10-11)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * enforce vite 5 manifest location ([#432](https://github.com/ElMassimo/vite_ruby/issues/432)) ([ce2df58](https://github.com/ElMassimo/vite_ruby/commit/ce2df5859018b3e305fc1a13443199d268dffca8)), closes [/github.com/ElMassimo/vite_ruby/blob/main/vite_ruby/lib/vite_ruby/builder.rb#L16](https://github.com//github.com/ElMassimo/vite_ruby/blob/main/vite_ruby/lib/vite_ruby/builder.rb/issues/L16)
16
+
17
+
18
+
1
19
  ## [3.8.3](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.8.2...vite_ruby@3.8.3) (2024-10-11)
2
20
 
3
21
 
data/exe/vite CHANGED
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- ENV['RAILS_ENV'] ||= ENV['RACK_ENV']
4
+ ENV["RAILS_ENV"] ||= ENV["RACK_ENV"]
5
5
 
6
- require 'bundler/setup'
7
- require 'vite_ruby'
6
+ require "bundler/setup"
7
+ require "vite_ruby"
8
8
 
9
9
  cli = ViteRuby::CLI
10
10
  cli.require_framework_libraries
data/lib/tasks/vite.rake CHANGED
@@ -2,46 +2,46 @@
2
2
 
3
3
  $stdout.sync = true
4
4
 
5
- require 'rake'
5
+ require "rake"
6
6
 
7
7
  namespace :vite do
8
8
  task :binstubs do
9
9
  ViteRuby.commands.install_binstubs
10
10
  end
11
11
 
12
- desc 'Bundle frontend entrypoints using ViteRuby'
13
- task build: :'vite:verify_install' do
12
+ desc "Bundle frontend entrypoints using ViteRuby"
13
+ task build: :"vite:verify_install" do
14
14
  ViteRuby.commands.build_from_task
15
15
  end
16
16
 
17
- desc 'Bundle a Node.js app from the SSR entrypoint using ViteRuby'
18
- task build_ssr: :'vite:verify_install' do
19
- ViteRuby.commands.build_from_task('--ssr')
17
+ desc "Bundle a Node.js app from the SSR entrypoint using ViteRuby"
18
+ task build_ssr: :"vite:verify_install" do
19
+ ViteRuby.commands.build_from_task("--ssr")
20
20
  end
21
21
 
22
- desc 'Bundle entrypoints using Vite Ruby (SSR only if enabled)'
23
- task build_all: :'vite:verify_install' do
22
+ desc "Bundle entrypoints using Vite Ruby (SSR only if enabled)"
23
+ task build_all: :"vite:verify_install" do
24
24
  ViteRuby.commands.build_from_task
25
- ViteRuby.commands.build_from_task('--ssr') if ViteRuby.config.ssr_build_enabled
25
+ ViteRuby.commands.build_from_task("--ssr") if ViteRuby.config.ssr_build_enabled
26
26
  end
27
27
 
28
- desc 'Remove the build output directory for ViteRuby'
29
- task clobber: :'vite:verify_install' do
28
+ desc "Remove the build output directory for ViteRuby"
29
+ task clobber: :"vite:verify_install" do
30
30
  ViteRuby.commands.clobber
31
31
  end
32
32
 
33
- desc 'Verify if ViteRuby is properly installed in the app'
33
+ desc "Verify if ViteRuby is properly installed in the app"
34
34
  task :verify_install do
35
35
  ViteRuby.commands.verify_install
36
36
  end
37
37
 
38
- desc 'Ensure build dependencies like Vite are installed before bundling'
38
+ desc "Ensure build dependencies like Vite are installed before bundling"
39
39
  task :install_dependencies do
40
- install_env_args = ENV['VITE_RUBY_SKIP_INSTALL_DEV_DEPENDENCIES'] == 'true' ? {} : { 'NODE_ENV' => 'development' }
40
+ install_env_args = (ENV["VITE_RUBY_SKIP_INSTALL_DEV_DEPENDENCIES"] == "true") ? {} : {"NODE_ENV" => "development"}
41
41
 
42
42
  install_cmd = case (pkg = ViteRuby.config.package_manager)
43
- when 'npm' then 'npm ci'
44
- else "#{ pkg } install --frozen-lockfile"
43
+ when "npm" then "npm ci"
44
+ else "#{pkg} install --frozen-lockfile"
45
45
  end
46
46
 
47
47
  system(install_env_args, install_cmd)
@@ -53,43 +53,43 @@ namespace :vite do
53
53
  end
54
54
  end
55
55
 
56
- unless ENV['VITE_RUBY_SKIP_ASSETS_PRECOMPILE_EXTENSION'] == 'true'
57
- if Rake::Task.task_defined?('assets:precompile')
58
- Rake::Task['assets:precompile'].enhance do |task|
56
+ unless ENV["VITE_RUBY_SKIP_ASSETS_PRECOMPILE_EXTENSION"] == "true"
57
+ if Rake::Task.task_defined?("assets:precompile")
58
+ Rake::Task["assets:precompile"].enhance do |task|
59
59
  prefix = task.name.split(/#|assets:precompile/).first
60
- unless ENV['VITE_RUBY_SKIP_ASSETS_PRECOMPILE_INSTALL'] == 'true'
61
- Rake::Task["#{ prefix }vite:install_dependencies"].invoke
60
+ unless ENV["VITE_RUBY_SKIP_ASSETS_PRECOMPILE_INSTALL"] == "true"
61
+ Rake::Task["#{prefix}vite:install_dependencies"].invoke
62
62
  end
63
- Rake::Task["#{ prefix }vite:build_all"].invoke
63
+ Rake::Task["#{prefix}vite:build_all"].invoke
64
64
  end
65
65
  else
66
- desc 'Bundle Vite assets'
67
- if ENV['VITE_RUBY_SKIP_ASSETS_PRECOMPILE_INSTALL'] == 'true'
68
- Rake::Task.define_task('assets:precompile' => 'vite:build_all')
66
+ desc "Bundle Vite assets"
67
+ if ENV["VITE_RUBY_SKIP_ASSETS_PRECOMPILE_INSTALL"] == "true"
68
+ Rake::Task.define_task("assets:precompile" => "vite:build_all")
69
69
  else
70
- Rake::Task.define_task('assets:precompile' => ['vite:install_dependencies', 'vite:build_all'])
70
+ Rake::Task.define_task("assets:precompile" => ["vite:install_dependencies", "vite:build_all"])
71
71
  end
72
72
  end
73
73
 
74
- if Rake::Task.task_defined?('assets:clobber')
75
- Rake::Task['assets:clobber'].enhance do
76
- Rake::Task['vite:clobber'].invoke
74
+ if Rake::Task.task_defined?("assets:clobber")
75
+ Rake::Task["assets:clobber"].enhance do
76
+ Rake::Task["vite:clobber"].invoke
77
77
  end
78
78
  else
79
- desc 'Remove compiled assets'
80
- Rake::Task.define_task('assets:clobber' => 'vite:clobber')
79
+ desc "Remove compiled assets"
80
+ Rake::Task.define_task("assets:clobber" => "vite:clobber")
81
81
  end
82
82
  end
83
83
 
84
84
  # Any prerequisite task that installs packages should also install build dependencies.
85
- if ARGV.include?('assets:precompile')
85
+ if ARGV.include?("assets:precompile")
86
86
  if ViteRuby.commands.legacy_npm_version?
87
- ENV['NPM_CONFIG_PRODUCTION'] = 'false'
87
+ ENV["NPM_CONFIG_PRODUCTION"] = "false"
88
88
  else
89
- ENV['NPM_CONFIG_INCLUDE'] = 'dev'
89
+ ENV["NPM_CONFIG_INCLUDE"] = "dev"
90
90
  end
91
91
 
92
92
  if ViteRuby.commands.legacy_yarn_version?
93
- ENV['YARN_PRODUCTION'] = 'false'
93
+ ENV["YARN_PRODUCTION"] = "false"
94
94
  end
95
95
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'json'
4
- require 'time'
3
+ require "json"
4
+ require "time"
5
5
 
6
6
  # Internal: Value object with information about the last build.
7
7
  ViteRuby::Build = Struct.new(:success, :timestamp, :vite_ruby, :digest, :current_digest, :last_build_path, :errors, keyword_init: true) do
@@ -28,7 +28,7 @@ ViteRuby::Build = Struct.new(:success, :timestamp, :vite_ruby, :digest, :current
28
28
 
29
29
  # Internal: To make it evident that there's no last build in error messages.
30
30
  def default_metadata
31
- { timestamp: 'never', digest: 'none' }
31
+ {timestamp: "never", digest: "none"}
32
32
  end
33
33
  end
34
34
 
@@ -56,7 +56,7 @@ ViteRuby::Build = Struct.new(:success, :timestamp, :vite_ruby, :digest, :current
56
56
  def with_result(**attrs)
57
57
  self.class.new(
58
58
  **attrs,
59
- timestamp: Time.now.strftime('%F %T'),
59
+ timestamp: Time.now.strftime("%F %T"),
60
60
  vite_ruby: ViteRuby::VERSION,
61
61
  digest: current_digest,
62
62
  current_digest: current_digest,
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'digest/sha1'
3
+ require "digest/sha1"
4
4
 
5
5
  # Public: Keeps track of watched files and triggers builds as needed.
6
6
  class ViteRuby::Builder
@@ -11,18 +11,18 @@ class ViteRuby::Builder
11
11
  # Public: Checks if the watched files have changed since the last compilation,
12
12
  # and triggers a Vite build if any files have changed.
13
13
  def build(*args)
14
- last_build = last_build_metadata(ssr: args.include?('--ssr'))
14
+ last_build = last_build_metadata(ssr: args.include?("--ssr"))
15
15
 
16
- if args.delete('--force') || last_build.stale? || config.manifest_paths.empty?
16
+ if args.delete("--force") || last_build.stale? || config.manifest_paths.empty?
17
17
  stdout, stderr, status = build_with_vite(*args)
18
18
  log_build_result(stdout, stderr, status)
19
19
  record_build_metadata(last_build, errors: stderr, success: status.success?)
20
20
  status.success?
21
21
  elsif last_build.success
22
- logger.debug "Skipping vite build. Watched files have not changed since the last build at #{ last_build.timestamp }"
22
+ logger.debug "Skipping vite build. Watched files have not changed since the last build at #{last_build.timestamp}"
23
23
  true
24
24
  else
25
- logger.error "Skipping vite build. Watched files have not changed since the build failed at #{ last_build.timestamp } ❌"
25
+ logger.error "Skipping vite build. Watched files have not changed since the build failed at #{last_build.timestamp} ❌"
26
26
  false
27
27
  end
28
28
  end
@@ -46,7 +46,7 @@ private
46
46
 
47
47
  # Internal: The file path where metadata of the last build is stored.
48
48
  def last_build_path(ssr:)
49
- config.build_cache_dir.join("last#{ '-ssr' if ssr }-build-#{ config.mode }.json")
49
+ config.build_cache_dir.join("last#{"-ssr" if ssr}-build-#{config.mode}.json")
50
50
  end
51
51
 
52
52
  # Internal: Returns a digest of all the watched files, allowing to detect
@@ -56,17 +56,17 @@ private
56
56
 
57
57
  config.within_root do
58
58
  files = Dir[*config.watched_paths].reject { |f| File.directory?(f) }
59
- file_ids = files.sort.map { |f| "#{ File.basename(f) }/#{ Digest::SHA1.file(f).hexdigest }" }
59
+ file_ids = files.sort.map { |f| "#{File.basename(f)}/#{Digest::SHA1.file(f).hexdigest}" }
60
60
  @last_digest_at = Time.now
61
- @last_digest = Digest::SHA1.hexdigest(file_ids.join('/'))
61
+ @last_digest = Digest::SHA1.hexdigest(file_ids.join("/"))
62
62
  end
63
63
  end
64
64
 
65
65
  # Public: Initiates a Vite build command to generate assets.
66
66
  def build_with_vite(*args)
67
- logger.info 'Building with Vite ⚡️'
67
+ logger.info "Building with Vite ⚡️"
68
68
 
69
- run(['build', *args])
69
+ run(["build", *args])
70
70
  end
71
71
 
72
72
  # Internal: Outputs the build results.
@@ -74,13 +74,13 @@ private
74
74
  # NOTE: By default it also outputs the manifest entries.
75
75
  def log_build_result(_stdout, stderr, status)
76
76
  if status.success?
77
- logger.info "Build with Vite complete: #{ config.build_output_dir }"
77
+ logger.info "Build with Vite complete: #{config.build_output_dir}"
78
78
  logger.error stderr unless stderr.empty?
79
79
  else
80
80
  logger.error stderr
81
81
  logger.error status
82
- logger.error 'Build with Vite failed! ❌'
83
- logger.error '❌ Check that vite and vite-plugin-ruby are in devDependencies and have been installed. ' if stderr.include?('ERR! canceled')
82
+ logger.error "Build with Vite failed! ❌"
83
+ logger.error "❌ Check that vite and vite-plugin-ruby are in devDependencies and have been installed. " if stderr.include?("ERR! canceled")
84
84
  end
85
85
  end
86
86
  end
@@ -1,14 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ViteRuby::CLI::Build < ViteRuby::CLI::Vite
4
- DEFAULT_ENV = CURRENT_ENV || 'production'
4
+ DEFAULT_ENV = CURRENT_ENV || "production"
5
5
 
6
- desc 'Bundle all entrypoints using Vite.'
6
+ desc "Bundle all entrypoints using Vite."
7
7
  shared_options
8
- option(:ssr, desc: 'Build the SSR entrypoint instead', type: :boolean)
9
- option(:force, desc: 'Force the build even if assets have not changed', type: :boolean)
10
- option(:watch, desc: 'Start the Rollup watcher and rebuild on files changes', type: :boolean)
11
- option(:profile, desc: 'Gather performance metrics from the build ', type: :boolean)
8
+ option(:ssr, desc: "Build the SSR entrypoint instead", type: :boolean)
9
+ option(:force, desc: "Force the build even if assets have not changed", type: :boolean)
10
+ option(:watch, desc: "Start the Rollup watcher and rebuild on files changes", type: :boolean)
11
+ option(:profile, desc: "Gather performance metrics from the build ", type: :boolean)
12
12
 
13
13
  def call(**options)
14
14
  super { |args| ViteRuby.commands.build_from_task(*args) }
@@ -1,14 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ViteRuby::CLI::Clobber < Dry::CLI::Command
4
- desc 'Clear the Vite cache, temp files, and builds'
4
+ desc "Clear the Vite cache, temp files, and builds"
5
5
 
6
- current_env = ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'development'
6
+ current_env = ENV["RACK_ENV"] || ENV["RAILS_ENV"] || "development"
7
7
 
8
- option(:mode, default: current_env, values: %w[development production test], aliases: ['m'], desc: 'The mode to use')
8
+ option(:mode, default: current_env, values: %w[development production test], aliases: ["m"], desc: "The mode to use")
9
9
 
10
10
  def call(mode:, **)
11
- ViteRuby.env['VITE_RUBY_MODE'] = mode
11
+ ViteRuby.env["VITE_RUBY_MODE"] = mode
12
12
  ViteRuby.commands.clobber
13
13
  end
14
14
  end
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ViteRuby::CLI::Dev < ViteRuby::CLI::Vite
4
- DEFAULT_ENV = CURRENT_ENV || 'development'
4
+ DEFAULT_ENV = CURRENT_ENV || "development"
5
5
 
6
- desc 'Start the Vite development server.'
6
+ desc "Start the Vite development server."
7
7
  shared_options
8
- option(:force, desc: 'Force Vite to re-bundle dependencies', type: :boolean)
8
+ option(:force, desc: "Force Vite to re-bundle dependencies", type: :boolean)
9
9
 
10
10
  def call(**options)
11
11
  super { |args| ViteRuby.run(args, exec: true) }
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'pathname'
4
- require 'fileutils'
3
+ require "pathname"
4
+ require "fileutils"
5
5
 
6
6
  # NOTE: Extracted from dry-cli version 0.6.0, which later removed this file as
7
7
  # it was refactored and extracted into the more complete (and complex) dry-files.
@@ -36,7 +36,7 @@ module ViteRuby::CLI::FileUtils
36
36
  return if content.join.include?(contents)
37
37
 
38
38
  content << "\n" unless content.last&.end_with?("\n")
39
- content << "#{ contents }\n"
39
+ content << "#{contents}\n"
40
40
 
41
41
  write(path, content)
42
42
  end
@@ -47,7 +47,7 @@ module ViteRuby::CLI::FileUtils
47
47
  # @api private
48
48
  def replace_first_line(path, target, replacement)
49
49
  content = read_lines(path)
50
- content[index(content, path, target)] = "#{ replacement }\n"
50
+ content[index(content, path, target)] = "#{replacement}\n"
51
51
 
52
52
  write(path, content)
53
53
  end
@@ -95,14 +95,14 @@ module ViteRuby::CLI::FileUtils
95
95
  # @api private
96
96
  def index(content, path, target)
97
97
  content.index { |line| line.include?(target) } ||
98
- raise(ArgumentError, "Cannot find `#{ target }' inside `#{ path }'.")
98
+ raise(ArgumentError, "Cannot find `#{target}' inside `#{path}'.")
99
99
  end
100
100
 
101
101
  # @since 1.2.11
102
102
  # @api private
103
103
  def rindex(content, path, target)
104
104
  content.rindex { |line| line.include?(target) } ||
105
- raise(ArgumentError, "Cannot find `#{ target }' inside `#{ path }'.")
105
+ raise(ArgumentError, "Cannot find `#{target}' inside `#{path}'.")
106
106
  end
107
107
 
108
108
  # @since 1.2.11
@@ -113,7 +113,7 @@ module ViteRuby::CLI::FileUtils
113
113
 
114
114
  i = finder.call(content, path, target)
115
115
 
116
- content.insert(i, "#{ contents }\n")
116
+ content.insert(i, "#{contents}\n")
117
117
  write(path, content)
118
118
  end
119
119
 
@@ -125,7 +125,7 @@ module ViteRuby::CLI::FileUtils
125
125
 
126
126
  i = finder.call(content, path, target)
127
127
 
128
- content.insert(i + 1, "#{ contents }\n")
128
+ content.insert(i + 1, "#{contents}\n")
129
129
  write(path, content)
130
130
  end
131
131
  end
@@ -1,31 +1,31 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'stringio'
4
- require 'json'
3
+ require "stringio"
4
+ require "json"
5
5
 
6
6
  class ViteRuby::CLI::Install < Dry::CLI::Command
7
- desc 'Performs the initial configuration setup to get started with Vite Ruby.'
7
+ desc "Performs the initial configuration setup to get started with Vite Ruby."
8
8
 
9
- option(:package_manager, values: %w[npm pnpm yarn bun], aliases: %w[package-manager with], desc: 'The package manager to use when installing JS dependencies.')
9
+ option(:package_manager, values: %w[npm pnpm yarn bun], aliases: %w[package-manager with], desc: "The package manager to use when installing JS dependencies.")
10
10
 
11
11
  def call(package_manager: nil, **)
12
- ENV['VITE_RUBY_PACKAGE_MANAGER'] ||= package_manager if package_manager
12
+ ENV["VITE_RUBY_PACKAGE_MANAGER"] ||= package_manager if package_manager
13
13
 
14
14
  $stdout.sync = true
15
15
 
16
- say 'Creating binstub'
16
+ say "Creating binstub"
17
17
  ViteRuby.commands.install_binstubs
18
18
 
19
- say 'Creating configuration files'
19
+ say "Creating configuration files"
20
20
  create_configuration_files
21
21
 
22
- say 'Installing sample files'
22
+ say "Installing sample files"
23
23
  install_sample_files
24
24
 
25
- say 'Installing js dependencies'
25
+ say "Installing js dependencies"
26
26
  install_js_dependencies
27
27
 
28
- say 'Adding files to .gitignore'
28
+ say "Adding files to .gitignore"
29
29
  install_gitignore
30
30
 
31
31
  say "\nVite ⚡️ Ruby successfully installed! 🎉"
@@ -36,30 +36,30 @@ protected
36
36
  # Internal: The JS packages that should be added to the app.
37
37
  def js_dependencies
38
38
  [
39
- "vite@#{ ViteRuby::DEFAULT_VITE_VERSION }",
40
- "vite-plugin-ruby@#{ ViteRuby::DEFAULT_PLUGIN_VERSION }",
39
+ "vite@#{ViteRuby::DEFAULT_VITE_VERSION}",
40
+ "vite-plugin-ruby@#{ViteRuby::DEFAULT_PLUGIN_VERSION}",
41
41
  ]
42
42
  end
43
43
 
44
44
  # Internal: Setup for a plain Rack application.
45
45
  def setup_app_files
46
- copy_template 'config/vite.json', to: config.config_path
46
+ copy_template "config/vite.json", to: config.config_path
47
47
 
48
- if (rackup_file = root.join('config.ru')).exist?
49
- inject_line_after_last rackup_file, 'require', 'use(ViteRuby::DevServerProxy, ssl_verify_none: true) if ViteRuby.run_proxy?'
48
+ if (rackup_file = root.join("config.ru")).exist?
49
+ inject_line_after_last rackup_file, "require", "use(ViteRuby::DevServerProxy, ssl_verify_none: true) if ViteRuby.run_proxy?"
50
50
  end
51
51
  end
52
52
 
53
53
  # Internal: Create a sample JS file and attempt to inject it in an HTML template.
54
54
  def install_sample_files
55
- copy_template 'entrypoints/application.js', to: config.resolved_entrypoints_dir.join('application.js')
55
+ copy_template "entrypoints/application.js", to: config.resolved_entrypoints_dir.join("application.js")
56
56
  end
57
57
 
58
58
  private
59
59
 
60
60
  extend Forwardable
61
61
 
62
- def_delegators 'ViteRuby', :config
62
+ def_delegators "ViteRuby", :config
63
63
 
64
64
  %i[append cp inject_line_after inject_line_after_last inject_line_before replace_first_line write].each do |util|
65
65
  define_method(util) { |*args|
@@ -67,7 +67,7 @@ private
67
67
  }
68
68
  end
69
69
 
70
- TEMPLATES_PATH = Pathname.new(File.expand_path('../../../templates', __dir__))
70
+ TEMPLATES_PATH = Pathname.new(File.expand_path("../../../templates", __dir__))
71
71
 
72
72
  def copy_template(path, to:)
73
73
  cp TEMPLATES_PATH.join(path), to
@@ -75,15 +75,15 @@ private
75
75
 
76
76
  # Internal: Creates the Vite and vite-plugin-ruby configuration files.
77
77
  def create_configuration_files
78
- copy_template 'config/vite.config.ts', to: root.join('vite.config.ts')
79
- append root.join('Procfile.dev'), 'vite: bin/vite dev'
78
+ copy_template "config/vite.config.ts", to: root.join("vite.config.ts")
79
+ append root.join("Procfile.dev"), "vite: bin/vite dev"
80
80
  setup_app_files
81
81
  ViteRuby.reload_with(config_path: config.config_path)
82
82
  end
83
83
 
84
84
  # Internal: Installs vite and vite-plugin-ruby at the project level.
85
85
  def install_js_dependencies
86
- package_json = root.join('package.json')
86
+ package_json = root.join("package.json")
87
87
  unless package_json.exist?
88
88
  write package_json, <<~JSON
89
89
  {
@@ -93,16 +93,16 @@ private
93
93
  JSON
94
94
  end
95
95
 
96
- if (JSON.parse(package_json.read)['type'] != 'module' rescue nil)
97
- FileUtils.mv root.join('vite.config.ts'), root.join('vite.config.mts'), force: true, verbose: true
96
+ if (JSON.parse(package_json.read)["type"] != "module" rescue nil)
97
+ FileUtils.mv root.join("vite.config.ts"), root.join("vite.config.mts"), force: true, verbose: true
98
98
  end
99
99
 
100
- install_js_packages js_dependencies.join(' ')
100
+ install_js_packages js_dependencies.join(" ")
101
101
  end
102
102
 
103
103
  # Internal: Adds compilation output dirs to git ignore.
104
104
  def install_gitignore
105
- return unless (gitignore_file = root.join('.gitignore')).exist?
105
+ return unless (gitignore_file = root.join(".gitignore")).exist?
106
106
 
107
107
  append(gitignore_file, <<~GITIGNORE)
108
108
 
@@ -132,7 +132,7 @@ private
132
132
  end
133
133
 
134
134
  def install_js_packages(deps)
135
- run_with_capture("#{ config.package_manager } add -D #{ deps }", stdin_data: "\n")
135
+ run_with_capture("#{config.package_manager} add -D #{deps}", stdin_data: "\n")
136
136
  end
137
137
 
138
138
  # Internal: Avoid printing warning about missing vite.json, we will create one.
@@ -1,25 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ViteRuby::CLI::SSR < ViteRuby::CLI::Vite
4
- DEFAULT_ENV = CURRENT_ENV || 'production'
4
+ DEFAULT_ENV = CURRENT_ENV || "production"
5
5
  JS_EXTENSIONS = %w[js mjs cjs]
6
6
 
7
- desc 'Run the resulting app from building in SSR mode.'
7
+ desc "Run the resulting app from building in SSR mode."
8
8
  executable_options
9
9
 
10
10
  def call(mode:, inspect: false, trace_deprecation: false)
11
- ViteRuby.env['VITE_RUBY_MODE'] = mode
11
+ ViteRuby.env["VITE_RUBY_MODE"] = mode
12
12
 
13
13
  ssr_entrypoint = JS_EXTENSIONS
14
- .map { |ext| ViteRuby.config.ssr_output_dir.join("ssr.#{ ext }") }
14
+ .map { |ext| ViteRuby.config.ssr_output_dir.join("ssr.#{ext}") }
15
15
  .find(&:exist?)
16
16
 
17
- raise ArgumentError, "No ssr entrypoint found `#{ ViteRuby.config.ssr_output_dir.relative_path_from(ViteRuby.config.root) }/ssr.{#{ JS_EXTENSIONS.join(',') }}`. Have you run bin/vite build --ssr?" unless ssr_entrypoint
17
+ raise ArgumentError, "No ssr entrypoint found `#{ViteRuby.config.ssr_output_dir.relative_path_from(ViteRuby.config.root)}/ssr.{#{JS_EXTENSIONS.join(",")}}`. Have you run bin/vite build --ssr?" unless ssr_entrypoint
18
18
 
19
19
  cmd = [
20
- 'node',
21
- ('--inspect-brk' if inspect),
22
- ('--trace-deprecation' if trace_deprecation),
20
+ "node",
21
+ ("--inspect-brk" if inspect),
22
+ ("--trace-deprecation" if trace_deprecation),
23
23
  ssr_entrypoint,
24
24
  ]
25
25
  Kernel.exec(*cmd.compact.map(&:to_s))
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ViteRuby::CLI::Upgrade < ViteRuby::CLI::Install
4
- desc 'Updates Vite Ruby related gems and npm packages.'
4
+ desc "Updates Vite Ruby related gems and npm packages."
5
5
 
6
6
  def call(**)
7
7
  upgrade_ruby_gems
@@ -11,15 +11,15 @@ class ViteRuby::CLI::Upgrade < ViteRuby::CLI::Install
11
11
  protected
12
12
 
13
13
  def upgrade_ruby_gems
14
- say 'Updating gems'
14
+ say "Updating gems"
15
15
 
16
16
  libraries = ViteRuby.framework_libraries.map { |_f, library| library.name }
17
17
 
18
- run_with_capture("bundle update #{ libraries.join(' ') }")
18
+ run_with_capture("bundle update #{libraries.join(" ")}")
19
19
  end
20
20
 
21
21
  # NOTE: Spawn a new process so that it uses the updated vite_ruby.
22
22
  def upgrade_npm_packages
23
- Kernel.exec('bundle exec vite upgrade_packages')
23
+ Kernel.exec("bundle exec vite upgrade_packages")
24
24
  end
25
25
  end
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ViteRuby::CLI::UpgradePackages < ViteRuby::CLI::Install
4
- desc 'Upgrades the npm packages to the recommended versions.'
4
+ desc "Upgrades the npm packages to the recommended versions."
5
5
 
6
6
  def call(**)
7
- say 'Upgrading npm packages'
8
- install_js_packages js_dependencies.join(' ')
7
+ say "Upgrading npm packages"
8
+ install_js_packages js_dependencies.join(" ")
9
9
  end
10
10
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ViteRuby::CLI::Version < Dry::CLI::Command
4
- desc 'Print version'
4
+ desc "Print version"
5
5
 
6
6
  def call(**)
7
7
  ViteRuby.commands.print_info