vite_ruby 1.0.1 → 1.1.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 +47 -0
- data/README.md +9 -7
- data/lib/vite_ruby.rb +8 -5
- data/lib/vite_ruby/build.rb +29 -0
- data/lib/vite_ruby/builder.rb +37 -32
- data/lib/vite_ruby/cli/build.rb +8 -3
- data/lib/vite_ruby/cli/dev.rb +3 -2
- data/lib/vite_ruby/cli/install.rb +1 -1
- data/lib/vite_ruby/commands.rb +17 -10
- data/lib/vite_ruby/dev_server_proxy.rb +2 -1
- data/lib/vite_ruby/manifest.rb +30 -18
- data/lib/vite_ruby/runner.rb +40 -33
- data/lib/vite_ruby/version.rb +1 -1
- metadata +126 -22
- data/CONTRIBUTING.md +0 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 436737196c45af00694c405d697cea826566bec8ab5e0ef246f5917b253df3cf
|
4
|
+
data.tar.gz: c052a43c6faa9c07318658f870a50db7aabdf7beb7074e80dc9026272125becc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b164085097cd79feabc3dffec84129b042a92ede8a37de7aaa04adb1a679be37af609d4eba1f105cb5a924cb173e425c850795f346a2648de7b4dd80b3e9f1d1
|
7
|
+
data.tar.gz: 67bb02e9619228ac48361fac841c46d032f1f0094ea6fc57cfe8dd68431f1fb4a1101de7dea04b911b40057acbf1484eda11046a2dce85c5699a1643b6c129ef
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,50 @@
|
|
1
|
+
# [1.1.0](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@1.0.5...vite_ruby@1.1.0) (2021-03-07)
|
2
|
+
|
3
|
+
|
4
|
+
### Bug Fixes
|
5
|
+
|
6
|
+
* Add development mutex in manifest to prevent re-entrant builds ([a6c6976](https://github.com/ElMassimo/vite_ruby/commit/a6c6976ba3821d8d6f26d012de13a440cb91c95b))
|
7
|
+
* Allow passing --inspect and other options to the build command ([1818ea4](https://github.com/ElMassimo/vite_ruby/commit/1818ea4f1d211923dfe0c04037baca8b2fd3b991))
|
8
|
+
|
9
|
+
|
10
|
+
### Features
|
11
|
+
|
12
|
+
* Record status and timestamp of each build to provide better errors ([a35a64a](https://github.com/ElMassimo/vite_ruby/commit/a35a64ad4ca802da7bb6d5f5139985da864293a4))
|
13
|
+
* Stream build output to provide feedback as the command runs ([2bce338](https://github.com/ElMassimo/vite_ruby/commit/2bce33888513f6961da11ddfa9f9c703182abfa6))
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
## [1.0.5](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@1.0.4...vite_ruby@1.0.5) (2021-03-03)
|
18
|
+
|
19
|
+
|
20
|
+
### Bug Fixes
|
21
|
+
|
22
|
+
* Fix installation of JS packages, prevent silent failures (closes [#22](https://github.com/ElMassimo/vite_ruby/issues/22)) ([#23](https://github.com/ElMassimo/vite_ruby/issues/23)) ([d972e6f](https://github.com/ElMassimo/vite_ruby/commit/d972e6f3968988460753e7a831c8e9199bbd6891))
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
## [1.0.4](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@1.0.3...vite_ruby@1.0.4) (2021-02-25)
|
27
|
+
|
28
|
+
|
29
|
+
### Features
|
30
|
+
|
31
|
+
* Create Vite.js integration with Padrino ([#17](https://github.com/ElMassimo/vite_ruby/issues/17)) ([9e9a0a6](https://github.com/ElMassimo/vite_ruby/commit/9e9a0a67abceed0a784d3c2e0554c717d7f5d1d6))
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
## [1.0.3](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@1.0.2...vite_ruby@1.0.3) (2021-02-25)
|
36
|
+
|
37
|
+
|
38
|
+
### Bug Fixes
|
39
|
+
|
40
|
+
* Infer package manager correctly ([09d3036](https://github.com/ElMassimo/vite_ruby/commit/09d303627d6012ead50acd6f814a32521a76927f))
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
## Vite Ruby 1.0.2 (2020-02-10)
|
45
|
+
|
46
|
+
- Fix auto-compilation when the dev server is not available.
|
47
|
+
|
1
48
|
## Vite Ruby 1.0.1 (2020-02-10)
|
2
49
|
|
3
50
|
- Fix installation script in Ruby 2.5
|
data/README.md
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
<h1 align="center">
|
2
|
-
<a href="https://vite-
|
2
|
+
<a href="https://vite-ruby.netlify.app/">
|
3
3
|
<img src="https://raw.githubusercontent.com/ElMassimo/vite_ruby/main/docs/public/logo.svg" width="120px"/>
|
4
4
|
</a>
|
5
5
|
|
6
6
|
<br>
|
7
7
|
|
8
|
-
<a href="https://vite-
|
8
|
+
<a href="https://vite-ruby.netlify.app/">
|
9
9
|
Vite Ruby
|
10
10
|
</a>
|
11
11
|
|
@@ -30,11 +30,11 @@
|
|
30
30
|
</p>
|
31
31
|
</h1>
|
32
32
|
|
33
|
-
[website]: https://vite-
|
34
|
-
[configuration reference]: https://vite-
|
35
|
-
[features]: https://vite-
|
36
|
-
[guides]: https://vite-
|
37
|
-
[config]: https://vite-
|
33
|
+
[website]: https://vite-ruby.netlify.app/
|
34
|
+
[configuration reference]: https://vite-ruby.netlify.app/config/
|
35
|
+
[features]: https://vite-ruby.netlify.app/guide/introduction.html
|
36
|
+
[guides]: https://vite-ruby.netlify.app/guide/
|
37
|
+
[config]: https://vite-ruby.netlify.app/config/
|
38
38
|
[vite_rails]: https://github.com/ElMassimo/vite_ruby
|
39
39
|
[webpacker]: https://github.com/rails/webpacker
|
40
40
|
[vite]: http://vitejs.dev/
|
@@ -70,6 +70,8 @@ Please use [Issues] to report bugs you find, and [Discussions] to make feature r
|
|
70
70
|
|
71
71
|
Don't hesitate to _⭐️ star the project_ if you find it useful!
|
72
72
|
|
73
|
+
Using it in production? Always love to hear about it! 😃
|
74
|
+
|
73
75
|
|
74
76
|
## Special Thanks 🙏
|
75
77
|
|
data/lib/vite_ruby.rb
CHANGED
@@ -17,19 +17,17 @@ class ViteRuby
|
|
17
17
|
ENV_PREFIX = 'VITE_RUBY'
|
18
18
|
|
19
19
|
# Internal: Versions used by default when running `vite install`.
|
20
|
-
DEFAULT_VITE_VERSION = '^2.0.
|
21
|
-
DEFAULT_PLUGIN_VERSION = '^1.0.
|
20
|
+
DEFAULT_VITE_VERSION = '^2.0.3'
|
21
|
+
DEFAULT_PLUGIN_VERSION = '^1.0.13'
|
22
22
|
|
23
23
|
# Internal: Ruby Frameworks that have a companion library for Vite Ruby.
|
24
|
-
SUPPORTED_FRAMEWORKS = %w[rails hanami roda].freeze
|
24
|
+
SUPPORTED_FRAMEWORKS = %w[rails hanami roda padrino sinatra].freeze
|
25
25
|
|
26
26
|
class << self
|
27
27
|
extend Forwardable
|
28
28
|
|
29
29
|
def_delegators :instance, :config, :commands, :run_proxy?
|
30
30
|
def_delegators :config, :mode
|
31
|
-
def_delegators :commands, :build
|
32
|
-
def_delegators 'ViteRuby::Runner.new', :run
|
33
31
|
|
34
32
|
def instance
|
35
33
|
@instance ||= ViteRuby.new
|
@@ -53,6 +51,11 @@ class ViteRuby
|
|
53
51
|
load File.expand_path('tasks/vite.rake', __dir__)
|
54
52
|
end
|
55
53
|
|
54
|
+
# Internal: Executes the vite binary.
|
55
|
+
def run(argv, **options)
|
56
|
+
ViteRuby::Runner.new(instance).run(argv, **options)
|
57
|
+
end
|
58
|
+
|
56
59
|
# Internal: Refreshes the config after setting the env vars.
|
57
60
|
def reload_with(env_vars)
|
58
61
|
env.update(env_vars)
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Internal: Value object with information about the last build.
|
4
|
+
ViteRuby::Build = Struct.new(:success, :timestamp, :digest, :current_digest) do
|
5
|
+
# Internal: Combines information from a previous build with the current digest.
|
6
|
+
def self.from_previous(attrs, current_digest)
|
7
|
+
new(attrs['success'], attrs['timestamp'] || 'never', attrs['digest'] || 'none', current_digest)
|
8
|
+
end
|
9
|
+
|
10
|
+
# Internal: Returns true if watched files have changed since the last build.
|
11
|
+
def stale?
|
12
|
+
digest != current_digest
|
13
|
+
end
|
14
|
+
|
15
|
+
# Internal: Returns true if watched files have not changed since the last build.
|
16
|
+
def fresh?
|
17
|
+
!stale?
|
18
|
+
end
|
19
|
+
|
20
|
+
# Internal: Returns a new build with the specified result.
|
21
|
+
def with_result(success)
|
22
|
+
self.class.new(success, Time.now.strftime('%F %T'), current_digest)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Internal: Returns a JSON string with the metadata of the build.
|
26
|
+
def to_json(*_args)
|
27
|
+
JSON.pretty_generate(to_h)
|
28
|
+
end
|
29
|
+
end
|
data/lib/vite_ruby/builder.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'json'
|
3
4
|
require 'digest/sha1'
|
4
5
|
|
5
6
|
# Public: Keeps track of watched files and triggers builds as needed.
|
@@ -10,23 +11,22 @@ class ViteRuby::Builder
|
|
10
11
|
|
11
12
|
# Public: Checks if the watched files have changed since the last compilation,
|
12
13
|
# and triggers a Vite build if any files have changed.
|
13
|
-
def build
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
def build(*args)
|
15
|
+
last_build = last_build_metadata
|
16
|
+
if args.delete('--force') || last_build.stale?
|
17
|
+
build_with_vite(*args).tap { |success| record_build_metadata(success, last_build) }
|
18
|
+
elsif last_build.success
|
19
|
+
logger.debug "Skipping vite build. Watched files have not changed since the last build at #{ last_build.timestamp }"
|
18
20
|
true
|
21
|
+
else
|
22
|
+
logger.error "Skipping vite build. Watched files have not changed since the build failed at #{ last_build.timestamp } ❌"
|
23
|
+
false
|
19
24
|
end
|
20
25
|
end
|
21
26
|
|
22
|
-
#
|
23
|
-
def
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
# Public: Returns true if any of the assets built by Vite is out of date.
|
28
|
-
def stale?
|
29
|
-
!fresh?
|
27
|
+
# Internal: Reads the result of the last compilation from disk.
|
28
|
+
def last_build_metadata
|
29
|
+
ViteRuby::Build.from_previous(last_build_attrs, watched_files_digest)
|
30
30
|
end
|
31
31
|
|
32
32
|
private
|
@@ -35,21 +35,22 @@ private
|
|
35
35
|
|
36
36
|
def_delegators :@vite_ruby, :config, :logger
|
37
37
|
|
38
|
-
# Internal:
|
39
|
-
def
|
40
|
-
|
41
|
-
|
38
|
+
# Internal: Reads metadata recorded on the last build, if it exists.
|
39
|
+
def last_build_attrs
|
40
|
+
last_build_path.exist? ? JSON.parse(last_build_path.read.to_s) : {}
|
41
|
+
rescue JSON::JSONError, Errno::ENOENT, Errno::ENOTDIR
|
42
|
+
{}
|
42
43
|
end
|
43
44
|
|
44
|
-
# Internal:
|
45
|
-
def
|
46
|
-
config.build_cache_dir.
|
45
|
+
# Internal: Writes a digest of the watched files to disk for future checks.
|
46
|
+
def record_build_metadata(success, build)
|
47
|
+
config.build_cache_dir.mkpath
|
48
|
+
last_build_path.write build.with_result(success).to_json
|
47
49
|
end
|
48
50
|
|
49
|
-
# Internal:
|
50
|
-
def
|
51
|
-
|
52
|
-
rescue Errno::ENOENT, Errno::ENOTDIR
|
51
|
+
# Internal: The file path where metadata of the last build is stored.
|
52
|
+
def last_build_path
|
53
|
+
config.build_cache_dir.join("last-build-#{ config.mode }.json")
|
53
54
|
end
|
54
55
|
|
55
56
|
# Internal: Returns a digest of all the watched files, allowing to detect
|
@@ -65,11 +66,11 @@ private
|
|
65
66
|
# Public: Initiates a Vite build command to generate assets.
|
66
67
|
#
|
67
68
|
# Returns true if the build is successful, or false if it failed.
|
68
|
-
def build_with_vite
|
69
|
+
def build_with_vite(*args)
|
69
70
|
logger.info 'Building with Vite ⚡️'
|
70
71
|
|
71
|
-
stdout, stderr, status = ViteRuby.run(['build'], capture: true)
|
72
|
-
log_build_result(stdout, stderr, status)
|
72
|
+
stdout, stderr, status = ViteRuby.run(['build', *args], capture: true)
|
73
|
+
log_build_result(stdout, stderr.to_s, status)
|
73
74
|
|
74
75
|
status.success?
|
75
76
|
end
|
@@ -77,14 +78,14 @@ private
|
|
77
78
|
# Internal: Outputs the build results.
|
78
79
|
#
|
79
80
|
# NOTE: By default it also outputs the manifest entries.
|
80
|
-
def log_build_result(
|
81
|
+
def log_build_result(_stdout, stderr, status)
|
81
82
|
if status.success?
|
82
83
|
logger.info "Build with Vite complete: #{ config.build_output_dir }"
|
83
|
-
logger.error
|
84
|
-
logger.info(stdout) unless config.hide_build_console_output
|
84
|
+
logger.error stderr.to_s unless stderr.empty?
|
85
85
|
else
|
86
|
-
|
87
|
-
logger.error
|
86
|
+
logger.error stderr
|
87
|
+
logger.error 'Build with Vite failed! ❌'
|
88
|
+
logger.error '❌ Check that vite and vite-plugin-ruby are in devDependencies and have been installed. ' if stderr.include?('ERR! canceled')
|
88
89
|
end
|
89
90
|
end
|
90
91
|
|
@@ -96,7 +97,11 @@ private
|
|
96
97
|
*config.watch_additional_paths,
|
97
98
|
"#{ config.source_code_dir }/**/*",
|
98
99
|
'yarn.lock',
|
100
|
+
'package-lock.json',
|
101
|
+
'pnpm-lock.yaml',
|
99
102
|
'package.json',
|
103
|
+
'vite.config.ts',
|
104
|
+
'vite.config.js',
|
100
105
|
config.config_path,
|
101
106
|
].freeze
|
102
107
|
end
|
data/lib/vite_ruby/cli/build.rb
CHANGED
@@ -5,14 +5,19 @@ 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], aliases: ['m'], desc: 'The build mode for Vite')
|
9
|
+
option(:debug, desc: 'Run Vite in verbose mode, printing all debugging output', aliases: ['verbose'], type: :boolean)
|
10
|
+
option(:inspect, desc: 'Run Vite in a debugging session with node --inspect-brk', aliases: ['inspect-brk'], type: :boolean)
|
11
|
+
option(:trace_deprecation, desc: 'Run Vite in debugging mode with node --trace-deprecation', aliases: ['trace-deprecation'], type: :boolean)
|
9
12
|
end
|
10
13
|
|
11
14
|
desc 'Bundle all entrypoints using Vite.'
|
12
15
|
shared_options
|
16
|
+
option(:force, desc: 'Force the build even if assets have not changed', type: :boolean)
|
13
17
|
|
14
|
-
def call(mode:)
|
18
|
+
def call(mode:, args: [], **boolean_opts)
|
15
19
|
ViteRuby.env['VITE_RUBY_MODE'] = mode
|
16
|
-
|
20
|
+
boolean_opts.map { |name, value| args << "--#{ name }" if value }
|
21
|
+
block_given? ? yield(args) : ViteRuby.commands.build_from_task(*args)
|
17
22
|
end
|
18
23
|
end
|
data/lib/vite_ruby/cli/dev.rb
CHANGED
@@ -5,8 +5,9 @@ class ViteRuby::CLI::Dev < ViteRuby::CLI::Build
|
|
5
5
|
|
6
6
|
desc 'Start the Vite development server.'
|
7
7
|
shared_options
|
8
|
+
option(:force, desc: 'Force Vite to re-bundle dependencies', type: :boolean)
|
8
9
|
|
9
|
-
def call(
|
10
|
-
super
|
10
|
+
def call(**options)
|
11
|
+
super { |args| ViteRuby.run(args) }
|
11
12
|
end
|
12
13
|
end
|
@@ -75,7 +75,7 @@ private
|
|
75
75
|
write(package_json, '{}') unless package_json.exist?
|
76
76
|
Dir.chdir(root) do
|
77
77
|
deps = "vite@#{ ViteRuby::DEFAULT_VITE_VERSION } vite-plugin-ruby@#{ ViteRuby::DEFAULT_PLUGIN_VERSION }"
|
78
|
-
stdout, stderr, status = Open3.capture3({ 'CI' => 'true' }, "npx ni -D #{ deps }")
|
78
|
+
stdout, stderr, status = Open3.capture3({ 'CI' => 'true' }, "npx --package @antfu/ni -- ni -D #{ deps }")
|
79
79
|
stdout, stderr, = Open3.capture3({}, "yarn add -D #{ deps }") unless status.success?
|
80
80
|
say(stdout, "\n", stderr)
|
81
81
|
end
|
data/lib/vite_ruby/commands.rb
CHANGED
@@ -8,17 +8,17 @@ class ViteRuby::Commands
|
|
8
8
|
end
|
9
9
|
|
10
10
|
# Public: Defaults to production, and exits if the build fails.
|
11
|
-
def build_from_task
|
11
|
+
def build_from_task(*args)
|
12
12
|
with_node_env(ENV.fetch('NODE_ENV', 'production')) {
|
13
13
|
ensure_log_goes_to_stdout {
|
14
|
-
build || exit!
|
14
|
+
build(*args) || exit!
|
15
15
|
}
|
16
16
|
}
|
17
17
|
end
|
18
18
|
|
19
19
|
# Public: Builds all assets that are managed by Vite, from the entrypoints.
|
20
|
-
def build
|
21
|
-
builder.build.tap { manifest.refresh }
|
20
|
+
def build(*args)
|
21
|
+
builder.build(*args).tap { manifest.refresh }
|
22
22
|
end
|
23
23
|
|
24
24
|
# Public: Removes all build cache and previously compiled assets.
|
@@ -69,6 +69,7 @@ class ViteRuby::Commands
|
|
69
69
|
def verify_install
|
70
70
|
unless File.exist?(config.root.join('bin/vite'))
|
71
71
|
warn <<~WARN
|
72
|
+
|
72
73
|
vite binstub not found.
|
73
74
|
Have you run `bundle binstub vite`?
|
74
75
|
Make sure the bin directory and bin/vite are not included in .gitignore
|
@@ -78,6 +79,7 @@ class ViteRuby::Commands
|
|
78
79
|
config_path = config.root.join(config.config_path)
|
79
80
|
unless config_path.exist?
|
80
81
|
warn <<~WARN
|
82
|
+
|
81
83
|
Configuration #{ config_path } file for vite-plugin-ruby not found.
|
82
84
|
Make sure `bundle exec vite install` has run successfully before running dependent tasks.
|
83
85
|
WARN
|
@@ -88,7 +90,7 @@ class ViteRuby::Commands
|
|
88
90
|
# Internal: Prints information about ViteRuby's environment.
|
89
91
|
def print_info
|
90
92
|
Dir.chdir(config.root) do
|
91
|
-
$stdout.puts "
|
93
|
+
$stdout.puts "bin/vite present?: #{ File.exist? 'bin/vite' }"
|
92
94
|
|
93
95
|
$stdout.puts "vite_ruby: #{ ViteRuby::VERSION }"
|
94
96
|
ViteRuby.framework_libraries.each do |framework, library|
|
@@ -98,11 +100,14 @@ class ViteRuby::Commands
|
|
98
100
|
|
99
101
|
$stdout.puts "node: #{ `node --version` }"
|
100
102
|
$stdout.puts "npm: #{ `npm --version` }"
|
101
|
-
$stdout.puts "yarn: #{ `yarn --version` }"
|
103
|
+
$stdout.puts "yarn: #{ `yarn --version` rescue nil }"
|
104
|
+
$stdout.puts "pnpm: #{ `pnpm --version` rescue nil }"
|
102
105
|
$stdout.puts "ruby: #{ `ruby --version` }"
|
103
106
|
|
104
107
|
$stdout.puts "\n"
|
105
|
-
|
108
|
+
packages = `npm ls vite vite-plugin-ruby`
|
109
|
+
packages_msg = packages.include?('vite@') ? "installed packages:\n#{ packages }" : '❌ Check that vite and vite-plugin-ruby have been added as development dependencies and installed.'
|
110
|
+
$stdout.puts packages_msg
|
106
111
|
end
|
107
112
|
end
|
108
113
|
|
@@ -144,10 +149,12 @@ private
|
|
144
149
|
end
|
145
150
|
|
146
151
|
def ensure_log_goes_to_stdout
|
147
|
-
old_logger = logger
|
148
|
-
|
152
|
+
old_logger, original_sync = logger, $stdout.sync
|
153
|
+
|
154
|
+
$stdout.sync = true
|
155
|
+
self.logger = Logger.new($stdout, formatter: proc { |_, _, progname, msg| progname == 'vite' ? msg : "#{ msg }\n" })
|
149
156
|
yield
|
150
157
|
ensure
|
151
|
-
self.logger = old_logger
|
158
|
+
self.logger, $stdout.sync = old_logger, original_sync
|
152
159
|
end
|
153
160
|
end
|
@@ -9,7 +9,7 @@ class ViteRuby::DevServerProxy < Rack::Proxy
|
|
9
9
|
|
10
10
|
def initialize(app = nil, options = {})
|
11
11
|
@vite_ruby = options.delete(:vite_ruby) || ViteRuby.instance
|
12
|
-
options[:streaming] = false if
|
12
|
+
options[:streaming] = false if config.mode == 'test' && !options.key?(:streaming)
|
13
13
|
super
|
14
14
|
end
|
15
15
|
|
@@ -39,6 +39,7 @@ private
|
|
39
39
|
|
40
40
|
def forward_to_vite_dev_server(env)
|
41
41
|
rewrite_uri_for_vite(env)
|
42
|
+
env['QUERY_STRING'] ||= ''
|
42
43
|
env['HTTP_HOST'] = env['HTTP_X_FORWARDED_HOST'] = config.host
|
43
44
|
env['HTTP_X_FORWARDED_SERVER'] = config.host_with_port
|
44
45
|
env['HTTP_PORT'] = env['HTTP_X_FORWARDED_PORT'] = config.port.to_s
|
data/lib/vite_ruby/manifest.rb
CHANGED
@@ -15,6 +15,7 @@ class ViteRuby::Manifest
|
|
15
15
|
|
16
16
|
def initialize(vite_ruby)
|
17
17
|
@vite_ruby = vite_ruby
|
18
|
+
@build_mutex = Mutex.new if config.auto_build
|
18
19
|
end
|
19
20
|
|
20
21
|
# Public: Returns the path for the specified Vite entrypoint file.
|
@@ -65,7 +66,7 @@ protected
|
|
65
66
|
# manifest.lookup('calendar.js')
|
66
67
|
# => { "file" => "/vite/assets/calendar-1016838bab065ae1e122.js", "imports" => [] }
|
67
68
|
def lookup(name, type: nil)
|
68
|
-
build if should_build?
|
69
|
+
@build_mutex.synchronize { builder.build } if should_build?
|
69
70
|
|
70
71
|
find_manifest_entry(with_file_extension(name, type))
|
71
72
|
end
|
@@ -74,7 +75,7 @@ private
|
|
74
75
|
|
75
76
|
extend Forwardable
|
76
77
|
|
77
|
-
def_delegators :@vite_ruby, :config, :
|
78
|
+
def_delegators :@vite_ruby, :config, :builder, :dev_server_running?
|
78
79
|
|
79
80
|
# NOTE: Auto compilation is convenient when running tests, when the developer
|
80
81
|
# won't focus on the frontend, or when running the Vite server is not desired.
|
@@ -142,27 +143,38 @@ private
|
|
142
143
|
# Internal: Raises a detailed message when an entry is missing in the manifest.
|
143
144
|
def missing_entry_error(name, type: nil, **_options)
|
144
145
|
file_name = with_file_extension(name, type)
|
146
|
+
last_build = builder.last_build_metadata
|
145
147
|
raise ViteRuby::Manifest::MissingEntryError, <<~MSG
|
146
|
-
Vite Ruby can't find #{ file_name } in #{ config.manifest_path } or #{ config.assets_manifest_path }.
|
148
|
+
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) }.
|
147
149
|
|
148
150
|
Possible causes:
|
149
|
-
#{
|
150
|
-
|
151
|
-
|
152
|
-
#{ JSON.pretty_generate(@manifest) }
|
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? }
|
153
156
|
MSG
|
154
157
|
end
|
155
158
|
|
156
|
-
def
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
(local && !dev_server_running? && 'The Vite development server has crashed or is no longer available.'),
|
162
|
-
'You have misconfigured config/vite.json file.',
|
163
|
-
(!local && 'Assets have not been precompiled'),
|
164
|
-
].select(&:itself)
|
165
|
-
rescue StandardError
|
166
|
-
[]
|
159
|
+
def possible_causes(last_build)
|
160
|
+
return FAILED_BUILD_CAUSES if last_build.success == false
|
161
|
+
return DEFAULT_CAUSES if config.auto_build
|
162
|
+
|
163
|
+
DEFAULT_CAUSES + NO_AUTO_BUILD_CAUSES
|
167
164
|
end
|
165
|
+
|
166
|
+
FAILED_BUILD_CAUSES = <<-MSG
|
167
|
+
- The last build failed. Try running `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
|
168
180
|
end
|
data/lib/vite_ruby/runner.rb
CHANGED
@@ -4,54 +4,61 @@ require 'open3'
|
|
4
4
|
|
5
5
|
# Public: Executes Vite commands, providing conveniences for debugging.
|
6
6
|
class ViteRuby::Runner
|
7
|
-
|
8
|
-
|
9
|
-
$stdout.sync = true
|
10
|
-
detect_unsupported_switches!(argv)
|
11
|
-
execute_command(argv.clone, **options)
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
UNSUPPORTED_SWITCHES = %w[--host --port --https --root -r --config -c].freeze
|
17
|
-
|
18
|
-
# Internal: Allows to prevent configuration mistakes by ensuring the Ruby app
|
19
|
-
# and vite-plugin-ruby are using the same configuration for the dev server.
|
20
|
-
def detect_unsupported_switches!(args)
|
21
|
-
return unless (unsupported = UNSUPPORTED_SWITCHES & args).any?
|
22
|
-
|
23
|
-
$stdout.puts "Please set the following switches in your vite.json instead: #{ unsupported }."
|
24
|
-
exit!
|
7
|
+
def initialize(vite_ruby)
|
8
|
+
@vite_ruby = vite_ruby
|
25
9
|
end
|
26
10
|
|
27
|
-
#
|
28
|
-
def
|
11
|
+
# Public: Executes Vite with the specified arguments.
|
12
|
+
def run(argv, capture: false)
|
29
13
|
if capture
|
30
|
-
|
14
|
+
capture3_with_output(*command_for(argv), chdir: config.root)
|
31
15
|
else
|
32
|
-
Dir.chdir(
|
16
|
+
Dir.chdir(config.root) { Kernel.exec(*command_for(argv)) }
|
33
17
|
end
|
34
18
|
end
|
35
19
|
|
20
|
+
private
|
21
|
+
|
22
|
+
extend Forwardable
|
23
|
+
|
24
|
+
def_delegators :@vite_ruby, :config, :logger
|
25
|
+
|
36
26
|
# Internal: Returns an Array with the command to run.
|
37
27
|
def command_for(args)
|
38
|
-
[
|
39
|
-
|
40
|
-
cmd.append('node', '--
|
28
|
+
[config.to_env].tap do |cmd|
|
29
|
+
args = args.clone
|
30
|
+
cmd.append('node', '--inspect-brk') if args.delete('--inspect')
|
31
|
+
cmd.append('node', '--trace-deprecation') if args.delete('--trace_deprecation')
|
41
32
|
cmd.append(*vite_executable(cmd))
|
42
33
|
cmd.append(*args)
|
43
|
-
cmd.append('--mode',
|
34
|
+
cmd.append('--mode', config.mode) unless args.include?('--mode') || args.include?('-m')
|
44
35
|
end
|
45
36
|
end
|
46
37
|
|
47
|
-
# Internal: The environment variables to pass to the command.
|
48
|
-
def vite_env
|
49
|
-
ViteRuby.config.to_env
|
50
|
-
end
|
51
|
-
|
52
38
|
# Internal: Resolves to an executable for Vite.
|
53
39
|
def vite_executable(cmd)
|
54
|
-
|
55
|
-
|
40
|
+
cmd.include?('node') ? ['./node_modules/.bin/vite'] : ['npx', '--no-install', '--', 'vite']
|
41
|
+
end
|
42
|
+
|
43
|
+
# Internal: A modified version of capture3 that continuosly prints stdout.
|
44
|
+
# NOTE: This improves the experience of running bin/vite build.
|
45
|
+
def capture3_with_output(*cmd, **opts)
|
46
|
+
return Open3.capture3(*cmd, opts) if config.hide_build_console_output
|
47
|
+
|
48
|
+
Open3.popen3(*cmd, opts) { |_stdin, stdout, stderr, wait_threads|
|
49
|
+
out = Thread.new { read_lines(stdout) { |l| logger.info('vite') { l } } }
|
50
|
+
err = Thread.new { stderr.read }
|
51
|
+
[out.value, err.value, wait_threads.value]
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
# Internal: Reads and yield every line in the stream. Returns the full content.
|
56
|
+
def read_lines(io)
|
57
|
+
buffer = +''
|
58
|
+
while line = io.gets
|
59
|
+
buffer << line
|
60
|
+
yield line
|
61
|
+
end
|
62
|
+
buffer
|
56
63
|
end
|
57
64
|
end
|
data/lib/vite_ruby/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vite_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
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: 2021-
|
11
|
+
date: 2021-03-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-cli
|
@@ -28,6 +28,9 @@ dependencies:
|
|
28
28
|
name: rack-proxy
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.6'
|
31
34
|
- - ">="
|
32
35
|
- !ruby/object:Gem::Version
|
33
36
|
version: 0.6.1
|
@@ -35,6 +38,9 @@ dependencies:
|
|
35
38
|
prerelease: false
|
36
39
|
version_requirements: !ruby/object:Gem::Requirement
|
37
40
|
requirements:
|
41
|
+
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0.6'
|
38
44
|
- - ">="
|
39
45
|
- !ruby/object:Gem::Version
|
40
46
|
version: 0.6.1
|
@@ -42,58 +48,156 @@ dependencies:
|
|
42
48
|
name: zeitwerk
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
44
50
|
requirements:
|
45
|
-
- - "
|
51
|
+
- - "~>"
|
46
52
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
53
|
+
version: '2.2'
|
48
54
|
type: :runtime
|
49
55
|
prerelease: false
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
51
57
|
requirements:
|
52
|
-
- - "
|
58
|
+
- - "~>"
|
53
59
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
60
|
+
version: '2.2'
|
55
61
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
62
|
+
name: m
|
57
63
|
requirement: !ruby/object:Gem::Requirement
|
58
64
|
requirements:
|
59
|
-
- - "
|
65
|
+
- - "~>"
|
60
66
|
- !ruby/object:Gem::Version
|
61
|
-
version: 1.
|
67
|
+
version: '1.5'
|
62
68
|
type: :development
|
63
69
|
prerelease: false
|
64
70
|
version_requirements: !ruby/object:Gem::Requirement
|
65
71
|
requirements:
|
66
|
-
- - "
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '1.5'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: minitest
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '5.0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
67
87
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
88
|
+
version: '5.0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: minitest-reporters
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '1.4'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '1.4'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: minitest-stub_any_instance
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '1.0'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - "~>"
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '1.0'
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: pry-byebug
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - "~>"
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '3.9'
|
124
|
+
type: :development
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - "~>"
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '3.9'
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
name: rake
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - "~>"
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '13.0'
|
138
|
+
type: :development
|
139
|
+
prerelease: false
|
140
|
+
version_requirements: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - "~>"
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '13.0'
|
69
145
|
- !ruby/object:Gem::Dependency
|
70
146
|
name: rubocop
|
71
147
|
requirement: !ruby/object:Gem::Requirement
|
72
148
|
requirements:
|
73
|
-
- - "
|
149
|
+
- - "~>"
|
74
150
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
151
|
+
version: '1.9'
|
76
152
|
type: :development
|
77
153
|
prerelease: false
|
78
154
|
version_requirements: !ruby/object:Gem::Requirement
|
79
155
|
requirements:
|
80
|
-
- - "
|
156
|
+
- - "~>"
|
81
157
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
158
|
+
version: '1.9'
|
159
|
+
- !ruby/object:Gem::Dependency
|
160
|
+
name: rubocop-minitest
|
161
|
+
requirement: !ruby/object:Gem::Requirement
|
162
|
+
requirements:
|
163
|
+
- - "~>"
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0.10'
|
166
|
+
type: :development
|
167
|
+
prerelease: false
|
168
|
+
version_requirements: !ruby/object:Gem::Requirement
|
169
|
+
requirements:
|
170
|
+
- - "~>"
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
version: '0.10'
|
83
173
|
- !ruby/object:Gem::Dependency
|
84
174
|
name: rubocop-performance
|
85
175
|
requirement: !ruby/object:Gem::Requirement
|
86
176
|
requirements:
|
87
|
-
- - "
|
177
|
+
- - "~>"
|
88
178
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
179
|
+
version: '1.9'
|
90
180
|
type: :development
|
91
181
|
prerelease: false
|
92
182
|
version_requirements: !ruby/object:Gem::Requirement
|
93
183
|
requirements:
|
94
|
-
- - "
|
184
|
+
- - "~>"
|
185
|
+
- !ruby/object:Gem::Version
|
186
|
+
version: '1.9'
|
187
|
+
- !ruby/object:Gem::Dependency
|
188
|
+
name: simplecov
|
189
|
+
requirement: !ruby/object:Gem::Requirement
|
190
|
+
requirements:
|
191
|
+
- - "<"
|
192
|
+
- !ruby/object:Gem::Version
|
193
|
+
version: '0.18'
|
194
|
+
type: :development
|
195
|
+
prerelease: false
|
196
|
+
version_requirements: !ruby/object:Gem::Requirement
|
197
|
+
requirements:
|
198
|
+
- - "<"
|
95
199
|
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
200
|
+
version: '0.18'
|
97
201
|
description:
|
98
202
|
email:
|
99
203
|
- maximomussini@gmail.com
|
@@ -103,13 +207,13 @@ extensions: []
|
|
103
207
|
extra_rdoc_files: []
|
104
208
|
files:
|
105
209
|
- CHANGELOG.md
|
106
|
-
- CONTRIBUTING.md
|
107
210
|
- LICENSE.txt
|
108
211
|
- README.md
|
109
212
|
- default.vite.json
|
110
213
|
- exe/vite
|
111
214
|
- lib/tasks/vite.rake
|
112
215
|
- lib/vite_ruby.rb
|
216
|
+
- lib/vite_ruby/build.rb
|
113
217
|
- lib/vite_ruby/builder.rb
|
114
218
|
- lib/vite_ruby/cli.rb
|
115
219
|
- lib/vite_ruby/cli/build.rb
|
@@ -129,8 +233,8 @@ homepage: https://github.com/ElMassimo/vite_ruby
|
|
129
233
|
licenses:
|
130
234
|
- MIT
|
131
235
|
metadata:
|
132
|
-
source_code_uri: https://github.com/ElMassimo/vite_ruby/tree/vite_ruby@1.0
|
133
|
-
changelog_uri: https://github.com/ElMassimo/vite_ruby/blob/vite_ruby@1.0
|
236
|
+
source_code_uri: https://github.com/ElMassimo/vite_ruby/tree/vite_ruby@1.1.0/vite_ruby
|
237
|
+
changelog_uri: https://github.com/ElMassimo/vite_ruby/blob/vite_ruby@1.1.0/vite_ruby/CHANGELOG.md
|
134
238
|
post_install_message:
|
135
239
|
rdoc_options: []
|
136
240
|
require_paths:
|
data/CONTRIBUTING.md
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
## Setting Up a Development Environment
|
2
|
-
|
3
|
-
1. Install [Yarn](https://yarnpkg.com/)
|
4
|
-
|
5
|
-
2. Run the following commands to set up the development environment.
|
6
|
-
|
7
|
-
```
|
8
|
-
bundle install
|
9
|
-
```
|
10
|
-
|
11
|
-
## Making sure your changes pass all tests
|
12
|
-
There are a number of automated checks which run on GitHub Actions when a pull request is created.
|
13
|
-
You can run those checks on your own locally to make sure that your changes would not break the CI build.
|
14
|
-
|
15
|
-
### 1. Check the code for JavaScript style violations
|
16
|
-
```
|
17
|
-
yarn lint
|
18
|
-
```
|
19
|
-
|
20
|
-
### 2. Check the code for Ruby style violations
|
21
|
-
```
|
22
|
-
bundle exec rubocop
|
23
|
-
```
|
24
|
-
|
25
|
-
### 3. Run the JavaScript test suite
|
26
|
-
```
|
27
|
-
yarn test
|
28
|
-
```
|
29
|
-
|
30
|
-
### 4. Run the Ruby test suite
|
31
|
-
```
|
32
|
-
bundle exec rake test
|
33
|
-
```
|