vite_ruby 1.1.2 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/default.vite.json +1 -0
- data/lib/tasks/vite.rake +0 -1
- data/lib/vite_ruby/cli.rb +1 -0
- data/lib/vite_ruby/cli/build.rb +4 -2
- data/lib/vite_ruby/cli/clobber.rb +13 -0
- data/lib/vite_ruby/commands.rb +3 -3
- data/lib/vite_ruby/config.rb +1 -1
- data/lib/vite_ruby/error.rb +11 -0
- data/lib/vite_ruby/manifest.rb +6 -37
- data/lib/vite_ruby/missing_entrypoint_error.rb +45 -0
- data/lib/vite_ruby/missing_executable_error.rb +13 -0
- data/lib/vite_ruby/runner.rb +10 -8
- data/lib/vite_ruby/version.rb +1 -1
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d9655dc4d615097239f9382298b8e2080b0ea63b9d23423cbb6c603817b6a3a1
|
4
|
+
data.tar.gz: 7046d45ec63fdcdb7e712113d0d6861a6c6df11ed06e0befac721315cb31546c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c7553b547d6a411ec608128285c84321a96707906b29c8e5c94f91d8a63db65a8054cb6d529bbaf1f30acc1bbbe98df392ea1bea8f0c80b8c827e6a630e4ab38
|
7
|
+
data.tar.gz: 4c9b45b1804d5d8aa10cc8997bbe4ab4277d9d2de44c497e679c9d67bb65dcae516210a8b3813ed84aa4627d28656112a40c69878e7f89aab0b6df045cf496f2
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
# [1.2.0](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@1.1.2...vite_ruby@1.2.0) (2021-03-19)
|
2
|
+
|
3
|
+
|
4
|
+
### Bug Fixes
|
5
|
+
|
6
|
+
* Improve error messages when the Vite executable is missing ([#41](https://github.com/ElMassimo/vite_ruby/issues/41)) ([a79edc6](https://github.com/ElMassimo/vite_ruby/commit/a79edc6cc603c1094ede9e899226e98f734e7bbe))
|
7
|
+
|
8
|
+
|
9
|
+
### Features
|
10
|
+
|
11
|
+
* Add `clobber` to the CLI, usable as `--clear` in the `dev` and `build` commands ([331d861](https://github.com/ElMassimo/vite_ruby/commit/331d86163c12eb3303d3975a94ecc205fa59dd41))
|
12
|
+
* Allow `clobber` to receive a `--mode` option. ([e6e7a6d](https://github.com/ElMassimo/vite_ruby/commit/e6e7a6dd0a2acf205d06877f76deb924c1d5aba7))
|
13
|
+
|
14
|
+
|
15
|
+
|
1
16
|
## [1.1.2](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@1.1.1...vite_ruby@1.1.2) (2021-03-19)
|
2
17
|
|
3
18
|
|
data/default.vite.json
CHANGED
data/lib/tasks/vite.rake
CHANGED
@@ -22,7 +22,6 @@ namespace :vite do
|
|
22
22
|
desc 'Remove the vite build output directory'
|
23
23
|
task clobber: :'vite:verify_install' do
|
24
24
|
ViteRuby.commands.clobber
|
25
|
-
$stdout.puts "Removed vite build output directory #{ ViteRuby.config.build_output_dir }"
|
26
25
|
end
|
27
26
|
|
28
27
|
desc 'Verifies if ViteRuby is properly installed in this application'
|
data/lib/vite_ruby/cli.rb
CHANGED
@@ -8,6 +8,7 @@ class ViteRuby::CLI
|
|
8
8
|
extend Dry::CLI::Registry
|
9
9
|
|
10
10
|
register 'build', Build, aliases: ['b']
|
11
|
+
register 'clobber', Clobber, aliases: %w[clean clear]
|
11
12
|
register 'dev', Dev, aliases: %w[d serve]
|
12
13
|
register 'install', Install, aliases: %w[setup init]
|
13
14
|
register 'version', Version, aliases: ['v', '-v', '--version', 'info']
|
data/lib/vite_ruby/cli/build.rb
CHANGED
@@ -5,7 +5,8 @@ class ViteRuby::CLI::Build < Dry::CLI::Command
|
|
5
5
|
DEFAULT_ENV = CURRENT_ENV || 'production'
|
6
6
|
|
7
7
|
def self.shared_options
|
8
|
-
option(:mode, default: self::DEFAULT_ENV, values: %w[development production], aliases: ['m'], desc: 'The build mode for Vite')
|
8
|
+
option(:mode, default: self::DEFAULT_ENV, values: %w[development production test], aliases: ['m'], desc: 'The build mode for Vite')
|
9
|
+
option(:clobber, desc: 'Clear cache and previous builds', type: :boolean, aliases: %w[clean clear])
|
9
10
|
option(:debug, desc: 'Run Vite in verbose mode, printing all debugging output', aliases: ['verbose'], type: :boolean)
|
10
11
|
option(:inspect, desc: 'Run Vite in a debugging session with node --inspect-brk', aliases: ['inspect-brk'], type: :boolean)
|
11
12
|
option(:trace_deprecation, desc: 'Run Vite in debugging mode with node --trace-deprecation', aliases: ['trace-deprecation'], type: :boolean)
|
@@ -15,8 +16,9 @@ class ViteRuby::CLI::Build < Dry::CLI::Command
|
|
15
16
|
shared_options
|
16
17
|
option(:force, desc: 'Force the build even if assets have not changed', type: :boolean)
|
17
18
|
|
18
|
-
def call(mode:, args: [], **boolean_opts)
|
19
|
+
def call(mode:, args: [], clobber: false, **boolean_opts)
|
19
20
|
ViteRuby.env['VITE_RUBY_MODE'] = mode
|
21
|
+
ViteRuby.commands.clobber if clobber
|
20
22
|
boolean_opts.map { |name, value| args << "--#{ name }" if value }
|
21
23
|
block_given? ? yield(args) : ViteRuby.commands.build_from_task(*args)
|
22
24
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class ViteRuby::CLI::Clobber < Dry::CLI::Command
|
4
|
+
desc 'Clear the Vite cache, temp files, and builds'
|
5
|
+
|
6
|
+
current_env = ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'development'
|
7
|
+
|
8
|
+
option(:mode, default: current_env, values: %w[development production test], aliases: ['m'], desc: 'The mode to use')
|
9
|
+
|
10
|
+
def call(**)
|
11
|
+
ViteRuby.commands.clobber
|
12
|
+
end
|
13
|
+
end
|
data/lib/vite_ruby/commands.rb
CHANGED
@@ -23,9 +23,9 @@ class ViteRuby::Commands
|
|
23
23
|
|
24
24
|
# Public: Removes all build cache and previously compiled assets.
|
25
25
|
def clobber
|
26
|
-
config.build_output_dir.
|
27
|
-
|
28
|
-
|
26
|
+
dirs = [config.build_output_dir, config.build_cache_dir, config.vite_cache_dir]
|
27
|
+
dirs.each { |dir| dir.rmtree if dir.exist? }
|
28
|
+
$stdout.puts "Removed vite cache and output dirs:\n\t#{ dirs.join("\n\t") }"
|
29
29
|
end
|
30
30
|
|
31
31
|
# Public: Receives arguments from a rake task.
|
data/lib/vite_ruby/config.rb
CHANGED
@@ -91,7 +91,7 @@ private
|
|
91
91
|
}
|
92
92
|
|
93
93
|
# Internal: Default values for a Ruby application.
|
94
|
-
def config_defaults(asset_host: nil, mode: ENV.fetch('RACK_ENV', '
|
94
|
+
def config_defaults(asset_host: nil, mode: ENV.fetch('RACK_ENV', 'development'), root: Dir.pwd)
|
95
95
|
{
|
96
96
|
'asset_host' => option_from_env('asset_host') || asset_host,
|
97
97
|
'config_path' => option_from_env('config_path') || DEFAULT_CONFIG.fetch('config_path'),
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Internal: Provides common functionality for errors.
|
4
|
+
class ViteRuby::Error < StandardError
|
5
|
+
def message
|
6
|
+
super.sub(':troubleshooting:', <<~MSG)
|
7
|
+
Visit the Troubleshooting guide for more information:
|
8
|
+
https://vite-ruby.netlify.app/guide/troubleshooting.html#troubleshooting
|
9
|
+
MSG
|
10
|
+
end
|
11
|
+
end
|
data/lib/vite_ruby/manifest.rb
CHANGED
@@ -10,9 +10,6 @@
|
|
10
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
|
-
class MissingEntryError < StandardError
|
14
|
-
end
|
15
|
-
|
16
13
|
def initialize(vite_ruby)
|
17
14
|
@vite_ruby = vite_ruby
|
18
15
|
@build_mutex = Mutex.new if config.auto_build
|
@@ -142,39 +139,11 @@ private
|
|
142
139
|
|
143
140
|
# Internal: Raises a detailed message when an entry is missing in the manifest.
|
144
141
|
def missing_entry_error(name, type: nil, **_options)
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
#{ possible_causes(last_build) }
|
152
|
-
Visit the Troubleshooting guide for more information:
|
153
|
-
https://vite-ruby.netlify.app/guide/troubleshooting.html#troubleshooting
|
154
|
-
#{ "\nContent in your manifests:\n#{ JSON.pretty_generate(@manifest) }\n" if last_build.success }
|
155
|
-
#{ "\nLast build in #{ config.mode } mode:\n#{ last_build.to_json }\n" unless last_build.success.nil? }
|
156
|
-
MSG
|
142
|
+
raise ViteRuby::MissingEntrypointError, OpenStruct.new(
|
143
|
+
file_name: with_file_extension(name, type),
|
144
|
+
last_build: builder.last_build_metadata,
|
145
|
+
manifest: @manifest,
|
146
|
+
config: config,
|
147
|
+
)
|
157
148
|
end
|
158
|
-
|
159
|
-
def possible_causes(last_build)
|
160
|
-
return FAILED_BUILD_CAUSES.sub(':mode', ViteRuby.mode) if last_build.success == false
|
161
|
-
return DEFAULT_CAUSES if config.auto_build
|
162
|
-
|
163
|
-
DEFAULT_CAUSES + NO_AUTO_BUILD_CAUSES
|
164
|
-
end
|
165
|
-
|
166
|
-
FAILED_BUILD_CAUSES = <<-MSG
|
167
|
-
- The last build failed. Try running `RACK_ENV=:mode bin/vite build --force` manually and check for errors.
|
168
|
-
MSG
|
169
|
-
|
170
|
-
DEFAULT_CAUSES = <<-MSG
|
171
|
-
- The file path is incorrect.
|
172
|
-
- The file is not in the entrypoints directory.
|
173
|
-
- Some files are outside the sourceCodeDir, and have not been added to watchAdditionalPaths.
|
174
|
-
MSG
|
175
|
-
|
176
|
-
NO_AUTO_BUILD_CAUSES = <<-MSG
|
177
|
-
- You have not run `bin/vite dev` to start Vite, or the dev server is not reachable.
|
178
|
-
- "autoBuild" is set to `false` in your config/vite.json for this environment.
|
179
|
-
MSG
|
180
149
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Internal: Raised when an entry is not found in the build manifest.
|
4
|
+
#
|
5
|
+
# NOTE: The complexity here is justified by the improved usability of providing
|
6
|
+
# a more specific error message depending on the situation.
|
7
|
+
class ViteRuby::MissingEntrypointError < ViteRuby::Error
|
8
|
+
extend Forwardable
|
9
|
+
def_delegators :@info, :file_name, :last_build, :manifest, :config
|
10
|
+
|
11
|
+
def initialize(info)
|
12
|
+
@info = info
|
13
|
+
super <<~MSG
|
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
|
+
|
16
|
+
Possible causes:
|
17
|
+
#{ possible_causes(last_build) }
|
18
|
+
:troubleshooting:
|
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
|
+
MSG
|
22
|
+
end
|
23
|
+
|
24
|
+
def possible_causes(last_build)
|
25
|
+
return FAILED_BUILD_CAUSES.sub(':mode:', config.mode) if last_build.success == false
|
26
|
+
return DEFAULT_CAUSES if config.auto_build
|
27
|
+
|
28
|
+
DEFAULT_CAUSES + NO_AUTO_BUILD_CAUSES
|
29
|
+
end
|
30
|
+
|
31
|
+
FAILED_BUILD_CAUSES = <<-MSG
|
32
|
+
- The last build failed. Try running `bin/vite build --clear --mode=:mode:` manually and check for errors.
|
33
|
+
MSG
|
34
|
+
|
35
|
+
DEFAULT_CAUSES = <<-MSG
|
36
|
+
- The file path is incorrect.
|
37
|
+
- The file is not in the entrypoints directory.
|
38
|
+
- Some files are outside the sourceCodeDir, and have not been added to watchAdditionalPaths.
|
39
|
+
MSG
|
40
|
+
|
41
|
+
NO_AUTO_BUILD_CAUSES = <<-MSG
|
42
|
+
- You have not run `bin/vite dev` to start Vite, or the dev server is not reachable.
|
43
|
+
- "autoBuild" is set to `false` in your config/vite.json for this environment.
|
44
|
+
MSG
|
45
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Internal: Raised when the Vite executable can not be found.
|
4
|
+
class ViteRuby::MissingExecutableError < ViteRuby::Error
|
5
|
+
def initialize(error = nil)
|
6
|
+
super <<~MSG
|
7
|
+
❌ The vite binary is not available. Have you installed Vite?
|
8
|
+
|
9
|
+
:troubleshooting:
|
10
|
+
#{ error }
|
11
|
+
MSG
|
12
|
+
end
|
13
|
+
end
|
data/lib/vite_ruby/runner.rb
CHANGED
@@ -10,11 +10,12 @@ class ViteRuby::Runner
|
|
10
10
|
|
11
11
|
# Public: Executes Vite with the specified arguments.
|
12
12
|
def run(argv, capture: false)
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
Dir.chdir(config.root) {
|
14
|
+
cmd = command_for(argv)
|
15
|
+
capture ? capture3_with_output(*cmd, chdir: config.root) : Kernel.exec(*cmd)
|
16
|
+
}
|
17
|
+
rescue Errno::ENOENT => error
|
18
|
+
raise ViteRuby::MissingExecutableError, error
|
18
19
|
end
|
19
20
|
|
20
21
|
private
|
@@ -29,15 +30,16 @@ private
|
|
29
30
|
args = args.clone
|
30
31
|
cmd.append('node', '--inspect-brk') if args.delete('--inspect')
|
31
32
|
cmd.append('node', '--trace-deprecation') if args.delete('--trace_deprecation')
|
32
|
-
cmd.append(
|
33
|
+
cmd.append(vite_executable)
|
33
34
|
cmd.append(*args)
|
34
35
|
cmd.append('--mode', config.mode) unless args.include?('--mode') || args.include?('-m')
|
35
36
|
end
|
36
37
|
end
|
37
38
|
|
38
39
|
# Internal: Resolves to an executable for Vite.
|
39
|
-
def vite_executable
|
40
|
-
|
40
|
+
def vite_executable
|
41
|
+
bin_path = config.vite_bin_path
|
42
|
+
File.exist?(bin_path) ? bin_path : "#{ `npm bin`.chomp }/vite"
|
41
43
|
end
|
42
44
|
|
43
45
|
# Internal: A modified version of capture3 that continuosly prints stdout.
|
data/lib/vite_ruby/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vite_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Máximo Mussini
|
@@ -217,13 +217,17 @@ files:
|
|
217
217
|
- lib/vite_ruby/builder.rb
|
218
218
|
- lib/vite_ruby/cli.rb
|
219
219
|
- lib/vite_ruby/cli/build.rb
|
220
|
+
- lib/vite_ruby/cli/clobber.rb
|
220
221
|
- lib/vite_ruby/cli/dev.rb
|
221
222
|
- lib/vite_ruby/cli/install.rb
|
222
223
|
- lib/vite_ruby/cli/version.rb
|
223
224
|
- lib/vite_ruby/commands.rb
|
224
225
|
- lib/vite_ruby/config.rb
|
225
226
|
- lib/vite_ruby/dev_server_proxy.rb
|
227
|
+
- lib/vite_ruby/error.rb
|
226
228
|
- lib/vite_ruby/manifest.rb
|
229
|
+
- lib/vite_ruby/missing_entrypoint_error.rb
|
230
|
+
- lib/vite_ruby/missing_executable_error.rb
|
227
231
|
- lib/vite_ruby/runner.rb
|
228
232
|
- lib/vite_ruby/version.rb
|
229
233
|
- templates/config/vite.config.ts
|
@@ -233,8 +237,8 @@ homepage: https://github.com/ElMassimo/vite_ruby
|
|
233
237
|
licenses:
|
234
238
|
- MIT
|
235
239
|
metadata:
|
236
|
-
source_code_uri: https://github.com/ElMassimo/vite_ruby/tree/vite_ruby@1.
|
237
|
-
changelog_uri: https://github.com/ElMassimo/vite_ruby/blob/vite_ruby@1.
|
240
|
+
source_code_uri: https://github.com/ElMassimo/vite_ruby/tree/vite_ruby@1.2.0/vite_ruby
|
241
|
+
changelog_uri: https://github.com/ElMassimo/vite_ruby/blob/vite_ruby@1.2.0/vite_ruby/CHANGELOG.md
|
238
242
|
post_install_message:
|
239
243
|
rdoc_options: []
|
240
244
|
require_paths:
|