vite_ruby 3.9.0 → 3.9.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/CHANGELOG.md +18 -0
- data/exe/vite +3 -3
- data/lib/tasks/vite.rake +35 -35
- data/lib/vite_ruby/build.rb +4 -4
- data/lib/vite_ruby/builder.rb +13 -13
- data/lib/vite_ruby/cli/build.rb +6 -6
- data/lib/vite_ruby/cli/clobber.rb +4 -4
- data/lib/vite_ruby/cli/dev.rb +3 -3
- data/lib/vite_ruby/cli/file_utils.rb +8 -8
- data/lib/vite_ruby/cli/install.rb +26 -26
- data/lib/vite_ruby/cli/ssr.rb +8 -8
- data/lib/vite_ruby/cli/upgrade.rb +4 -4
- data/lib/vite_ruby/cli/upgrade_packages.rb +3 -3
- data/lib/vite_ruby/cli/version.rb +1 -1
- data/lib/vite_ruby/cli/vite.rb +13 -13
- data/lib/vite_ruby/cli.rb +13 -13
- data/lib/vite_ruby/commands.rb +17 -17
- data/lib/vite_ruby/compatibility_check.rb +7 -7
- data/lib/vite_ruby/config.rb +39 -38
- data/lib/vite_ruby/dev_server_proxy.rb +21 -20
- data/lib/vite_ruby/error.rb +1 -1
- data/lib/vite_ruby/io.rb +3 -3
- data/lib/vite_ruby/manifest.rb +24 -22
- data/lib/vite_ruby/missing_entrypoint_error.rb +7 -7
- data/lib/vite_ruby/missing_executable_error.rb +1 -1
- data/lib/vite_ruby/runner.rb +9 -9
- data/lib/vite_ruby/version.rb +3 -3
- data/lib/vite_ruby.rb +26 -26
- metadata +22 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba95591fae6501dc4fb3bbc68126442bc17ad0feff1efabcf295e8cd28e5ae75
|
4
|
+
data.tar.gz: 115ad722326ce5b6c2e1d6ccdc87f1b19926c6aa6f4385365b726085703aac63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37bb1edf9d083402a72553f49afb784aa9a9908e892b73d1112516baca40eaff6dcecb6d413f726cb8a9233ee1704725360abe4fb4a47d73a31397e3cbb89498
|
7
|
+
data.tar.gz: 4e61b6ee27a01a35c418996769783ccbb3a84f1be8c1b78ad4b9042b59d997f37641578c30073bfe6880c2303a2eb90d44c98df09d097b35d8f3959ce0997852
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,21 @@
|
|
1
|
+
## [3.9.2](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.9.1...vite_ruby@3.9.2) (2025-03-26)
|
2
|
+
|
3
|
+
|
4
|
+
### Features
|
5
|
+
|
6
|
+
* update `detect_package_manager` to look for new Bun lockfile ([#530](https://github.com/ElMassimo/vite_ruby/issues/530)) ([eca05a3](https://github.com/ElMassimo/vite_ruby/commit/eca05a3021250736776746e4711066a1e00fde68))
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
## [3.9.1](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.9.0...vite_ruby@3.9.1) (2024-11-21)
|
11
|
+
|
12
|
+
|
13
|
+
### Performance Improvements
|
14
|
+
|
15
|
+
* 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)
|
16
|
+
|
17
|
+
|
18
|
+
|
1
19
|
# [3.9.0](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.8.3...vite_ruby@3.9.0) (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[
|
4
|
+
ENV["RAILS_ENV"] ||= ENV["RACK_ENV"]
|
5
5
|
|
6
|
-
require
|
7
|
-
require
|
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
|
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
|
13
|
-
task build: :
|
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
|
18
|
-
task build_ssr: :
|
19
|
-
ViteRuby.commands.build_from_task(
|
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
|
23
|
-
task build_all: :
|
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(
|
25
|
+
ViteRuby.commands.build_from_task("--ssr") if ViteRuby.config.ssr_build_enabled
|
26
26
|
end
|
27
27
|
|
28
|
-
desc
|
29
|
-
task clobber: :
|
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
|
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
|
38
|
+
desc "Ensure build dependencies like Vite are installed before bundling"
|
39
39
|
task :install_dependencies do
|
40
|
-
install_env_args = ENV[
|
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
|
44
|
-
else "#{
|
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[
|
57
|
-
if Rake::Task.task_defined?(
|
58
|
-
Rake::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[
|
61
|
-
Rake::Task["#{
|
60
|
+
unless ENV["VITE_RUBY_SKIP_ASSETS_PRECOMPILE_INSTALL"] == "true"
|
61
|
+
Rake::Task["#{prefix}vite:install_dependencies"].invoke
|
62
62
|
end
|
63
|
-
Rake::Task["#{
|
63
|
+
Rake::Task["#{prefix}vite:build_all"].invoke
|
64
64
|
end
|
65
65
|
else
|
66
|
-
desc
|
67
|
-
if ENV[
|
68
|
-
Rake::Task.define_task(
|
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(
|
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?(
|
75
|
-
Rake::Task[
|
76
|
-
Rake::Task[
|
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
|
80
|
-
Rake::Task.define_task(
|
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?(
|
85
|
+
if ARGV.include?("assets:precompile")
|
86
86
|
if ViteRuby.commands.legacy_npm_version?
|
87
|
-
ENV[
|
87
|
+
ENV["NPM_CONFIG_PRODUCTION"] = "false"
|
88
88
|
else
|
89
|
-
ENV[
|
89
|
+
ENV["NPM_CONFIG_INCLUDE"] = "dev"
|
90
90
|
end
|
91
91
|
|
92
92
|
if ViteRuby.commands.legacy_yarn_version?
|
93
|
-
ENV[
|
93
|
+
ENV["YARN_PRODUCTION"] = "false"
|
94
94
|
end
|
95
95
|
end
|
data/lib/vite_ruby/build.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
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
|
-
{
|
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(
|
59
|
+
timestamp: Time.now.strftime("%F %T"),
|
60
60
|
vite_ruby: ViteRuby::VERSION,
|
61
61
|
digest: current_digest,
|
62
62
|
current_digest: current_digest,
|
data/lib/vite_ruby/builder.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
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?(
|
14
|
+
last_build = last_build_metadata(ssr: args.include?("--ssr"))
|
15
15
|
|
16
|
-
if args.delete(
|
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 #{
|
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 #{
|
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#{
|
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| "#{
|
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
|
67
|
+
logger.info "Building with Vite ⚡️"
|
68
68
|
|
69
|
-
run([
|
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: #{
|
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
|
83
|
-
logger.error
|
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
|
data/lib/vite_ruby/cli/build.rb
CHANGED
@@ -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 ||
|
4
|
+
DEFAULT_ENV = CURRENT_ENV || "production"
|
5
5
|
|
6
|
-
desc
|
6
|
+
desc "Bundle all entrypoints using Vite."
|
7
7
|
shared_options
|
8
|
-
option(:ssr, desc:
|
9
|
-
option(:force, desc:
|
10
|
-
option(:watch, desc:
|
11
|
-
option(:profile, desc:
|
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
|
4
|
+
desc "Clear the Vite cache, temp files, and builds"
|
5
5
|
|
6
|
-
current_env = ENV[
|
6
|
+
current_env = ENV["RACK_ENV"] || ENV["RAILS_ENV"] || "development"
|
7
7
|
|
8
|
-
option(:mode, default: current_env, values: %w[development production test], aliases: [
|
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[
|
11
|
+
ViteRuby.env["VITE_RUBY_MODE"] = mode
|
12
12
|
ViteRuby.commands.clobber
|
13
13
|
end
|
14
14
|
end
|
data/lib/vite_ruby/cli/dev.rb
CHANGED
@@ -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 ||
|
4
|
+
DEFAULT_ENV = CURRENT_ENV || "development"
|
5
5
|
|
6
|
-
desc
|
6
|
+
desc "Start the Vite development server."
|
7
7
|
shared_options
|
8
|
-
option(:force, desc:
|
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
|
4
|
-
require
|
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 << "#{
|
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)] = "#{
|
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 `#{
|
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 `#{
|
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, "#{
|
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, "#{
|
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
|
4
|
-
require
|
3
|
+
require "stringio"
|
4
|
+
require "json"
|
5
5
|
|
6
6
|
class ViteRuby::CLI::Install < Dry::CLI::Command
|
7
|
-
desc
|
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:
|
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[
|
12
|
+
ENV["VITE_RUBY_PACKAGE_MANAGER"] ||= package_manager if package_manager
|
13
13
|
|
14
14
|
$stdout.sync = true
|
15
15
|
|
16
|
-
say
|
16
|
+
say "Creating binstub"
|
17
17
|
ViteRuby.commands.install_binstubs
|
18
18
|
|
19
|
-
say
|
19
|
+
say "Creating configuration files"
|
20
20
|
create_configuration_files
|
21
21
|
|
22
|
-
say
|
22
|
+
say "Installing sample files"
|
23
23
|
install_sample_files
|
24
24
|
|
25
|
-
say
|
25
|
+
say "Installing js dependencies"
|
26
26
|
install_js_dependencies
|
27
27
|
|
28
|
-
say
|
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@#{
|
40
|
-
"vite-plugin-ruby@#{
|
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
|
46
|
+
copy_template "config/vite.json", to: config.config_path
|
47
47
|
|
48
|
-
if (rackup_file = root.join(
|
49
|
-
inject_line_after_last rackup_file,
|
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
|
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
|
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(
|
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
|
79
|
-
append root.join(
|
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(
|
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)[
|
97
|
-
FileUtils.mv root.join(
|
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(
|
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("#{
|
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.
|
data/lib/vite_ruby/cli/ssr.rb
CHANGED
@@ -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 ||
|
4
|
+
DEFAULT_ENV = CURRENT_ENV || "production"
|
5
5
|
JS_EXTENSIONS = %w[js mjs cjs]
|
6
6
|
|
7
|
-
desc
|
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[
|
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.#{
|
14
|
+
.map { |ext| ViteRuby.config.ssr_output_dir.join("ssr.#{ext}") }
|
15
15
|
.find(&:exist?)
|
16
16
|
|
17
|
-
raise ArgumentError, "No ssr entrypoint found `#{
|
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
|
-
|
21
|
-
(
|
22
|
-
(
|
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
|
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
|
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 #{
|
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(
|
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
|
4
|
+
desc "Upgrades the npm packages to the recommended versions."
|
5
5
|
|
6
6
|
def call(**)
|
7
|
-
say
|
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
|