vite_ruby 3.10.2 → 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 -466
- data/README.md +1 -1
- data/default.vite.json +2 -7
- data/exe/vite +3 -5
- data/lib/tasks/vite.rake +19 -56
- data/lib/vite_ruby/build.rb +17 -47
- data/lib/vite_ruby/builder.rb +34 -29
- data/lib/vite_ruby/cli/build.rb +4 -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 +9 -16
- data/lib/vite_ruby/cli/install.rb +41 -46
- data/lib/vite_ruby/cli/upgrade.rb +4 -4
- data/lib/vite_ruby/cli/upgrade_packages.rb +4 -3
- data/lib/vite_ruby/cli/version.rb +1 -1
- data/lib/vite_ruby/cli/vite.rb +9 -24
- data/lib/vite_ruby/cli.rb +8 -21
- data/lib/vite_ruby/commands.rb +75 -31
- data/lib/vite_ruby/compatibility_check.rb +8 -8
- data/lib/vite_ruby/config.rb +37 -68
- data/lib/vite_ruby/dev_server_proxy.rb +24 -30
- data/lib/vite_ruby/error.rb +1 -1
- data/lib/vite_ruby/io.rb +4 -4
- data/lib/vite_ruby/manifest.rb +32 -63
- data/lib/vite_ruby/missing_entrypoint_error.rb +14 -21
- data/lib/vite_ruby/missing_executable_error.rb +1 -1
- data/lib/vite_ruby/runner.rb +12 -20
- data/lib/vite_ruby/version.rb +3 -3
- data/lib/vite_ruby.rb +34 -49
- metadata +15 -48
- data/lib/vite_ruby/cli/ssr.rb +0 -27
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)
|
|
@@ -19,37 +19,19 @@ class ViteRuby::Manifest
|
|
|
19
19
|
#
|
|
20
20
|
# Raises an error if the resource could not be found in the manifest.
|
|
21
21
|
def path_for(name, **options)
|
|
22
|
-
lookup!(name, **options).fetch(
|
|
22
|
+
lookup!(name, **options).fetch('file')
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
-
#
|
|
26
|
-
# Returns chunks in dependency-first order (deepest imports first), deduped.
|
|
27
|
-
def import_chunks_for(entry, seen_filenames: Set.new)
|
|
28
|
-
chunks = []
|
|
29
|
-
|
|
30
|
-
entry["imports"]&.each do |chunk|
|
|
31
|
-
filename = chunk["file"]
|
|
32
|
-
next if seen_filenames.include?(filename)
|
|
33
|
-
seen_filenames.add(filename)
|
|
34
|
-
|
|
35
|
-
chunks.concat(import_chunks_for(chunk, seen_filenames: seen_filenames))
|
|
36
|
-
chunks << chunk
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
chunks
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
# Public: Returns scripts, imported modules, and stylesheets for the specified
|
|
25
|
+
# Public: Returns entries, imported modules, and stylesheets for the specified
|
|
43
26
|
# entrypoint files.
|
|
44
27
|
def resolve_entries(*names, **options)
|
|
45
28
|
entries = names.map { |name| lookup!(name, **options) }
|
|
46
|
-
script_paths = entries.map { |entry| entry.fetch("file") }
|
|
47
29
|
|
|
48
|
-
imports = dev_server_running? ? [] : entries.flat_map { |entry|
|
|
30
|
+
imports = dev_server_running? ? [] : entries.flat_map { |entry| entry['imports'] }.compact.uniq
|
|
49
31
|
{
|
|
50
|
-
|
|
51
|
-
imports: imports.
|
|
52
|
-
stylesheets: dev_server_running? ? [] : (entries + imports).flat_map { |entry| entry[
|
|
32
|
+
main: entries.map(&TO_ENTRY),
|
|
33
|
+
imports: imports.map(&TO_ENTRY).uniq,
|
|
34
|
+
stylesheets: dev_server_running? ? [] : (entries + imports).flat_map { |entry| entry['css'] }.compact.uniq,
|
|
53
35
|
}
|
|
54
36
|
end
|
|
55
37
|
|
|
@@ -60,7 +42,7 @@ class ViteRuby::Manifest
|
|
|
60
42
|
|
|
61
43
|
# Public: The path from where the browser can download the Vite HMR client.
|
|
62
44
|
def vite_client_src
|
|
63
|
-
prefix_asset_with_host(
|
|
45
|
+
prefix_asset_with_host('@vite/client') if dev_server_running?
|
|
64
46
|
end
|
|
65
47
|
|
|
66
48
|
# Public: The content of the preamble needed by the React Refresh plugin.
|
|
@@ -68,27 +50,21 @@ class ViteRuby::Manifest
|
|
|
68
50
|
if dev_server_running?
|
|
69
51
|
<<~REACT_REFRESH
|
|
70
52
|
<script type="module">
|
|
71
|
-
#{
|
|
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
|
|
72
58
|
</script>
|
|
73
59
|
REACT_REFRESH
|
|
74
60
|
end
|
|
75
61
|
end
|
|
76
62
|
|
|
77
|
-
# Public: Source script for the React Refresh plugin.
|
|
78
|
-
def react_preamble_code
|
|
79
|
-
if dev_server_running?
|
|
80
|
-
<<~REACT_PREAMBLE_CODE
|
|
81
|
-
import RefreshRuntime from '#{prefix_asset_with_host("@react-refresh")}'
|
|
82
|
-
RefreshRuntime.injectIntoGlobalHook(window)
|
|
83
|
-
window.$RefreshReg$ = () => {}
|
|
84
|
-
window.$RefreshSig$ = () => (type) => type
|
|
85
|
-
window.__vite_plugin_react_preamble_installed__ = true
|
|
86
|
-
REACT_PREAMBLE_CODE
|
|
87
|
-
end
|
|
88
|
-
end
|
|
89
|
-
|
|
90
63
|
protected
|
|
91
64
|
|
|
65
|
+
# Internal: Returns a [src, attrs] entry.
|
|
66
|
+
TO_ENTRY = ->(entry) { [entry.fetch('file'), entry.slice('integrity').symbolize_keys] }
|
|
67
|
+
|
|
92
68
|
# Internal: Strict version of lookup.
|
|
93
69
|
#
|
|
94
70
|
# Returns a relative path for the asset, or raises an error if not found.
|
|
@@ -104,7 +80,7 @@ protected
|
|
|
104
80
|
# manifest.lookup('calendar.js')
|
|
105
81
|
# => { "file" => "/vite/assets/calendar-1016838bab065ae1e122.js", "imports" => [] }
|
|
106
82
|
def lookup(name, **options)
|
|
107
|
-
@build_mutex.synchronize { builder.build
|
|
83
|
+
@build_mutex.synchronize { builder.build } if should_build?
|
|
108
84
|
|
|
109
85
|
find_manifest_entry resolve_entry_name(name, **options)
|
|
110
86
|
end
|
|
@@ -112,7 +88,7 @@ protected
|
|
|
112
88
|
private
|
|
113
89
|
|
|
114
90
|
# Internal: The prefix used by Vite.js to request files with an absolute path.
|
|
115
|
-
FS_PREFIX =
|
|
91
|
+
FS_PREFIX = '/@fs/'
|
|
116
92
|
|
|
117
93
|
extend Forwardable
|
|
118
94
|
|
|
@@ -127,7 +103,7 @@ private
|
|
|
127
103
|
# Internal: Finds the specified entry in the manifest.
|
|
128
104
|
def find_manifest_entry(name)
|
|
129
105
|
if dev_server_running?
|
|
130
|
-
{
|
|
106
|
+
{ 'file' => prefix_vite_asset(name) }
|
|
131
107
|
else
|
|
132
108
|
manifest[name]
|
|
133
109
|
end
|
|
@@ -145,36 +121,29 @@ private
|
|
|
145
121
|
|
|
146
122
|
# Internal: Loads and merges the manifest files, resolving the asset paths.
|
|
147
123
|
def load_manifest
|
|
148
|
-
config.
|
|
149
|
-
|
|
150
|
-
.inject({}, &:merge)
|
|
151
|
-
.tap { |manifest| resolve_references(manifest) }
|
|
124
|
+
files = [config.manifest_path, config.assets_manifest_path].select(&:exist?)
|
|
125
|
+
files.map { |path| JSON.parse(path.read) }.inject({}, &:merge).tap(&method(:resolve_references))
|
|
152
126
|
end
|
|
153
127
|
|
|
154
128
|
# Internal: Scopes an asset to the output folder in public, as a path.
|
|
155
129
|
def prefix_vite_asset(path)
|
|
156
|
-
File.join(
|
|
130
|
+
File.join("/#{ config.public_output_dir }", path)
|
|
157
131
|
end
|
|
158
132
|
|
|
159
133
|
# Internal: Prefixes an asset with the `asset_host` for tags that do not use
|
|
160
134
|
# the framework tag helpers.
|
|
161
135
|
def prefix_asset_with_host(path)
|
|
162
|
-
File.join(
|
|
163
|
-
end
|
|
164
|
-
|
|
165
|
-
# Internal: The origin of assets managed by Vite.
|
|
166
|
-
def vite_asset_origin
|
|
167
|
-
config.origin if dev_server_running? && config.skip_proxy
|
|
136
|
+
File.join(config.asset_host || '/', config.public_output_dir, path)
|
|
168
137
|
end
|
|
169
138
|
|
|
170
139
|
# Internal: Resolves the paths that reference a manifest entry.
|
|
171
140
|
def resolve_references(manifest)
|
|
172
141
|
manifest.each_value do |entry|
|
|
173
|
-
entry[
|
|
142
|
+
entry['file'] = prefix_vite_asset(entry['file'])
|
|
174
143
|
%w[css assets].each do |key|
|
|
175
144
|
entry[key] = entry[key].map { |path| prefix_vite_asset(path) } if entry[key]
|
|
176
145
|
end
|
|
177
|
-
entry[
|
|
146
|
+
entry['imports']&.map! { |name| manifest.fetch(name) }
|
|
178
147
|
end
|
|
179
148
|
end
|
|
180
149
|
|
|
@@ -183,7 +152,7 @@ private
|
|
|
183
152
|
return resolve_virtual_entry(name) if type == :virtual
|
|
184
153
|
|
|
185
154
|
name = with_file_extension(name.to_s, type)
|
|
186
|
-
raise ArgumentError, "Asset names can not be relative. Found: #{name}" if name.start_with?(
|
|
155
|
+
raise ArgumentError, "Asset names can not be relative. Found: #{ name }" if name.start_with?('.')
|
|
187
156
|
|
|
188
157
|
# Explicit path, relative to the source_code_dir.
|
|
189
158
|
name.sub(%r{^~/(.+)$}) { return Regexp.last_match(1) }
|
|
@@ -192,7 +161,7 @@ private
|
|
|
192
161
|
name.sub(%r{^/(.+)$}) { return resolve_absolute_entry(Regexp.last_match(1)) }
|
|
193
162
|
|
|
194
163
|
# Sugar: Prefix with the entrypoints dir if the path is not nested.
|
|
195
|
-
name.include?(
|
|
164
|
+
name.include?('/') ? name : File.join(config.entrypoints_dir, name)
|
|
196
165
|
end
|
|
197
166
|
|
|
198
167
|
# Internal: Entry names in the manifest are relative to the Vite.js.
|
|
@@ -213,7 +182,7 @@ private
|
|
|
213
182
|
# Internal: Adds a file extension to the file name, unless it already has one.
|
|
214
183
|
def with_file_extension(name, entry_type)
|
|
215
184
|
if File.extname(name).empty? && (ext = extension_for_type(entry_type))
|
|
216
|
-
"#{name}.#{ext}"
|
|
185
|
+
"#{ name }.#{ ext }"
|
|
217
186
|
else
|
|
218
187
|
name
|
|
219
188
|
end
|
|
@@ -222,16 +191,16 @@ private
|
|
|
222
191
|
# Internal: Allows to receive :javascript and :stylesheet as :type in helpers.
|
|
223
192
|
def extension_for_type(entry_type)
|
|
224
193
|
case entry_type
|
|
225
|
-
when :javascript then
|
|
226
|
-
when :stylesheet then
|
|
227
|
-
when :typescript then
|
|
194
|
+
when :javascript then 'js'
|
|
195
|
+
when :stylesheet then 'css'
|
|
196
|
+
when :typescript then 'ts'
|
|
228
197
|
else entry_type
|
|
229
198
|
end
|
|
230
199
|
end
|
|
231
200
|
|
|
232
201
|
# Internal: Raises a detailed message when an entry is missing in the manifest.
|
|
233
202
|
def missing_entry_error(name, **options)
|
|
234
|
-
raise ViteRuby::MissingEntrypointError.new(
|
|
203
|
+
raise ViteRuby::MissingEntrypointError, OpenStruct.new(
|
|
235
204
|
file_name: resolve_entry_name(name, **options),
|
|
236
205
|
last_build: builder.last_build_metadata,
|
|
237
206
|
manifest: @manifest,
|
|
@@ -5,38 +5,31 @@
|
|
|
5
5
|
# NOTE: The complexity here is justified by the improved usability of providing
|
|
6
6
|
# a more specific error message depending on the situation.
|
|
7
7
|
class ViteRuby::MissingEntrypointError < ViteRuby::Error
|
|
8
|
-
|
|
8
|
+
extend Forwardable
|
|
9
|
+
def_delegators :@info, :file_name, :last_build, :manifest, :config
|
|
9
10
|
|
|
10
|
-
def initialize(
|
|
11
|
-
@
|
|
11
|
+
def initialize(info)
|
|
12
|
+
@info = info
|
|
12
13
|
super <<~MSG
|
|
13
|
-
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) }.
|
|
14
15
|
|
|
15
16
|
Possible causes:
|
|
16
|
-
#{possible_causes(last_build)}
|
|
17
|
+
#{ possible_causes(last_build) }
|
|
17
18
|
:troubleshooting:
|
|
18
|
-
#{"
|
|
19
|
-
#{"Last build in #{config.mode} mode:\n#{last_build.to_json}\n"
|
|
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? }
|
|
20
21
|
MSG
|
|
21
22
|
end
|
|
22
23
|
|
|
23
24
|
def possible_causes(last_build)
|
|
24
|
-
if last_build.success == false
|
|
25
|
-
|
|
26
|
-
.sub(":mode:", config.mode)
|
|
27
|
-
.sub(":errors:", last_build.errors.to_s.gsub(/^(?!$)/, " "))
|
|
28
|
-
elsif config.auto_build
|
|
29
|
-
DEFAULT_CAUSES
|
|
30
|
-
else
|
|
31
|
-
DEFAULT_CAUSES + NO_AUTO_BUILD_CAUSES
|
|
32
|
-
end
|
|
33
|
-
end
|
|
25
|
+
return FAILED_BUILD_CAUSES.sub(':mode:', config.mode) if last_build.success == false
|
|
26
|
+
return DEFAULT_CAUSES if config.auto_build
|
|
34
27
|
|
|
35
|
-
|
|
36
|
-
|
|
28
|
+
DEFAULT_CAUSES + NO_AUTO_BUILD_CAUSES
|
|
29
|
+
end
|
|
37
30
|
|
|
38
|
-
|
|
39
|
-
|
|
31
|
+
FAILED_BUILD_CAUSES = <<-MSG
|
|
32
|
+
- The last build failed. Try running `bin/vite build --clear --mode=:mode:` manually and check for errors.
|
|
40
33
|
MSG
|
|
41
34
|
|
|
42
35
|
DEFAULT_CAUSES = <<-MSG
|
data/lib/vite_ruby/runner.rb
CHANGED
|
@@ -8,11 +8,11 @@ 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
|
|
|
15
|
-
log_or_noop = ->(line) { logger.info(
|
|
15
|
+
log_or_noop = ->(line) { logger.info('vite') { line } } unless config.hide_build_console_output
|
|
16
16
|
ViteRuby::IO.capture(*cmd, chdir: config.root, with_output: log_or_noop)
|
|
17
17
|
}
|
|
18
18
|
rescue Errno::ENOENT => error
|
|
@@ -23,31 +23,23 @@ 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
|
|
31
|
-
|
|
32
|
-
cmd.push(
|
|
33
|
-
cmd.push(
|
|
34
|
-
cmd.push(
|
|
30
|
+
[config.to_env].tap do |cmd|
|
|
31
|
+
args = args.clone
|
|
32
|
+
cmd.push('node', '--inspect-brk') if args.delete('--inspect')
|
|
33
|
+
cmd.push('node', '--trace-deprecation') if args.delete('--trace_deprecation')
|
|
34
|
+
cmd.push(vite_executable)
|
|
35
|
+
cmd.push(*args)
|
|
36
|
+
cmd.push('--mode', config.mode) unless args.include?('--mode') || args.include?('-m')
|
|
35
37
|
end
|
|
36
38
|
end
|
|
37
39
|
|
|
38
40
|
# Internal: Resolves to an executable for Vite.
|
|
39
|
-
def vite_executable
|
|
41
|
+
def vite_executable
|
|
40
42
|
bin_path = config.vite_bin_path
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
x = case config.package_manager
|
|
44
|
-
when "npm" then %w[npx]
|
|
45
|
-
when "pnpm" then %w[pnpm exec]
|
|
46
|
-
when "bun" then %w[bun x --bun]
|
|
47
|
-
when "yarn" then %w[yarn]
|
|
48
|
-
else raise ArgumentError, "Unknown package manager #{config.package_manager.inspect}"
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
[*x, *exec_args, "vite"]
|
|
43
|
+
File.exist?(bin_path) ? bin_path : "#{ `npm bin`.chomp }/vite"
|
|
52
44
|
end
|
|
53
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
|
@@ -1,38 +1,39 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
4
|
-
require
|
|
5
|
-
require
|
|
6
|
-
require
|
|
3
|
+
require 'logger'
|
|
4
|
+
require 'forwardable'
|
|
5
|
+
require 'pathname'
|
|
6
|
+
require 'socket'
|
|
7
7
|
|
|
8
|
-
require
|
|
8
|
+
require 'zeitwerk'
|
|
9
9
|
loader = Zeitwerk::Loader.for_gem
|
|
10
|
-
loader.ignore("#{__dir__}/install")
|
|
11
|
-
loader.ignore("#{__dir__}/tasks")
|
|
12
|
-
loader.ignore("#{__dir__}/exe")
|
|
13
|
-
loader.inflector.inflect(
|
|
14
|
-
loader.inflector.inflect(
|
|
15
|
-
loader.inflector.inflect("io" => "IO")
|
|
10
|
+
loader.ignore("#{ __dir__ }/install")
|
|
11
|
+
loader.ignore("#{ __dir__ }/tasks")
|
|
12
|
+
loader.ignore("#{ __dir__ }/exe")
|
|
13
|
+
loader.inflector.inflect('cli' => 'CLI')
|
|
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
|
-
ENV_PREFIX =
|
|
21
|
+
ENV_PREFIX = 'VITE_RUBY'
|
|
21
22
|
|
|
22
23
|
# Internal: Companion libraries for Vite Ruby, and their target framework.
|
|
23
24
|
COMPANION_LIBRARIES = {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
'vite_rails' => 'rails',
|
|
26
|
+
'vite_hanami' => 'hanami',
|
|
27
|
+
'vite_padrino' => 'padrino',
|
|
28
|
+
'jekyll-vite' => 'jekyll',
|
|
29
|
+
'vite_rails_legacy' => 'rails',
|
|
30
|
+
'vite_plugin_legacy' => 'rack',
|
|
30
31
|
}
|
|
31
32
|
|
|
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
|
|
@@ -46,7 +47,7 @@ class ViteRuby
|
|
|
46
47
|
|
|
47
48
|
# Internal: Loads all available rake tasks.
|
|
48
49
|
def install_tasks
|
|
49
|
-
load File.expand_path(
|
|
50
|
+
load File.expand_path('tasks/vite.rake', __dir__)
|
|
50
51
|
end
|
|
51
52
|
|
|
52
53
|
# Internal: Creates a new instance with the specified options.
|
|
@@ -57,11 +58,11 @@ class ViteRuby
|
|
|
57
58
|
# Internal: Detects if the application has installed a framework-specific
|
|
58
59
|
# variant of Vite Ruby.
|
|
59
60
|
def framework_libraries
|
|
60
|
-
COMPANION_LIBRARIES.
|
|
61
|
+
COMPANION_LIBRARIES.map { |name, framework|
|
|
61
62
|
if library = Gem.loaded_specs[name]
|
|
62
63
|
[framework, library]
|
|
63
64
|
end
|
|
64
|
-
}
|
|
65
|
+
}.compact
|
|
65
66
|
end
|
|
66
67
|
end
|
|
67
68
|
|
|
@@ -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.
|
|
@@ -107,9 +99,9 @@ class ViteRuby
|
|
|
107
99
|
|
|
108
100
|
# Public: The proxy for assets should only run in development mode.
|
|
109
101
|
def run_proxy?
|
|
110
|
-
config.mode ==
|
|
111
|
-
rescue => error
|
|
112
|
-
logger.error("Failed to check mode for Vite: #{error.message}")
|
|
102
|
+
config.mode == 'development' || (config.mode == 'test' && !ENV['CI'])
|
|
103
|
+
rescue StandardError => error
|
|
104
|
+
logger.error("Failed to check mode for Vite: #{ error.message }")
|
|
113
105
|
false
|
|
114
106
|
end
|
|
115
107
|
|
|
@@ -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,62 +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
|
+
autorequire:
|
|
8
9
|
bindir: exe
|
|
9
10
|
cert_chain: []
|
|
10
|
-
date:
|
|
11
|
+
date: 2022-01-18 00:00:00.000000000 Z
|
|
11
12
|
dependencies:
|
|
12
13
|
- !ruby/object:Gem::Dependency
|
|
13
14
|
name: dry-cli
|
|
14
|
-
requirement: !ruby/object:Gem::Requirement
|
|
15
|
-
requirements:
|
|
16
|
-
- - ">="
|
|
17
|
-
- !ruby/object:Gem::Version
|
|
18
|
-
version: '0.7'
|
|
19
|
-
- - "<"
|
|
20
|
-
- !ruby/object:Gem::Version
|
|
21
|
-
version: '2'
|
|
22
|
-
type: :runtime
|
|
23
|
-
prerelease: false
|
|
24
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
-
requirements:
|
|
26
|
-
- - ">="
|
|
27
|
-
- !ruby/object:Gem::Version
|
|
28
|
-
version: '0.7'
|
|
29
|
-
- - "<"
|
|
30
|
-
- !ruby/object:Gem::Version
|
|
31
|
-
version: '2'
|
|
32
|
-
- !ruby/object:Gem::Dependency
|
|
33
|
-
name: logger
|
|
34
15
|
requirement: !ruby/object:Gem::Requirement
|
|
35
16
|
requirements:
|
|
36
17
|
- - "~>"
|
|
37
18
|
- !ruby/object:Gem::Version
|
|
38
|
-
version:
|
|
19
|
+
version: 0.7.0
|
|
39
20
|
type: :runtime
|
|
40
21
|
prerelease: false
|
|
41
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
42
23
|
requirements:
|
|
43
24
|
- - "~>"
|
|
44
25
|
- !ruby/object:Gem::Version
|
|
45
|
-
version:
|
|
46
|
-
- !ruby/object:Gem::Dependency
|
|
47
|
-
name: mutex_m
|
|
48
|
-
requirement: !ruby/object:Gem::Requirement
|
|
49
|
-
requirements:
|
|
50
|
-
- - ">="
|
|
51
|
-
- !ruby/object:Gem::Version
|
|
52
|
-
version: '0'
|
|
53
|
-
type: :runtime
|
|
54
|
-
prerelease: false
|
|
55
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
56
|
-
requirements:
|
|
57
|
-
- - ">="
|
|
58
|
-
- !ruby/object:Gem::Version
|
|
59
|
-
version: '0'
|
|
26
|
+
version: 0.7.0
|
|
60
27
|
- !ruby/object:Gem::Dependency
|
|
61
28
|
name: rack-proxy
|
|
62
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -181,14 +148,15 @@ dependencies:
|
|
|
181
148
|
requirements:
|
|
182
149
|
- - "<"
|
|
183
150
|
- !ruby/object:Gem::Version
|
|
184
|
-
version: '0.
|
|
151
|
+
version: '0.18'
|
|
185
152
|
type: :development
|
|
186
153
|
prerelease: false
|
|
187
154
|
version_requirements: !ruby/object:Gem::Requirement
|
|
188
155
|
requirements:
|
|
189
156
|
- - "<"
|
|
190
157
|
- !ruby/object:Gem::Version
|
|
191
|
-
version: '0.
|
|
158
|
+
version: '0.18'
|
|
159
|
+
description:
|
|
192
160
|
email:
|
|
193
161
|
- maximomussini@gmail.com
|
|
194
162
|
executables:
|
|
@@ -211,7 +179,6 @@ files:
|
|
|
211
179
|
- lib/vite_ruby/cli/dev.rb
|
|
212
180
|
- lib/vite_ruby/cli/file_utils.rb
|
|
213
181
|
- lib/vite_ruby/cli/install.rb
|
|
214
|
-
- lib/vite_ruby/cli/ssr.rb
|
|
215
182
|
- lib/vite_ruby/cli/upgrade.rb
|
|
216
183
|
- lib/vite_ruby/cli/upgrade_packages.rb
|
|
217
184
|
- lib/vite_ruby/cli/version.rb
|
|
@@ -234,9 +201,8 @@ homepage: https://github.com/ElMassimo/vite_ruby
|
|
|
234
201
|
licenses:
|
|
235
202
|
- MIT
|
|
236
203
|
metadata:
|
|
237
|
-
source_code_uri: https://github.com/ElMassimo/vite_ruby/tree/vite_ruby@
|
|
238
|
-
changelog_uri: https://github.com/ElMassimo/vite_ruby/blob/vite_ruby@
|
|
239
|
-
rubygems_mfa_required: 'true'
|
|
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
|
|
240
206
|
post_install_message: "Thanks for installing Vite Ruby!\n\nIf you upgraded the gem
|
|
241
207
|
manually, please run:\n\tbundle exec vite upgrade"
|
|
242
208
|
rdoc_options: []
|
|
@@ -246,14 +212,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
246
212
|
requirements:
|
|
247
213
|
- - ">="
|
|
248
214
|
- !ruby/object:Gem::Version
|
|
249
|
-
version: '2.
|
|
215
|
+
version: '2.4'
|
|
250
216
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
251
217
|
requirements:
|
|
252
|
-
- - "
|
|
218
|
+
- - ">"
|
|
253
219
|
- !ruby/object:Gem::Version
|
|
254
|
-
version:
|
|
220
|
+
version: 1.3.1
|
|
255
221
|
requirements: []
|
|
256
|
-
rubygems_version: 3.
|
|
222
|
+
rubygems_version: 3.2.32
|
|
223
|
+
signing_key:
|
|
257
224
|
specification_version: 4
|
|
258
225
|
summary: Use Vite in Ruby and bring joy to your JavaScript experience
|
|
259
226
|
test_files: []
|
data/lib/vite_ruby/cli/ssr.rb
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
class ViteRuby::CLI::SSR < ViteRuby::CLI::Vite
|
|
4
|
-
DEFAULT_ENV = CURRENT_ENV || "production"
|
|
5
|
-
JS_EXTENSIONS = %w[js mjs cjs]
|
|
6
|
-
|
|
7
|
-
desc "Run the resulting app from building in SSR mode."
|
|
8
|
-
executable_options
|
|
9
|
-
|
|
10
|
-
def call(mode:, inspect: false, trace_deprecation: false)
|
|
11
|
-
ViteRuby.env["VITE_RUBY_MODE"] = mode
|
|
12
|
-
|
|
13
|
-
ssr_entrypoint = JS_EXTENSIONS
|
|
14
|
-
.map { |ext| ViteRuby.config.ssr_output_dir.join("ssr.#{ext}") }
|
|
15
|
-
.find(&:exist?)
|
|
16
|
-
|
|
17
|
-
raise ArgumentError, "No ssr entrypoint found `#{ViteRuby.config.ssr_output_dir.relative_path_from(ViteRuby.config.root)}/ssr.{#{JS_EXTENSIONS.join(",")}}`. Have you run bin/vite build --ssr?" unless ssr_entrypoint
|
|
18
|
-
|
|
19
|
-
cmd = [
|
|
20
|
-
"node",
|
|
21
|
-
("--inspect-brk" if inspect),
|
|
22
|
-
("--trace-deprecation" if trace_deprecation),
|
|
23
|
-
ssr_entrypoint,
|
|
24
|
-
]
|
|
25
|
-
Kernel.exec(*cmd.compact.map(&:to_s))
|
|
26
|
-
end
|
|
27
|
-
end
|