vite_ruby 3.3.4 → 3.10.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 +176 -0
- data/default.vite.json +2 -1
- data/exe/vite +3 -3
- data/lib/tasks/vite.rake +43 -47
- 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 +16 -9
- data/lib/vite_ruby/cli/install.rb +44 -32
- 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 -4
- data/lib/vite_ruby/cli/version.rb +1 -1
- data/lib/vite_ruby/cli/vite.rb +20 -9
- data/lib/vite_ruby/cli.rb +13 -13
- data/lib/vite_ruby/commands.rb +20 -74
- data/lib/vite_ruby/compatibility_check.rb +7 -7
- data/lib/vite_ruby/config.rb +54 -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 +42 -23
- data/lib/vite_ruby/missing_entrypoint_error.rb +9 -10
- data/lib/vite_ruby/missing_executable_error.rb +1 -1
- data/lib/vite_ruby/runner.rb +16 -14
- data/lib/vite_ruby/version.rb +3 -3
- data/lib/vite_ruby.rb +26 -26
- metadata +36 -10
|
@@ -1,26 +1,31 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
3
|
+
require "stringio"
|
|
4
|
+
require "json"
|
|
4
5
|
|
|
5
6
|
class ViteRuby::CLI::Install < Dry::CLI::Command
|
|
6
|
-
desc
|
|
7
|
+
desc "Performs the initial configuration setup to get started with Vite Ruby."
|
|
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.")
|
|
10
|
+
|
|
11
|
+
def call(package_manager: nil, **)
|
|
12
|
+
ENV["VITE_RUBY_PACKAGE_MANAGER"] ||= package_manager if package_manager
|
|
7
13
|
|
|
8
|
-
def call(**)
|
|
9
14
|
$stdout.sync = true
|
|
10
15
|
|
|
11
|
-
say
|
|
16
|
+
say "Creating binstub"
|
|
12
17
|
ViteRuby.commands.install_binstubs
|
|
13
18
|
|
|
14
|
-
say
|
|
19
|
+
say "Creating configuration files"
|
|
15
20
|
create_configuration_files
|
|
16
21
|
|
|
17
|
-
say
|
|
22
|
+
say "Installing sample files"
|
|
18
23
|
install_sample_files
|
|
19
24
|
|
|
20
|
-
say
|
|
25
|
+
say "Installing js dependencies"
|
|
21
26
|
install_js_dependencies
|
|
22
27
|
|
|
23
|
-
say
|
|
28
|
+
say "Adding files to .gitignore"
|
|
24
29
|
install_gitignore
|
|
25
30
|
|
|
26
31
|
say "\nVite ⚡️ Ruby successfully installed! 🎉"
|
|
@@ -31,38 +36,38 @@ protected
|
|
|
31
36
|
# Internal: The JS packages that should be added to the app.
|
|
32
37
|
def js_dependencies
|
|
33
38
|
[
|
|
34
|
-
"vite@#{
|
|
35
|
-
"vite-plugin-ruby@#{
|
|
39
|
+
"vite@#{ViteRuby::DEFAULT_VITE_VERSION}",
|
|
40
|
+
"vite-plugin-ruby@#{ViteRuby::DEFAULT_PLUGIN_VERSION}",
|
|
36
41
|
]
|
|
37
42
|
end
|
|
38
43
|
|
|
39
44
|
# Internal: Setup for a plain Rack application.
|
|
40
45
|
def setup_app_files
|
|
41
|
-
copy_template
|
|
46
|
+
copy_template "config/vite.json", to: config.config_path
|
|
42
47
|
|
|
43
|
-
if (rackup_file = root.join(
|
|
44
|
-
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?"
|
|
45
50
|
end
|
|
46
51
|
end
|
|
47
52
|
|
|
48
53
|
# Internal: Create a sample JS file and attempt to inject it in an HTML template.
|
|
49
54
|
def install_sample_files
|
|
50
|
-
copy_template
|
|
55
|
+
copy_template "entrypoints/application.js", to: config.resolved_entrypoints_dir.join("application.js")
|
|
51
56
|
end
|
|
52
57
|
|
|
53
58
|
private
|
|
54
59
|
|
|
55
60
|
extend Forwardable
|
|
56
61
|
|
|
57
|
-
def_delegators
|
|
62
|
+
def_delegators "ViteRuby", :config
|
|
58
63
|
|
|
59
|
-
%i[append cp inject_line_after inject_line_after_last inject_line_before replace_first_line write].each do |util|
|
|
60
|
-
define_method(util) { |*args|
|
|
61
|
-
ViteRuby::CLI::FileUtils.send(util, *args) rescue nil
|
|
64
|
+
%i[append append_unless_present cp inject_line_after inject_line_after_last inject_line_before replace_first_line write].each do |util|
|
|
65
|
+
define_method(util) { |*args, **kwargs, &block|
|
|
66
|
+
ViteRuby::CLI::FileUtils.send(util, *args, **kwargs, &block) rescue nil
|
|
62
67
|
}
|
|
63
68
|
end
|
|
64
69
|
|
|
65
|
-
TEMPLATES_PATH = Pathname.new(File.expand_path(
|
|
70
|
+
TEMPLATES_PATH = Pathname.new(File.expand_path("../../../templates", __dir__))
|
|
66
71
|
|
|
67
72
|
def copy_template(path, to:)
|
|
68
73
|
cp TEMPLATES_PATH.join(path), to
|
|
@@ -70,23 +75,34 @@ private
|
|
|
70
75
|
|
|
71
76
|
# Internal: Creates the Vite and vite-plugin-ruby configuration files.
|
|
72
77
|
def create_configuration_files
|
|
73
|
-
copy_template
|
|
74
|
-
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"
|
|
75
80
|
setup_app_files
|
|
76
81
|
ViteRuby.reload_with(config_path: config.config_path)
|
|
77
82
|
end
|
|
78
83
|
|
|
79
84
|
# Internal: Installs vite and vite-plugin-ruby at the project level.
|
|
80
85
|
def install_js_dependencies
|
|
81
|
-
package_json = root.join(
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
86
|
+
package_json = root.join("package.json")
|
|
87
|
+
unless package_json.exist?
|
|
88
|
+
write package_json, <<~JSON
|
|
89
|
+
{
|
|
90
|
+
"private": true,
|
|
91
|
+
"type": "module"
|
|
92
|
+
}
|
|
93
|
+
JSON
|
|
94
|
+
end
|
|
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
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
install_js_packages js_dependencies.join(" ")
|
|
85
101
|
end
|
|
86
102
|
|
|
87
103
|
# Internal: Adds compilation output dirs to git ignore.
|
|
88
104
|
def install_gitignore
|
|
89
|
-
return unless (gitignore_file = root.join(
|
|
105
|
+
return unless (gitignore_file = root.join(".gitignore")).exist?
|
|
90
106
|
|
|
91
107
|
append(gitignore_file, <<~GITIGNORE)
|
|
92
108
|
|
|
@@ -115,12 +131,8 @@ private
|
|
|
115
131
|
end
|
|
116
132
|
end
|
|
117
133
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
return 'yarn add' if root.join('yarn.lock').exist?
|
|
121
|
-
return 'pnpm install' if root.join('pnpm-lock.yaml').exist?
|
|
122
|
-
|
|
123
|
-
'npm install'
|
|
134
|
+
def install_js_packages(deps)
|
|
135
|
+
run_with_capture("#{config.package_manager} add -D #{deps}", stdin_data: "\n")
|
|
124
136
|
end
|
|
125
137
|
|
|
126
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,11 +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
|
-
|
|
9
|
-
run_with_capture("#{ npm_install } -D #{ deps }")
|
|
7
|
+
say "Upgrading npm packages"
|
|
8
|
+
install_js_packages js_dependencies.join(" ")
|
|
10
9
|
end
|
|
11
10
|
end
|
data/lib/vite_ruby/cli/vite.rb
CHANGED
|
@@ -1,24 +1,35 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
class ViteRuby::CLI::Vite < Dry::CLI::Command
|
|
4
|
-
CURRENT_ENV = ENV[
|
|
4
|
+
CURRENT_ENV = ENV["RACK_ENV"] || ENV["RAILS_ENV"]
|
|
5
5
|
|
|
6
6
|
def self.executable_options
|
|
7
|
-
option(:mode, default: self::DEFAULT_ENV, values: %w[development production test], aliases: [
|
|
8
|
-
option(:
|
|
9
|
-
option(:
|
|
7
|
+
option(:mode, default: self::DEFAULT_ENV, values: %w[development production test], aliases: ["m"], desc: "The build mode for Vite")
|
|
8
|
+
option(:node_options, desc: "Node options for the Vite executable", aliases: ["node-options"])
|
|
9
|
+
option(:inspect, desc: "Run Vite in a debugging session with node --inspect-brk", aliases: ["inspect-brk"], type: :boolean)
|
|
10
|
+
option(:trace_deprecation, desc: "Run Vite in debugging mode with node --trace-deprecation", aliases: ["trace-deprecation"], type: :boolean)
|
|
10
11
|
end
|
|
11
12
|
|
|
12
13
|
def self.shared_options
|
|
13
14
|
executable_options
|
|
14
|
-
option(:debug, desc:
|
|
15
|
-
option(:clobber, desc:
|
|
15
|
+
option(:debug, desc: "Run Vite in verbose mode, printing all debugging output", aliases: ["verbose"], type: :boolean)
|
|
16
|
+
option(:clobber, desc: "Clear cache and previous builds", type: :boolean, aliases: %w[clean clear])
|
|
16
17
|
end
|
|
17
18
|
|
|
18
|
-
def call(mode:, args: [], clobber: false, **boolean_opts)
|
|
19
|
-
ViteRuby.env[
|
|
19
|
+
def call(mode:, args: [], clobber: false, node_options: nil, inspect: nil, trace_deprecation: nil, **boolean_opts)
|
|
20
|
+
ViteRuby.env["VITE_RUBY_MODE"] = mode
|
|
20
21
|
ViteRuby.commands.clobber if clobber
|
|
21
|
-
|
|
22
|
+
|
|
23
|
+
node_options = [
|
|
24
|
+
node_options,
|
|
25
|
+
("--inspect-brk" if inspect),
|
|
26
|
+
("--trace-deprecation" if trace_deprecation),
|
|
27
|
+
].compact.join(" ")
|
|
28
|
+
|
|
29
|
+
args << %(--node-options="#{node_options}") unless node_options.empty?
|
|
30
|
+
|
|
31
|
+
boolean_opts.map { |name, value| args << "--#{name}" if value }
|
|
32
|
+
|
|
22
33
|
yield(args)
|
|
23
34
|
end
|
|
24
35
|
end
|
data/lib/vite_ruby/cli.rb
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
3
|
+
require "dry/cli"
|
|
4
4
|
|
|
5
5
|
# Public: Command line interface that allows to install the library, and run
|
|
6
6
|
# simple commands.
|
|
7
7
|
class ViteRuby::CLI
|
|
8
8
|
extend Dry::CLI::Registry
|
|
9
9
|
|
|
10
|
-
register
|
|
11
|
-
register
|
|
12
|
-
register
|
|
13
|
-
register
|
|
14
|
-
register
|
|
15
|
-
register
|
|
16
|
-
register
|
|
17
|
-
register
|
|
10
|
+
register "build", Build, aliases: ["b"]
|
|
11
|
+
register "clobber", Clobber, aliases: %w[clean clear]
|
|
12
|
+
register "dev", Dev, aliases: %w[d serve]
|
|
13
|
+
register "install", Install
|
|
14
|
+
register "ssr", SSR
|
|
15
|
+
register "version", Version, aliases: ["v", "-v", "--version", "info"]
|
|
16
|
+
register "upgrade", Upgrade, aliases: ["update"]
|
|
17
|
+
register "upgrade_packages", UpgradePackages, aliases: ["update_packages"]
|
|
18
18
|
|
|
19
19
|
# Internal: Allows framework-specific variants to extend the CLI.
|
|
20
|
-
def self.require_framework_libraries(path =
|
|
20
|
+
def self.require_framework_libraries(path = "cli")
|
|
21
21
|
ViteRuby.framework_libraries.each do |_framework, library|
|
|
22
|
-
require [library.name.tr(
|
|
22
|
+
require [library.name.tr("-", "/").to_s, path].compact.join("/")
|
|
23
23
|
end
|
|
24
24
|
rescue LoadError
|
|
25
|
-
require_framework_libraries
|
|
25
|
+
require_framework_libraries "installation" unless path == "installation"
|
|
26
26
|
end
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
# NOTE: This allows framework-specific variants to extend the CLI.
|
|
30
|
-
ViteRuby::CLI.require_framework_libraries(
|
|
30
|
+
ViteRuby::CLI.require_framework_libraries("cli")
|
data/lib/vite_ruby/commands.rb
CHANGED
|
@@ -9,7 +9,7 @@ class ViteRuby::Commands
|
|
|
9
9
|
|
|
10
10
|
# Public: Defaults to production, and exits if the build fails.
|
|
11
11
|
def build_from_task(*args)
|
|
12
|
-
with_node_env(ENV.fetch(
|
|
12
|
+
with_node_env(ENV.fetch("NODE_ENV", "production")) {
|
|
13
13
|
ensure_log_goes_to_stdout {
|
|
14
14
|
build(*args) || exit!
|
|
15
15
|
}
|
|
@@ -25,44 +25,13 @@ class ViteRuby::Commands
|
|
|
25
25
|
def clobber
|
|
26
26
|
dirs = [config.build_output_dir, config.ssr_output_dir, config.build_cache_dir, config.vite_cache_dir]
|
|
27
27
|
dirs.each { |dir| dir.rmtree if dir.exist? }
|
|
28
|
-
$stdout.puts "Removed vite cache and output dirs:\n\t#{
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
# Public: Receives arguments from a rake task.
|
|
32
|
-
def clean_from_task(args)
|
|
33
|
-
ensure_log_goes_to_stdout {
|
|
34
|
-
clean(keep_up_to: Integer(args.keep || 2), age_in_seconds: Integer(args.age || 3600))
|
|
35
|
-
}
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
# Public: Cleanup old assets in the output directory.
|
|
39
|
-
#
|
|
40
|
-
# keep_up_to - Max amount of backups to preserve.
|
|
41
|
-
# age_in_seconds - Amount of time to look back in order to preserve them.
|
|
42
|
-
#
|
|
43
|
-
# NOTE: By default keeps the last version, or 2 if created in the past hour.
|
|
44
|
-
#
|
|
45
|
-
# Examples:
|
|
46
|
-
# To force only 1 backup to be kept: clean(1, 0)
|
|
47
|
-
# To only keep files created within the last 10 minutes: clean(0, 600)
|
|
48
|
-
def clean(keep_up_to: 2, age_in_seconds: 3600)
|
|
49
|
-
return false unless may_clean?
|
|
50
|
-
|
|
51
|
-
versions
|
|
52
|
-
.each_with_index
|
|
53
|
-
.drop_while { |(mtime, _), index|
|
|
54
|
-
max_age = [0, Time.now - Time.at(mtime)].max
|
|
55
|
-
max_age < age_in_seconds || index < keep_up_to
|
|
56
|
-
}
|
|
57
|
-
.each do |(_, files), _|
|
|
58
|
-
clean_files(files)
|
|
59
|
-
end
|
|
60
|
-
true
|
|
28
|
+
$stdout.puts "Removed vite cache and output dirs:\n\t#{dirs.join("\n\t")}"
|
|
61
29
|
end
|
|
62
30
|
|
|
63
31
|
# Internal: Installs the binstub for the CLI in the appropriate path.
|
|
64
32
|
def install_binstubs
|
|
65
|
-
`bundle
|
|
33
|
+
`bundle config set bin #{config.root.join("bin")}`
|
|
34
|
+
`bundle binstub vite_ruby`
|
|
66
35
|
`bundle config --delete bin`
|
|
67
36
|
end
|
|
68
37
|
|
|
@@ -78,7 +47,7 @@ class ViteRuby::Commands
|
|
|
78
47
|
|
|
79
48
|
# Internal: Verifies if ViteRuby is properly installed.
|
|
80
49
|
def verify_install
|
|
81
|
-
unless File.exist?(config.root.join(
|
|
50
|
+
unless File.exist?(config.root.join("bin/vite"))
|
|
82
51
|
warn <<~WARN
|
|
83
52
|
|
|
84
53
|
vite binstub not found.
|
|
@@ -91,7 +60,7 @@ class ViteRuby::Commands
|
|
|
91
60
|
unless config_path.exist?
|
|
92
61
|
warn <<~WARN
|
|
93
62
|
|
|
94
|
-
Configuration #{
|
|
63
|
+
Configuration #{config_path} file for vite-plugin-ruby not found.
|
|
95
64
|
Make sure `bundle exec vite install` has run successfully before running dependent tasks.
|
|
96
65
|
WARN
|
|
97
66
|
exit!
|
|
@@ -101,23 +70,23 @@ class ViteRuby::Commands
|
|
|
101
70
|
# Internal: Prints information about ViteRuby's environment.
|
|
102
71
|
def print_info
|
|
103
72
|
config.within_root do
|
|
104
|
-
$stdout.puts "bin/vite present?: #{
|
|
73
|
+
$stdout.puts "bin/vite present?: #{File.exist? "bin/vite"}"
|
|
105
74
|
|
|
106
|
-
$stdout.puts "vite_ruby: #{
|
|
75
|
+
$stdout.puts "vite_ruby: #{ViteRuby::VERSION}"
|
|
107
76
|
ViteRuby.framework_libraries.each do |framework, library|
|
|
108
|
-
$stdout.puts "#{
|
|
109
|
-
$stdout.puts "#{
|
|
77
|
+
$stdout.puts "#{library.name}: #{library.version}"
|
|
78
|
+
$stdout.puts "#{framework}: #{Gem.loaded_specs[framework]&.version}"
|
|
110
79
|
end
|
|
111
80
|
|
|
112
|
-
$stdout.puts "
|
|
113
|
-
$stdout.puts "
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
$stdout.puts "
|
|
81
|
+
$stdout.puts "ruby: #{`ruby --version`}"
|
|
82
|
+
$stdout.puts "node: #{`node --version`}"
|
|
83
|
+
|
|
84
|
+
pkg = config.package_manager
|
|
85
|
+
$stdout.puts "#{pkg}: #{`#{pkg} --version` rescue nil}"
|
|
117
86
|
|
|
118
87
|
$stdout.puts "\n"
|
|
119
88
|
packages = `npm ls vite vite-plugin-ruby`
|
|
120
|
-
packages_msg = packages.include?(
|
|
89
|
+
packages_msg = packages.include?("vite@") ? "installed packages:\n#{packages}" : "❌ Check that vite and vite-plugin-ruby have been added as development dependencies and installed."
|
|
121
90
|
$stdout.puts packages_msg
|
|
122
91
|
|
|
123
92
|
ViteRuby::CompatibilityCheck.verify_plugin_version(config.root)
|
|
@@ -130,42 +99,19 @@ private
|
|
|
130
99
|
|
|
131
100
|
def_delegators :@vite_ruby, :config, :builder, :manifest, :logger, :logger=
|
|
132
101
|
|
|
133
|
-
def may_clean?
|
|
134
|
-
config.build_output_dir.exist? && config.manifest_path.exist?
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
def clean_files(files)
|
|
138
|
-
files.select { |file| File.file?(file) }.each do |file|
|
|
139
|
-
File.delete(file)
|
|
140
|
-
logger.info("Removed #{ file }")
|
|
141
|
-
end
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
def versions
|
|
145
|
-
all_files = Dir.glob("#{ config.build_output_dir }/**/*")
|
|
146
|
-
entries = all_files - config.manifest_paths - current_version_files
|
|
147
|
-
entries.reject { |file| File.directory?(file) }
|
|
148
|
-
.group_by { |file| File.mtime(file).utc.to_i }
|
|
149
|
-
.sort.reverse
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
def current_version_files
|
|
153
|
-
Dir.glob(manifest.refresh.values.map { |value| config.build_output_dir.join("#{ value['file'] }*") })
|
|
154
|
-
end
|
|
155
|
-
|
|
156
102
|
def with_node_env(env)
|
|
157
|
-
original = ENV[
|
|
158
|
-
ENV[
|
|
103
|
+
original = ENV["NODE_ENV"]
|
|
104
|
+
ENV["NODE_ENV"] = env
|
|
159
105
|
yield
|
|
160
106
|
ensure
|
|
161
|
-
ENV[
|
|
107
|
+
ENV["NODE_ENV"] = original
|
|
162
108
|
end
|
|
163
109
|
|
|
164
110
|
def ensure_log_goes_to_stdout
|
|
165
111
|
old_logger, original_sync = logger, $stdout.sync
|
|
166
112
|
|
|
167
113
|
$stdout.sync = true
|
|
168
|
-
self.logger = Logger.new($stdout, formatter: proc { |_, _, progname, msg| progname ==
|
|
114
|
+
self.logger = Logger.new($stdout, formatter: proc { |_, _, progname, msg| (progname == "vite") ? msg : "#{msg}\n" })
|
|
169
115
|
yield
|
|
170
116
|
ensure
|
|
171
117
|
self.logger, $stdout.sync = old_logger, original_sync
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
3
|
+
require "json"
|
|
4
4
|
|
|
5
5
|
# Internal: Verifies that the installed vite-plugin-ruby version is compatible
|
|
6
6
|
# with the current version of vite_ruby.
|
|
@@ -11,9 +11,9 @@ module ViteRuby::CompatibilityCheck
|
|
|
11
11
|
class << self
|
|
12
12
|
# Public: Attempt to verify that the vite-plugin-ruby version is compatible.
|
|
13
13
|
def verify_plugin_version(root)
|
|
14
|
-
package = JSON.parse(root.join(
|
|
15
|
-
requirement = package.dig(
|
|
16
|
-
|
|
14
|
+
package = JSON.parse(root.join("package.json").read) rescue {}
|
|
15
|
+
requirement = package.dig("devDependencies", "vite-plugin-ruby") ||
|
|
16
|
+
package.dig("dependencies", "vite-plugin-ruby")
|
|
17
17
|
|
|
18
18
|
raise_unless_satisfied(requirement, ViteRuby::DEFAULT_PLUGIN_VERSION)
|
|
19
19
|
end
|
|
@@ -22,7 +22,7 @@ module ViteRuby::CompatibilityCheck
|
|
|
22
22
|
def raise_unless_satisfied(npm_req, ruby_req)
|
|
23
23
|
unless compatible_plugin?(npm_req, ruby_req)
|
|
24
24
|
raise ArgumentError, <<~ERROR
|
|
25
|
-
vite-plugin-ruby@#{
|
|
25
|
+
vite-plugin-ruby@#{npm_req} might not be compatible with vite_ruby-#{ViteRuby::VERSION}
|
|
26
26
|
|
|
27
27
|
You may disable this check if needed: https://vite-ruby.netlify.app/config/#skipcompatibilitycheck
|
|
28
28
|
|
|
@@ -37,12 +37,12 @@ module ViteRuby::CompatibilityCheck
|
|
|
37
37
|
# requirement.
|
|
38
38
|
def compatible_plugin?(npm_req, ruby_req)
|
|
39
39
|
npm_req, ruby_req = [npm_req, ruby_req]
|
|
40
|
-
.map { |req| Gem::Requirement.new(req.sub(
|
|
40
|
+
.map { |req| Gem::Requirement.new(req.sub("^", "~>")) }
|
|
41
41
|
|
|
42
42
|
current_version = npm_req.requirements.first.second
|
|
43
43
|
|
|
44
44
|
ruby_req.satisfied_by?(current_version)
|
|
45
|
-
rescue
|
|
45
|
+
rescue
|
|
46
46
|
true
|
|
47
47
|
end
|
|
48
48
|
end
|