vite_ruby 3.5.0 → 4.0.0.alpha1
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 +2 -318
- data/README.md +1 -1
- data/default.vite.json +1 -5
- data/exe/vite +0 -2
- data/lib/tasks/vite.rake +10 -51
- data/lib/vite_ruby/build.rb +16 -46
- data/lib/vite_ruby/builder.rb +26 -21
- data/lib/vite_ruby/cli/build.rb +0 -2
- data/lib/vite_ruby/cli/install.rb +9 -2
- data/lib/vite_ruby/cli/vite.rb +3 -7
- data/lib/vite_ruby/cli.rb +0 -13
- data/lib/vite_ruby/commands.rb +7 -19
- data/lib/vite_ruby/compatibility_check.rb +1 -1
- data/lib/vite_ruby/config.rb +10 -30
- data/lib/vite_ruby/dev_server_proxy.rb +5 -10
- data/lib/vite_ruby/io.rb +1 -1
- data/lib/vite_ruby/manifest.rb +16 -28
- data/lib/vite_ruby/missing_entrypoint_error.rb +9 -18
- data/lib/vite_ruby/runner.rb +5 -11
- data/lib/vite_ruby/version.rb +3 -3
- data/lib/vite_ruby.rb +11 -26
- metadata +12 -19
- data/lib/vite_ruby/cli/ssr.rb +0 -27
@@ -91,7 +91,9 @@ private
|
|
91
91
|
append(gitignore_file, <<~GITIGNORE)
|
92
92
|
|
93
93
|
# Vite Ruby
|
94
|
-
/public/vite
|
94
|
+
/public/vite
|
95
|
+
/public/vite-dev
|
96
|
+
/public/vite-test
|
95
97
|
node_modules
|
96
98
|
# Vite uses dotenv and suggests to ignore local-only env files. See
|
97
99
|
# https://vitejs.dev/guide/env-and-mode.html#env-files
|
@@ -111,7 +113,7 @@ private
|
|
111
113
|
def run_with_capture(*args, **options)
|
112
114
|
Dir.chdir(root) do
|
113
115
|
_, stderr, status = ViteRuby::IO.capture(*args, **options)
|
114
|
-
say(stderr) unless status.success? || stderr.empty?
|
116
|
+
say(stderr) unless status.success? || stderr.to_s.empty?
|
115
117
|
end
|
116
118
|
end
|
117
119
|
|
@@ -132,3 +134,8 @@ private
|
|
132
134
|
$stderr = old_stderr
|
133
135
|
end
|
134
136
|
end
|
137
|
+
|
138
|
+
# NOTE: This allows framework-specific variants to extend the installation.
|
139
|
+
ViteRuby.framework_libraries.each do |_framework, library|
|
140
|
+
require "#{ library.name.tr('-', '/') }/installation"
|
141
|
+
end
|
data/lib/vite_ruby/cli/vite.rb
CHANGED
@@ -3,18 +3,14 @@
|
|
3
3
|
class ViteRuby::CLI::Vite < Dry::CLI::Command
|
4
4
|
CURRENT_ENV = ENV['RACK_ENV'] || ENV['RAILS_ENV']
|
5
5
|
|
6
|
-
def self.
|
6
|
+
def self.shared_options
|
7
7
|
option(:mode, default: self::DEFAULT_ENV, values: %w[development production test], aliases: ['m'], desc: 'The build mode for Vite')
|
8
|
+
option(:clobber, desc: 'Clear cache and previous builds', type: :boolean, aliases: %w[clean clear])
|
9
|
+
option(:debug, desc: 'Run Vite in verbose mode, printing all debugging output', aliases: ['verbose'], type: :boolean)
|
8
10
|
option(:inspect, desc: 'Run Vite in a debugging session with node --inspect-brk', aliases: ['inspect-brk'], type: :boolean)
|
9
11
|
option(:trace_deprecation, desc: 'Run Vite in debugging mode with node --trace-deprecation', aliases: ['trace-deprecation'], type: :boolean)
|
10
12
|
end
|
11
13
|
|
12
|
-
def self.shared_options
|
13
|
-
executable_options
|
14
|
-
option(:debug, desc: 'Run Vite in verbose mode, printing all debugging output', aliases: ['verbose'], type: :boolean)
|
15
|
-
option(:clobber, desc: 'Clear cache and previous builds', type: :boolean, aliases: %w[clean clear])
|
16
|
-
end
|
17
|
-
|
18
14
|
def call(mode:, args: [], clobber: false, **boolean_opts)
|
19
15
|
ViteRuby.env['VITE_RUBY_MODE'] = mode
|
20
16
|
ViteRuby.commands.clobber if clobber
|
data/lib/vite_ruby/cli.rb
CHANGED
@@ -11,20 +11,7 @@ class ViteRuby::CLI
|
|
11
11
|
register 'clobber', Clobber, aliases: %w[clean clear]
|
12
12
|
register 'dev', Dev, aliases: %w[d serve]
|
13
13
|
register 'install', Install
|
14
|
-
register 'ssr', SSR
|
15
14
|
register 'version', Version, aliases: ['v', '-v', '--version', 'info']
|
16
15
|
register 'upgrade', Upgrade, aliases: ['update']
|
17
16
|
register 'upgrade_packages', UpgradePackages, aliases: ['update_packages']
|
18
|
-
|
19
|
-
# Internal: Allows framework-specific variants to extend the CLI.
|
20
|
-
def self.require_framework_libraries(path = 'cli')
|
21
|
-
ViteRuby.framework_libraries.each do |_framework, library|
|
22
|
-
require [library.name.tr('-', '/').to_s, path].compact.join('/')
|
23
|
-
end
|
24
|
-
rescue LoadError
|
25
|
-
require_framework_libraries 'installation' unless path == 'installation'
|
26
|
-
end
|
27
17
|
end
|
28
|
-
|
29
|
-
# NOTE: This allows framework-specific variants to extend the CLI.
|
30
|
-
ViteRuby::CLI.require_framework_libraries('cli')
|
data/lib/vite_ruby/commands.rb
CHANGED
@@ -23,7 +23,7 @@ class ViteRuby::Commands
|
|
23
23
|
|
24
24
|
# Public: Removes all build cache and previously compiled assets.
|
25
25
|
def clobber
|
26
|
-
dirs = [config.build_output_dir, config.
|
26
|
+
dirs = [config.build_output_dir, config.build_cache_dir, config.vite_cache_dir]
|
27
27
|
dirs.each { |dir| dir.rmtree if dir.exist? }
|
28
28
|
$stdout.puts "Removed vite cache and output dirs:\n\t#{ dirs.join("\n\t") }"
|
29
29
|
end
|
@@ -50,7 +50,7 @@ class ViteRuby::Commands
|
|
50
50
|
|
51
51
|
versions
|
52
52
|
.each_with_index
|
53
|
-
.drop_while { |(mtime,
|
53
|
+
.drop_while { |(mtime, _), index|
|
54
54
|
max_age = [0, Time.now - Time.at(mtime)].max
|
55
55
|
max_age < age_in_seconds || index < keep_up_to
|
56
56
|
}
|
@@ -66,16 +66,6 @@ class ViteRuby::Commands
|
|
66
66
|
`bundle config --delete bin`
|
67
67
|
end
|
68
68
|
|
69
|
-
# Internal: Checks if the npm version is 6 or lower.
|
70
|
-
def legacy_npm_version?
|
71
|
-
`npm --version`.to_i < 7 rescue false
|
72
|
-
end
|
73
|
-
|
74
|
-
# Internal: Checks if the yarn version is 1.x.
|
75
|
-
def legacy_yarn_version?
|
76
|
-
`yarn --version`.to_i < 2 rescue false
|
77
|
-
end
|
78
|
-
|
79
69
|
# Internal: Verifies if ViteRuby is properly installed.
|
80
70
|
def verify_install
|
81
71
|
unless File.exist?(config.root.join('bin/vite'))
|
@@ -100,7 +90,7 @@ class ViteRuby::Commands
|
|
100
90
|
|
101
91
|
# Internal: Prints information about ViteRuby's environment.
|
102
92
|
def print_info
|
103
|
-
config.
|
93
|
+
Dir.chdir(config.root) do
|
104
94
|
$stdout.puts "bin/vite present?: #{ File.exist? 'bin/vite' }"
|
105
95
|
|
106
96
|
$stdout.puts "vite_ruby: #{ ViteRuby::VERSION }"
|
@@ -131,7 +121,7 @@ private
|
|
131
121
|
def_delegators :@vite_ruby, :config, :builder, :manifest, :logger, :logger=
|
132
122
|
|
133
123
|
def may_clean?
|
134
|
-
config.build_output_dir.exist? && config.
|
124
|
+
config.build_output_dir.exist? && config.manifest_path.exist?
|
135
125
|
end
|
136
126
|
|
137
127
|
def clean_files(files)
|
@@ -143,16 +133,14 @@ private
|
|
143
133
|
|
144
134
|
def versions
|
145
135
|
all_files = Dir.glob("#{ config.build_output_dir }/**/*")
|
146
|
-
entries = all_files - config.
|
136
|
+
entries = all_files - [config.manifest_path] - current_version_files
|
147
137
|
entries.reject { |file| File.directory?(file) }
|
148
138
|
.group_by { |file| File.mtime(file).utc.to_i }
|
149
139
|
.sort.reverse
|
150
140
|
end
|
151
141
|
|
152
|
-
def
|
153
|
-
|
154
|
-
JSON.parse(path.read).map { |_, entry| entry['file'] }
|
155
|
-
}.compact.uniq.map { |path| config.build_output_dir.join(path).to_s }
|
142
|
+
def current_version_files
|
143
|
+
Dir.glob(manifest.refresh.values.map { |value| config.build_output_dir.join("#{ value['file'] }*") })
|
156
144
|
end
|
157
145
|
|
158
146
|
def with_node_env(env)
|
@@ -24,7 +24,7 @@ module ViteRuby::CompatibilityCheck
|
|
24
24
|
raise ArgumentError, <<~ERROR
|
25
25
|
vite-plugin-ruby@#{ npm_req } might not be compatible with vite_ruby-#{ ViteRuby::VERSION }
|
26
26
|
|
27
|
-
You may disable this check if needed: https://vite-ruby.netlify.app/config/#
|
27
|
+
You may disable this check if needed: https://vite-ruby.netlify.app/config/#skipCompatibilityCheck
|
28
28
|
|
29
29
|
You may upgrade both by running:
|
30
30
|
|
data/lib/vite_ruby/config.rb
CHANGED
@@ -5,10 +5,6 @@ require 'json'
|
|
5
5
|
# Public: Allows to resolve configuration sourced from `config/vite.json` and
|
6
6
|
# environment variables, combining them with the default options.
|
7
7
|
class ViteRuby::Config
|
8
|
-
def origin
|
9
|
-
"#{ protocol }://#{ host_with_port }"
|
10
|
-
end
|
11
|
-
|
12
8
|
def protocol
|
13
9
|
https ? 'https' : 'http'
|
14
10
|
end
|
@@ -17,24 +13,14 @@ class ViteRuby::Config
|
|
17
13
|
"#{ host }:#{ port }"
|
18
14
|
end
|
19
15
|
|
20
|
-
# Internal: Path
|
21
|
-
def
|
22
|
-
|
23
|
-
# NOTE: Generated by Vite when `manifest: true`, which vite-plugin-ruby enables.
|
24
|
-
'manifest.json',
|
25
|
-
# NOTE: Path where vite-plugin-ruby outputs the assets manifest file.
|
26
|
-
'manifest-assets.json',
|
27
|
-
].flat_map { |path|
|
28
|
-
[
|
29
|
-
build_output_dir.join(".vite/#{ path }"), # Vite 5 onwards
|
30
|
-
build_output_dir.join(path), # Vite 4 and below
|
31
|
-
]
|
32
|
-
}
|
16
|
+
# Internal: Path where Vite outputs the manifest file.
|
17
|
+
def manifest_path
|
18
|
+
build_output_dir.join('manifest.json')
|
33
19
|
end
|
34
20
|
|
35
|
-
# Internal: Path
|
36
|
-
def
|
37
|
-
|
21
|
+
# Internal: Path where vite-plugin-ruby outputs the assets manifest file.
|
22
|
+
def assets_manifest_path
|
23
|
+
build_output_dir.join('manifest-assets.json')
|
38
24
|
end
|
39
25
|
|
40
26
|
# Public: The directory where Vite will store the built assets.
|
@@ -64,12 +50,12 @@ class ViteRuby::Config
|
|
64
50
|
end
|
65
51
|
|
66
52
|
# Public: Sets additional environment variables for vite-plugin-ruby.
|
67
|
-
def to_env
|
53
|
+
def to_env
|
68
54
|
CONFIGURABLE_WITH_ENV.each_with_object({}) do |option, env|
|
69
55
|
unless (value = @config[option]).nil?
|
70
56
|
env["#{ ViteRuby::ENV_PREFIX }_#{ option.upcase }"] = value.to_s
|
71
57
|
end
|
72
|
-
end.merge(
|
58
|
+
end.merge(ViteRuby.env)
|
73
59
|
end
|
74
60
|
|
75
61
|
# Internal: Files and directories that should be watched for changes.
|
@@ -84,11 +70,6 @@ class ViteRuby::Config
|
|
84
70
|
].freeze
|
85
71
|
end
|
86
72
|
|
87
|
-
# Internal: Changes the current directory to the root dir.
|
88
|
-
def within_root(&block)
|
89
|
-
Dir.chdir(File.expand_path(root), &block)
|
90
|
-
end
|
91
|
-
|
92
73
|
private
|
93
74
|
|
94
75
|
# Internal: Coerces all the configuration values, in case they were passed
|
@@ -98,8 +79,7 @@ private
|
|
98
79
|
config['port'] = config['port'].to_i
|
99
80
|
config['root'] = Pathname.new(config['root'])
|
100
81
|
config['build_cache_dir'] = config['root'].join(config['build_cache_dir'])
|
101
|
-
config
|
102
|
-
coerce_booleans(config, 'auto_build', 'hide_build_console_output', 'https', 'skip_compatibility_check', 'skip_proxy')
|
82
|
+
coerce_booleans(config, 'auto_build', 'hide_build_console_output', 'https', 'skip_compatibility_check')
|
103
83
|
end
|
104
84
|
|
105
85
|
# Internal: Coerces configuration options to boolean.
|
@@ -141,7 +121,7 @@ private
|
|
141
121
|
'config_path' => option_from_env('config_path') || DEFAULT_CONFIG.fetch('config_path'),
|
142
122
|
'mode' => option_from_env('mode') || mode,
|
143
123
|
'root' => option_from_env('root') || root,
|
144
|
-
}
|
124
|
+
}
|
145
125
|
end
|
146
126
|
|
147
127
|
# Internal: Used to load a JSON file from the specified path.
|
@@ -38,7 +38,7 @@ private
|
|
38
38
|
uri
|
39
39
|
.sub(HOST_WITH_PORT_REGEX, '/') # Hanami adds the host and port.
|
40
40
|
.sub('.ts.js', '.ts') # Hanami's javascript helper always adds the extension.
|
41
|
-
.sub(
|
41
|
+
.sub(/(\.(?!min|module)\w+)\.css$/, '\1') # Rails' stylesheet_link_tag always adds the extension.
|
42
42
|
end
|
43
43
|
|
44
44
|
def forward_to_vite_dev_server(env)
|
@@ -54,22 +54,17 @@ private
|
|
54
54
|
|
55
55
|
def vite_should_handle?(env)
|
56
56
|
path = normalize_uri(env['PATH_INFO'])
|
57
|
-
return true if path.start_with?(
|
57
|
+
return true if path.start_with?(vite_asset_url_prefix) # Vite asset
|
58
|
+
return true if path.start_with?(VITE_DEPENDENCY_PREFIX) # Packages and imports
|
58
59
|
return true if file_in_vite_root?(path) # Fallback if Vite can serve the file
|
59
60
|
end
|
60
61
|
|
61
|
-
# NOTE: When using an empty 'public_output_dir', we need to rely on a
|
62
|
-
# filesystem check to check whether Vite should serve the request.
|
63
62
|
def file_in_vite_root?(path)
|
64
63
|
path.include?('.') && # Check for extension, avoid filesystem if possible.
|
65
64
|
config.vite_root_dir.join(path.start_with?('/') ? path[1..-1] : path).file?
|
66
65
|
end
|
67
66
|
|
68
|
-
|
69
|
-
|
70
|
-
#
|
71
|
-
# If the path starts with that prefix, it will be redirected to Vite.
|
72
|
-
def vite_url_prefix
|
73
|
-
@vite_url_prefix ||= config.public_output_dir.empty? ? VITE_DEPENDENCY_PREFIX : "/#{ config.public_output_dir }/"
|
67
|
+
def vite_asset_url_prefix
|
68
|
+
@vite_asset_url_prefix ||= config.public_output_dir.empty? ? "\0" : "/#{ config.public_output_dir }/"
|
74
69
|
end
|
75
70
|
end
|
data/lib/vite_ruby/io.rb
CHANGED
data/lib/vite_ruby/manifest.rb
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
# lookup_entrypoint('calendar', type: :javascript)
|
8
8
|
# => { "file" => "/vite/assets/calendar-1016838bab065ae1e314.js", "imports" => [] }
|
9
9
|
#
|
10
|
-
# NOTE: Using
|
10
|
+
# NOTE: Using "autoBuild": true` in `config/vite.json` file will trigger a build
|
11
11
|
# on demand as needed, before performing any lookup.
|
12
12
|
class ViteRuby::Manifest
|
13
13
|
def initialize(vite_ruby)
|
@@ -22,16 +22,15 @@ class ViteRuby::Manifest
|
|
22
22
|
lookup!(name, **options).fetch('file')
|
23
23
|
end
|
24
24
|
|
25
|
-
# Public: Returns
|
25
|
+
# Public: Returns entries, 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') }
|
30
29
|
|
31
30
|
imports = dev_server_running? ? [] : entries.flat_map { |entry| entry['imports'] }.compact.uniq
|
32
31
|
{
|
33
|
-
|
34
|
-
imports: imports.map
|
32
|
+
main: entries.map(&TO_ENTRY),
|
33
|
+
imports: imports.map(&TO_ENTRY).uniq,
|
35
34
|
stylesheets: dev_server_running? ? [] : (entries + imports).flat_map { |entry| entry['css'] }.compact.uniq,
|
36
35
|
}
|
37
36
|
end
|
@@ -51,27 +50,21 @@ class ViteRuby::Manifest
|
|
51
50
|
if dev_server_running?
|
52
51
|
<<~REACT_REFRESH
|
53
52
|
<script type="module">
|
54
|
-
#{
|
53
|
+
import RefreshRuntime from '#{ prefix_asset_with_host('@react-refresh') }'
|
54
|
+
RefreshRuntime.injectIntoGlobalHook(window)
|
55
|
+
window.$RefreshReg$ = () => {}
|
56
|
+
window.$RefreshSig$ = () => (type) => type
|
57
|
+
window.__vite_plugin_react_preamble_installed__ = true
|
55
58
|
</script>
|
56
59
|
REACT_REFRESH
|
57
60
|
end
|
58
61
|
end
|
59
62
|
|
60
|
-
# Public: Source script for the React Refresh plugin.
|
61
|
-
def react_preamble_code
|
62
|
-
if dev_server_running?
|
63
|
-
<<~REACT_PREAMBLE_CODE
|
64
|
-
import RefreshRuntime from '#{ prefix_asset_with_host('@react-refresh') }'
|
65
|
-
RefreshRuntime.injectIntoGlobalHook(window)
|
66
|
-
window.$RefreshReg$ = () => {}
|
67
|
-
window.$RefreshSig$ = () => (type) => type
|
68
|
-
window.__vite_plugin_react_preamble_installed__ = true
|
69
|
-
REACT_PREAMBLE_CODE
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
63
|
protected
|
74
64
|
|
65
|
+
# Internal: Returns a [src, attrs] entry.
|
66
|
+
TO_ENTRY = ->(entry) { [entry.fetch('file'), entry.slice('integrity').symbolize_keys] }
|
67
|
+
|
75
68
|
# Internal: Strict version of lookup.
|
76
69
|
#
|
77
70
|
# Returns a relative path for the asset, or raises an error if not found.
|
@@ -87,7 +80,7 @@ protected
|
|
87
80
|
# manifest.lookup('calendar.js')
|
88
81
|
# => { "file" => "/vite/assets/calendar-1016838bab065ae1e122.js", "imports" => [] }
|
89
82
|
def lookup(name, **options)
|
90
|
-
@build_mutex.synchronize { builder.build
|
83
|
+
@build_mutex.synchronize { builder.build } if should_build?
|
91
84
|
|
92
85
|
find_manifest_entry resolve_entry_name(name, **options)
|
93
86
|
end
|
@@ -128,24 +121,19 @@ private
|
|
128
121
|
|
129
122
|
# Internal: Loads and merges the manifest files, resolving the asset paths.
|
130
123
|
def load_manifest
|
131
|
-
files = config.
|
124
|
+
files = [config.manifest_path, config.assets_manifest_path].select(&:exist?)
|
132
125
|
files.map { |path| JSON.parse(path.read) }.inject({}, &:merge).tap(&method(:resolve_references))
|
133
126
|
end
|
134
127
|
|
135
128
|
# Internal: Scopes an asset to the output folder in public, as a path.
|
136
129
|
def prefix_vite_asset(path)
|
137
|
-
File.join(
|
130
|
+
File.join("/#{ config.public_output_dir }", path)
|
138
131
|
end
|
139
132
|
|
140
133
|
# Internal: Prefixes an asset with the `asset_host` for tags that do not use
|
141
134
|
# the framework tag helpers.
|
142
135
|
def prefix_asset_with_host(path)
|
143
|
-
File.join(
|
144
|
-
end
|
145
|
-
|
146
|
-
# Internal: The origin of assets managed by Vite.
|
147
|
-
def vite_asset_origin
|
148
|
-
config.origin if dev_server_running? && config.skip_proxy
|
136
|
+
File.join(config.asset_host || '/', config.public_output_dir, path)
|
149
137
|
end
|
150
138
|
|
151
139
|
# Internal: Resolves the paths that reference a manifest entry.
|
@@ -11,34 +11,25 @@ class ViteRuby::MissingEntrypointError < ViteRuby::Error
|
|
11
11
|
def initialize(info)
|
12
12
|
@info = info
|
13
13
|
super <<~MSG
|
14
|
-
Vite Ruby can't find #{ file_name } in
|
14
|
+
Vite Ruby can't find #{ file_name } in #{ config.manifest_path.relative_path_from(config.root) } or #{ config.assets_manifest_path.relative_path_from(config.root) }.
|
15
15
|
|
16
16
|
Possible causes:
|
17
17
|
#{ possible_causes(last_build) }
|
18
18
|
:troubleshooting:
|
19
|
-
#{ "
|
20
|
-
#{ "
|
21
|
-
#{ "Last build in #{ config.mode } mode:\n#{ last_build.to_json }\n" if last_build.success }
|
19
|
+
#{ "\nContent 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" unless last_build.success.nil? }
|
22
21
|
MSG
|
23
22
|
end
|
24
23
|
|
25
24
|
def possible_causes(last_build)
|
26
|
-
if last_build.success == false
|
27
|
-
|
28
|
-
.sub(':mode:', config.mode)
|
29
|
-
.sub(':errors:', last_build.errors.to_s.gsub(/^(?!$)/, ' '))
|
30
|
-
elsif config.auto_build
|
31
|
-
DEFAULT_CAUSES
|
32
|
-
else
|
33
|
-
DEFAULT_CAUSES + NO_AUTO_BUILD_CAUSES
|
34
|
-
end
|
35
|
-
end
|
25
|
+
return FAILED_BUILD_CAUSES.sub(':mode:', config.mode) if last_build.success == false
|
26
|
+
return DEFAULT_CAUSES if config.auto_build
|
36
27
|
|
37
|
-
|
38
|
-
|
28
|
+
DEFAULT_CAUSES + NO_AUTO_BUILD_CAUSES
|
29
|
+
end
|
39
30
|
|
40
|
-
|
41
|
-
|
31
|
+
FAILED_BUILD_CAUSES = <<-MSG
|
32
|
+
- The last build failed. Try running `bin/vite build --clear --mode=:mode:` manually and check for errors.
|
42
33
|
MSG
|
43
34
|
|
44
35
|
DEFAULT_CAUSES = <<-MSG
|
data/lib/vite_ruby/runner.rb
CHANGED
@@ -8,7 +8,7 @@ class ViteRuby::Runner
|
|
8
8
|
|
9
9
|
# Public: Executes Vite with the specified arguments.
|
10
10
|
def run(argv, exec: false)
|
11
|
-
config.
|
11
|
+
Dir.chdir(config.root) {
|
12
12
|
cmd = command_for(argv)
|
13
13
|
return Kernel.exec(*cmd) if exec
|
14
14
|
|
@@ -23,15 +23,15 @@ private
|
|
23
23
|
|
24
24
|
extend Forwardable
|
25
25
|
|
26
|
-
def_delegators :@vite_ruby, :config, :logger
|
26
|
+
def_delegators :@vite_ruby, :config, :logger
|
27
27
|
|
28
28
|
# Internal: Returns an Array with the command to run.
|
29
29
|
def command_for(args)
|
30
|
-
[config.to_env
|
30
|
+
[config.to_env].tap do |cmd|
|
31
31
|
args = args.clone
|
32
32
|
cmd.push('node', '--inspect-brk') if args.delete('--inspect')
|
33
33
|
cmd.push('node', '--trace-deprecation') if args.delete('--trace_deprecation')
|
34
|
-
cmd.push(
|
34
|
+
cmd.push(vite_executable)
|
35
35
|
cmd.push(*args)
|
36
36
|
cmd.push('--mode', config.mode) unless args.include?('--mode') || args.include?('-m')
|
37
37
|
end
|
@@ -40,12 +40,6 @@ private
|
|
40
40
|
# Internal: Resolves to an executable for Vite.
|
41
41
|
def vite_executable
|
42
42
|
bin_path = config.vite_bin_path
|
43
|
-
|
44
|
-
|
45
|
-
if config.root.join('yarn.lock').exist?
|
46
|
-
%w[yarn vite]
|
47
|
-
else
|
48
|
-
["#{ `npm bin`.chomp }/vite"]
|
49
|
-
end
|
43
|
+
File.exist?(bin_path) ? bin_path : "#{ `npm bin`.chomp }/vite"
|
50
44
|
end
|
51
45
|
end
|
data/lib/vite_ruby/version.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class ViteRuby
|
4
|
-
VERSION = '
|
4
|
+
VERSION = '4.0.0.alpha1'
|
5
5
|
|
6
6
|
# Internal: Versions used by default when running `vite install`.
|
7
|
-
DEFAULT_VITE_VERSION = '^
|
8
|
-
DEFAULT_PLUGIN_VERSION = '^
|
7
|
+
DEFAULT_VITE_VERSION = '^2.7.7'
|
8
|
+
DEFAULT_PLUGIN_VERSION = '^3.0.5'
|
9
9
|
end
|
data/lib/vite_ruby.rb
CHANGED
@@ -11,10 +11,11 @@ loader.ignore("#{ __dir__ }/install")
|
|
11
11
|
loader.ignore("#{ __dir__ }/tasks")
|
12
12
|
loader.ignore("#{ __dir__ }/exe")
|
13
13
|
loader.inflector.inflect('cli' => 'CLI')
|
14
|
-
loader.inflector.inflect('ssr' => 'SSR')
|
15
14
|
loader.inflector.inflect('io' => 'IO')
|
16
15
|
loader.setup
|
17
16
|
|
17
|
+
require 'vite_ruby/version'
|
18
|
+
|
18
19
|
class ViteRuby
|
19
20
|
# Internal: Prefix used for environment variables that modify the configuration.
|
20
21
|
ENV_PREFIX = 'VITE_RUBY'
|
@@ -32,7 +33,7 @@ class ViteRuby
|
|
32
33
|
class << self
|
33
34
|
extend Forwardable
|
34
35
|
|
35
|
-
def_delegators :instance, :config, :
|
36
|
+
def_delegators :instance, :config, :commands, :env, :run, :run_proxy?
|
36
37
|
def_delegators :config, :mode
|
37
38
|
|
38
39
|
def instance
|
@@ -75,26 +76,17 @@ class ViteRuby
|
|
75
76
|
@logger ||= Logger.new($stdout)
|
76
77
|
end
|
77
78
|
|
78
|
-
# Public: Returns a digest of all the watched files, allowing to detect
|
79
|
-
# changes. Useful to perform version checks in single-page applications.
|
80
|
-
def digest
|
81
|
-
builder.send(:watched_files_digest)
|
82
|
-
end
|
83
|
-
|
84
79
|
# Public: Returns true if the Vite development server is currently running.
|
85
80
|
# NOTE: Checks only once every second since every lookup calls this method.
|
86
81
|
def dev_server_running?
|
87
82
|
return false unless run_proxy?
|
88
|
-
return
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
ensure
|
96
|
-
@running_checked_at = Time.now
|
97
|
-
end
|
83
|
+
return true if defined?(@running_at) && @running_at && Time.now - @running_at < 1
|
84
|
+
|
85
|
+
Socket.tcp(config.host, config.port, connect_timeout: config.dev_server_connect_timeout).close
|
86
|
+
@running_at = Time.now
|
87
|
+
true
|
88
|
+
rescue StandardError
|
89
|
+
@running_at = false
|
98
90
|
end
|
99
91
|
|
100
92
|
# Public: Additional environment variables to pass to Vite.
|
@@ -131,22 +123,15 @@ class ViteRuby
|
|
131
123
|
# Public: Current instance configuration for Vite.
|
132
124
|
def config
|
133
125
|
unless defined?(@config)
|
134
|
-
|
126
|
+
@config = ViteRuby::Config.resolve_config(**@config_options)
|
135
127
|
@config.load_ruby_config
|
136
128
|
end
|
137
129
|
|
138
130
|
@config
|
139
131
|
end
|
140
132
|
|
141
|
-
# Public: Allows overriding the configuration for this instance.
|
142
|
-
def configure(**options)
|
143
|
-
@config = ViteRuby::Config.resolve_config(**@config_options, **options)
|
144
|
-
end
|
145
|
-
|
146
133
|
# Public: Enables looking up assets managed by Vite using name and type.
|
147
134
|
def manifest
|
148
135
|
@manifest ||= ViteRuby::Manifest.new(self)
|
149
136
|
end
|
150
137
|
end
|
151
|
-
|
152
|
-
require 'vite_ruby/version'
|
metadata
CHANGED
@@ -1,35 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vite_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.0.alpha1
|
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:
|
11
|
+
date: 2022-01-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-cli
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0.7'
|
20
|
-
- - "<"
|
17
|
+
- - "~>"
|
21
18
|
- !ruby/object:Gem::Version
|
22
|
-
version:
|
19
|
+
version: 0.7.0
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
|
-
- - "
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '0.7'
|
30
|
-
- - "<"
|
24
|
+
- - "~>"
|
31
25
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
26
|
+
version: 0.7.0
|
33
27
|
- !ruby/object:Gem::Dependency
|
34
28
|
name: rack-proxy
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -185,7 +179,6 @@ files:
|
|
185
179
|
- lib/vite_ruby/cli/dev.rb
|
186
180
|
- lib/vite_ruby/cli/file_utils.rb
|
187
181
|
- lib/vite_ruby/cli/install.rb
|
188
|
-
- lib/vite_ruby/cli/ssr.rb
|
189
182
|
- lib/vite_ruby/cli/upgrade.rb
|
190
183
|
- lib/vite_ruby/cli/upgrade_packages.rb
|
191
184
|
- lib/vite_ruby/cli/version.rb
|
@@ -208,8 +201,8 @@ homepage: https://github.com/ElMassimo/vite_ruby
|
|
208
201
|
licenses:
|
209
202
|
- MIT
|
210
203
|
metadata:
|
211
|
-
source_code_uri: https://github.com/ElMassimo/vite_ruby/tree/vite_ruby@
|
212
|
-
changelog_uri: https://github.com/ElMassimo/vite_ruby/blob/vite_ruby@
|
204
|
+
source_code_uri: https://github.com/ElMassimo/vite_ruby/tree/vite_ruby@4.0.0.alpha1/vite_ruby
|
205
|
+
changelog_uri: https://github.com/ElMassimo/vite_ruby/blob/vite_ruby@4.0.0.alpha1/vite_ruby/CHANGELOG.md
|
213
206
|
post_install_message: "Thanks for installing Vite Ruby!\n\nIf you upgraded the gem
|
214
207
|
manually, please run:\n\tbundle exec vite upgrade"
|
215
208
|
rdoc_options: []
|
@@ -219,14 +212,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
219
212
|
requirements:
|
220
213
|
- - ">="
|
221
214
|
- !ruby/object:Gem::Version
|
222
|
-
version: '2.
|
215
|
+
version: '2.4'
|
223
216
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
224
217
|
requirements:
|
225
|
-
- - "
|
218
|
+
- - ">"
|
226
219
|
- !ruby/object:Gem::Version
|
227
|
-
version:
|
220
|
+
version: 1.3.1
|
228
221
|
requirements: []
|
229
|
-
rubygems_version: 3.
|
222
|
+
rubygems_version: 3.2.32
|
230
223
|
signing_key:
|
231
224
|
specification_version: 4
|
232
225
|
summary: Use Vite in Ruby and bring joy to your JavaScript experience
|