vite_ruby 3.9.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 -400
- data/README.md +1 -1
- data/default.vite.json +2 -7
- data/exe/vite +0 -2
- data/lib/tasks/vite.rake +12 -49
- 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 +19 -24
- data/lib/vite_ruby/cli/upgrade_packages.rb +2 -1
- data/lib/vite_ruby/cli/vite.rb +4 -19
- data/lib/vite_ruby/cli.rb +0 -13
- data/lib/vite_ruby/commands.rb +61 -16
- data/lib/vite_ruby/compatibility_check.rb +1 -1
- data/lib/vite_ruby/config.rb +12 -41
- data/lib/vite_ruby/dev_server_proxy.rb +5 -10
- data/lib/vite_ruby/io.rb +1 -1
- data/lib/vite_ruby/manifest.rb +17 -29
- data/lib/vite_ruby/missing_entrypoint_error.rb +13 -21
- data/lib/vite_ruby/runner.rb +10 -18
- data/lib/vite_ruby/version.rb +3 -3
- data/lib/vite_ruby.rb +11 -26
- metadata +10 -31
- data/lib/vite_ruby/cli/ssr.rb +0 -27
@@ -5,39 +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
17
|
#{ possible_causes(last_build) }
|
17
18
|
:troubleshooting:
|
18
|
-
#{ "
|
19
|
-
#{ "
|
20
|
-
#{ "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? }
|
21
21
|
MSG
|
22
22
|
end
|
23
23
|
|
24
24
|
def possible_causes(last_build)
|
25
|
-
if last_build.success == false
|
26
|
-
|
27
|
-
.sub(':mode:', config.mode)
|
28
|
-
.sub(':errors:', last_build.errors.to_s.gsub(/^(?!$)/, ' '))
|
29
|
-
elsif config.auto_build
|
30
|
-
DEFAULT_CAUSES
|
31
|
-
else
|
32
|
-
DEFAULT_CAUSES + NO_AUTO_BUILD_CAUSES
|
33
|
-
end
|
34
|
-
end
|
25
|
+
return FAILED_BUILD_CAUSES.sub(':mode:', config.mode) if last_build.success == false
|
26
|
+
return DEFAULT_CAUSES if config.auto_build
|
35
27
|
|
36
|
-
|
37
|
-
|
28
|
+
DEFAULT_CAUSES + NO_AUTO_BUILD_CAUSES
|
29
|
+
end
|
38
30
|
|
39
|
-
|
40
|
-
|
31
|
+
FAILED_BUILD_CAUSES = <<-MSG
|
32
|
+
- The last build failed. Try running `bin/vite build --clear --mode=:mode:` manually and check for errors.
|
41
33
|
MSG
|
42
34
|
|
43
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,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(
|
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)
|
34
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
@@ -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,49 +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
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0.7'
|
20
|
-
- - "<"
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: '2'
|
23
|
-
type: :runtime
|
24
|
-
prerelease: false
|
25
|
-
version_requirements: !ruby/object:Gem::Requirement
|
26
|
-
requirements:
|
27
|
-
- - ">="
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '0.7'
|
30
|
-
- - "<"
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: '2'
|
33
|
-
- !ruby/object:Gem::Dependency
|
34
|
-
name: logger
|
35
15
|
requirement: !ruby/object:Gem::Requirement
|
36
16
|
requirements:
|
37
17
|
- - "~>"
|
38
18
|
- !ruby/object:Gem::Version
|
39
|
-
version:
|
19
|
+
version: 0.7.0
|
40
20
|
type: :runtime
|
41
21
|
prerelease: false
|
42
22
|
version_requirements: !ruby/object:Gem::Requirement
|
43
23
|
requirements:
|
44
24
|
- - "~>"
|
45
25
|
- !ruby/object:Gem::Version
|
46
|
-
version:
|
26
|
+
version: 0.7.0
|
47
27
|
- !ruby/object:Gem::Dependency
|
48
28
|
name: rack-proxy
|
49
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -199,7 +179,6 @@ files:
|
|
199
179
|
- lib/vite_ruby/cli/dev.rb
|
200
180
|
- lib/vite_ruby/cli/file_utils.rb
|
201
181
|
- lib/vite_ruby/cli/install.rb
|
202
|
-
- lib/vite_ruby/cli/ssr.rb
|
203
182
|
- lib/vite_ruby/cli/upgrade.rb
|
204
183
|
- lib/vite_ruby/cli/upgrade_packages.rb
|
205
184
|
- lib/vite_ruby/cli/version.rb
|
@@ -222,8 +201,8 @@ homepage: https://github.com/ElMassimo/vite_ruby
|
|
222
201
|
licenses:
|
223
202
|
- MIT
|
224
203
|
metadata:
|
225
|
-
source_code_uri: https://github.com/ElMassimo/vite_ruby/tree/vite_ruby@
|
226
|
-
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
|
227
206
|
post_install_message: "Thanks for installing Vite Ruby!\n\nIf you upgraded the gem
|
228
207
|
manually, please run:\n\tbundle exec vite upgrade"
|
229
208
|
rdoc_options: []
|
@@ -233,14 +212,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
233
212
|
requirements:
|
234
213
|
- - ">="
|
235
214
|
- !ruby/object:Gem::Version
|
236
|
-
version: '2.
|
215
|
+
version: '2.4'
|
237
216
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
238
217
|
requirements:
|
239
|
-
- - "
|
218
|
+
- - ">"
|
240
219
|
- !ruby/object:Gem::Version
|
241
|
-
version:
|
220
|
+
version: 1.3.1
|
242
221
|
requirements: []
|
243
|
-
rubygems_version: 3.
|
222
|
+
rubygems_version: 3.2.32
|
244
223
|
signing_key:
|
245
224
|
specification_version: 4
|
246
225
|
summary: Use Vite in Ruby and bring joy to your JavaScript experience
|
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
|