vite_ruby 3.6.0 → 4.0.0.alpha1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +2 -327
- data/README.md +1 -1
- data/default.vite.json +1 -5
- data/exe/vite +0 -2
- data/lib/tasks/vite.rake +10 -57
- 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 -31
- 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 -30
- 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
data/lib/vite_ruby/cli/build.rb
CHANGED
@@ -5,10 +5,8 @@ class ViteRuby::CLI::Build < ViteRuby::CLI::Vite
|
|
5
5
|
|
6
6
|
desc 'Bundle all entrypoints using Vite.'
|
7
7
|
shared_options
|
8
|
-
option(:ssr, desc: 'Build the SSR entrypoint instead', type: :boolean)
|
9
8
|
option(:force, desc: 'Force the build even if assets have not changed', type: :boolean)
|
10
9
|
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
10
|
|
13
11
|
def call(**options)
|
14
12
|
super { |args| ViteRuby.commands.build_from_task(*args) }
|
@@ -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.
|
@@ -195,7 +175,6 @@ private
|
|
195
175
|
postcss.config.js
|
196
176
|
tailwind.config.js
|
197
177
|
vite.config.js
|
198
|
-
vite.config.mjs
|
199
178
|
vite.config.ts
|
200
179
|
windi.config.ts
|
201
180
|
yarn.lock
|
@@ -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
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'ostruct'
|
4
|
-
|
5
3
|
# Public: Registry for accessing resources managed by Vite, using a generated
|
6
4
|
# manifest file which maps entrypoint names to file paths.
|
7
5
|
#
|
@@ -9,7 +7,7 @@ require 'ostruct'
|
|
9
7
|
# lookup_entrypoint('calendar', type: :javascript)
|
10
8
|
# => { "file" => "/vite/assets/calendar-1016838bab065ae1e314.js", "imports" => [] }
|
11
9
|
#
|
12
|
-
# NOTE: Using
|
10
|
+
# NOTE: Using "autoBuild": true` in `config/vite.json` file will trigger a build
|
13
11
|
# on demand as needed, before performing any lookup.
|
14
12
|
class ViteRuby::Manifest
|
15
13
|
def initialize(vite_ruby)
|
@@ -24,16 +22,15 @@ class ViteRuby::Manifest
|
|
24
22
|
lookup!(name, **options).fetch('file')
|
25
23
|
end
|
26
24
|
|
27
|
-
# Public: Returns
|
25
|
+
# Public: Returns entries, imported modules, and stylesheets for the specified
|
28
26
|
# entrypoint files.
|
29
27
|
def resolve_entries(*names, **options)
|
30
28
|
entries = names.map { |name| lookup!(name, **options) }
|
31
|
-
script_paths = entries.map { |entry| entry.fetch('file') }
|
32
29
|
|
33
30
|
imports = dev_server_running? ? [] : entries.flat_map { |entry| entry['imports'] }.compact.uniq
|
34
31
|
{
|
35
|
-
|
36
|
-
imports: imports.map
|
32
|
+
main: entries.map(&TO_ENTRY),
|
33
|
+
imports: imports.map(&TO_ENTRY).uniq,
|
37
34
|
stylesheets: dev_server_running? ? [] : (entries + imports).flat_map { |entry| entry['css'] }.compact.uniq,
|
38
35
|
}
|
39
36
|
end
|
@@ -53,27 +50,21 @@ class ViteRuby::Manifest
|
|
53
50
|
if dev_server_running?
|
54
51
|
<<~REACT_REFRESH
|
55
52
|
<script type="module">
|
56
|
-
#{
|
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
|
57
58
|
</script>
|
58
59
|
REACT_REFRESH
|
59
60
|
end
|
60
61
|
end
|
61
62
|
|
62
|
-
# Public: Source script for the React Refresh plugin.
|
63
|
-
def react_preamble_code
|
64
|
-
if dev_server_running?
|
65
|
-
<<~REACT_PREAMBLE_CODE
|
66
|
-
import RefreshRuntime from '#{ prefix_asset_with_host('@react-refresh') }'
|
67
|
-
RefreshRuntime.injectIntoGlobalHook(window)
|
68
|
-
window.$RefreshReg$ = () => {}
|
69
|
-
window.$RefreshSig$ = () => (type) => type
|
70
|
-
window.__vite_plugin_react_preamble_installed__ = true
|
71
|
-
REACT_PREAMBLE_CODE
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
63
|
protected
|
76
64
|
|
65
|
+
# Internal: Returns a [src, attrs] entry.
|
66
|
+
TO_ENTRY = ->(entry) { [entry.fetch('file'), entry.slice('integrity').symbolize_keys] }
|
67
|
+
|
77
68
|
# Internal: Strict version of lookup.
|
78
69
|
#
|
79
70
|
# Returns a relative path for the asset, or raises an error if not found.
|
@@ -89,7 +80,7 @@ protected
|
|
89
80
|
# manifest.lookup('calendar.js')
|
90
81
|
# => { "file" => "/vite/assets/calendar-1016838bab065ae1e122.js", "imports" => [] }
|
91
82
|
def lookup(name, **options)
|
92
|
-
@build_mutex.synchronize { builder.build
|
83
|
+
@build_mutex.synchronize { builder.build } if should_build?
|
93
84
|
|
94
85
|
find_manifest_entry resolve_entry_name(name, **options)
|
95
86
|
end
|
@@ -130,24 +121,19 @@ private
|
|
130
121
|
|
131
122
|
# Internal: Loads and merges the manifest files, resolving the asset paths.
|
132
123
|
def load_manifest
|
133
|
-
files = config.
|
124
|
+
files = [config.manifest_path, config.assets_manifest_path].select(&:exist?)
|
134
125
|
files.map { |path| JSON.parse(path.read) }.inject({}, &:merge).tap(&method(:resolve_references))
|
135
126
|
end
|
136
127
|
|
137
128
|
# Internal: Scopes an asset to the output folder in public, as a path.
|
138
129
|
def prefix_vite_asset(path)
|
139
|
-
File.join(
|
130
|
+
File.join("/#{ config.public_output_dir }", path)
|
140
131
|
end
|
141
132
|
|
142
133
|
# Internal: Prefixes an asset with the `asset_host` for tags that do not use
|
143
134
|
# the framework tag helpers.
|
144
135
|
def prefix_asset_with_host(path)
|
145
|
-
File.join(
|
146
|
-
end
|
147
|
-
|
148
|
-
# Internal: The origin of assets managed by Vite.
|
149
|
-
def vite_asset_origin
|
150
|
-
config.origin if dev_server_running? && config.skip_proxy
|
136
|
+
File.join(config.asset_host || '/', config.public_output_dir, path)
|
151
137
|
end
|
152
138
|
|
153
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'
|