vite_ruby 3.0.0.beta.1 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/default.vite.json +2 -1
- data/lib/tasks/vite.rake +8 -6
- data/lib/vite_ruby/builder.rb +1 -21
- data/lib/vite_ruby/cli/build.rb +1 -0
- data/lib/vite_ruby/commands.rb +3 -1
- data/lib/vite_ruby/compatibility_check.rb +49 -0
- data/lib/vite_ruby/config.rb +29 -3
- data/lib/vite_ruby/manifest.rb +24 -6
- data/lib/vite_ruby/version.rb +3 -3
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9606e4636341971487203132916240e61c6f78de01009ee2cc001ad8cc13f12a
|
4
|
+
data.tar.gz: 521ccded8cafa3b17ae62408650c0673c78b1441fc669532b240555702b51642
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b903a283f653cd02e89272174d66efd5991266c174418e978ed680205ea703d2d2a9384b16a155618788eaaae3748cb900eeca5b354e3e4277de7709a7784605
|
7
|
+
data.tar.gz: 60e731442205c932f7033317ea75651370474ae419d70f6204fa59059be61d54f472f583d136d93672167ac0777d049a229928f79896b6a96448525b44e5be83
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
## [3.0.1](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@3.0.0...vite_ruby@3.0.1) (2021-10-27)
|
2
|
+
|
3
|
+
|
4
|
+
### Features
|
5
|
+
|
6
|
+
* expose the `--watch` flag for the build command ([4e20d0a](https://github.com/ElMassimo/vite_ruby/commit/4e20d0a7b697b535e13335dac5a75fb8a193a133))
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
# [3.0.0](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@1.2.20...vite_ruby@3.0.0) (2021-08-16)
|
11
|
+
|
12
|
+
See https://github.com/ElMassimo/vite_ruby/pull/116 for features and breaking changes.
|
13
|
+
|
1
14
|
## [1.2.20](https://github.com/ElMassimo/vite_ruby/compare/vite_ruby@1.2.18...vite_ruby@1.2.20) (2021-07-30)
|
2
15
|
|
3
16
|
|
data/default.vite.json
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
{
|
2
|
-
"
|
2
|
+
"additionalEntrypoints": ["~/{assets,fonts,icons,images}/**/*"],
|
3
3
|
"assetHost": null,
|
4
4
|
"assetsDir": "assets",
|
5
5
|
"autoBuild": false,
|
@@ -10,6 +10,7 @@
|
|
10
10
|
"publicDir": "public",
|
11
11
|
"entrypointsDir": "entrypoints",
|
12
12
|
"sourceCodeDir": "app/frontend",
|
13
|
+
"skipCompatibilityCheck": false,
|
13
14
|
"host": "localhost",
|
14
15
|
"https": null,
|
15
16
|
"port": 3036,
|
data/lib/tasks/vite.rake
CHANGED
@@ -40,13 +40,15 @@ namespace :vite do
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
|
44
|
-
Rake::Task
|
45
|
-
|
46
|
-
|
43
|
+
unless ENV['VITE_RUBY_SKIP_ASSETS_PRECOMPILE_EXTENSION'] == 'true'
|
44
|
+
if Rake::Task.task_defined?('assets:precompile')
|
45
|
+
Rake::Task['assets:precompile'].enhance do |task|
|
46
|
+
prefix = task.name.split(/#|assets:precompile/).first
|
47
|
+
Rake::Task["#{ prefix }vite:build"].invoke
|
48
|
+
end
|
49
|
+
else
|
50
|
+
Rake::Task.define_task('assets:precompile' => ['vite:install_dependencies', 'vite:build'])
|
47
51
|
end
|
48
|
-
else
|
49
|
-
Rake::Task.define_task('assets:precompile' => ['vite:install_dependencies', 'vite:build'])
|
50
52
|
end
|
51
53
|
|
52
54
|
# Any prerequisite task that installs packages should also install build dependencies.
|
data/lib/vite_ruby/builder.rb
CHANGED
@@ -57,7 +57,7 @@ private
|
|
57
57
|
# changes, and skip Vite builds if no files have changed.
|
58
58
|
def watched_files_digest
|
59
59
|
Dir.chdir File.expand_path(config.root) do
|
60
|
-
files = Dir[*watched_paths].reject { |f| File.directory?(f) }
|
60
|
+
files = Dir[*config.watched_paths].reject { |f| File.directory?(f) }
|
61
61
|
file_ids = files.sort.map { |f| "#{ File.basename(f) }/#{ Digest::SHA1.file(f).hexdigest }" }
|
62
62
|
Digest::SHA1.hexdigest(file_ids.join('/'))
|
63
63
|
end
|
@@ -88,24 +88,4 @@ private
|
|
88
88
|
logger.error '❌ Check that vite and vite-plugin-ruby are in devDependencies and have been installed. ' if stderr.include?('ERR! canceled')
|
89
89
|
end
|
90
90
|
end
|
91
|
-
|
92
|
-
# Internal: Files and directories that should be watched for changes.
|
93
|
-
#
|
94
|
-
# NOTE: You can specify additional ones in vite.json using "watchAdditionalPaths": [...]
|
95
|
-
def watched_paths
|
96
|
-
[
|
97
|
-
*config.watch_additional_paths,
|
98
|
-
"#{ config.source_code_dir }/**/*",
|
99
|
-
'package-lock.json',
|
100
|
-
'package.json',
|
101
|
-
'pnpm-lock.yaml',
|
102
|
-
'postcss.config.js',
|
103
|
-
'tailwind.config.js',
|
104
|
-
'vite.config.js',
|
105
|
-
'vite.config.ts',
|
106
|
-
'windi.config.ts',
|
107
|
-
'yarn.lock',
|
108
|
-
config.config_path,
|
109
|
-
].freeze
|
110
|
-
end
|
111
91
|
end
|
data/lib/vite_ruby/cli/build.rb
CHANGED
@@ -6,6 +6,7 @@ class ViteRuby::CLI::Build < ViteRuby::CLI::Vite
|
|
6
6
|
desc 'Bundle all entrypoints using Vite.'
|
7
7
|
shared_options
|
8
8
|
option(:force, desc: 'Force the build even if assets have not changed', type: :boolean)
|
9
|
+
option(:watch, desc: 'Start the Rollup watcher and rebuild on files changes', type: :boolean)
|
9
10
|
|
10
11
|
def call(**options)
|
11
12
|
super { |args| ViteRuby.commands.build_from_task(*args) }
|
data/lib/vite_ruby/commands.rb
CHANGED
@@ -71,7 +71,7 @@ class ViteRuby::Commands
|
|
71
71
|
warn <<~WARN
|
72
72
|
|
73
73
|
vite binstub not found.
|
74
|
-
Have you run `bundle binstub
|
74
|
+
Have you run `bundle binstub vite_ruby`?
|
75
75
|
Make sure the bin directory and bin/vite are not included in .gitignore
|
76
76
|
WARN
|
77
77
|
end
|
@@ -108,6 +108,8 @@ class ViteRuby::Commands
|
|
108
108
|
packages = `npm ls vite vite-plugin-ruby`
|
109
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
110
|
$stdout.puts packages_msg
|
111
|
+
|
112
|
+
ViteRuby::CompatibilityCheck.verify_plugin_version(config.root)
|
111
113
|
end
|
112
114
|
end
|
113
115
|
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
# Internal: Verifies that the installed vite-plugin-ruby version is compatible
|
6
|
+
# with the current version of vite_ruby.
|
7
|
+
#
|
8
|
+
# This helps to prevent more subtle runtime errors if there is a mismatch in the
|
9
|
+
# manifest schema.
|
10
|
+
module ViteRuby::CompatibilityCheck
|
11
|
+
class << self
|
12
|
+
# Public: Attempt to verify that the vite-plugin-ruby version is compatible.
|
13
|
+
def verify_plugin_version(root)
|
14
|
+
package = JSON.parse(root.join('package.json').read) rescue {}
|
15
|
+
requirement = package.dig('devDependencies', 'vite-plugin-ruby') ||
|
16
|
+
package.dig('dependencies', 'vite-plugin-ruby')
|
17
|
+
|
18
|
+
raise_unless_satisfied(requirement, ViteRuby::DEFAULT_PLUGIN_VERSION)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Internal: Notifies the user of a possible incompatible plugin.
|
22
|
+
def raise_unless_satisfied(npm_req, ruby_req)
|
23
|
+
unless compatible_plugin?(npm_req, ruby_req)
|
24
|
+
raise ArgumentError, <<~ERROR
|
25
|
+
vite-plugin-ruby@#{ npm_req } might not be compatible with vite_ruby-#{ ViteRuby::VERSION }
|
26
|
+
|
27
|
+
You may disable this check if needed: https://vite-ruby.netlify.app/config/#skipCompatibilityCheck
|
28
|
+
|
29
|
+
You may upgrade both by running:
|
30
|
+
|
31
|
+
bundle exec vite upgrade
|
32
|
+
ERROR
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# Internal: Returns true unless the check is performed and does not meet the
|
37
|
+
# requirement.
|
38
|
+
def compatible_plugin?(npm_req, ruby_req)
|
39
|
+
npm_req, ruby_req = [npm_req, ruby_req]
|
40
|
+
.map { |req| Gem::Requirement.new(req.sub('^', '~>')) }
|
41
|
+
|
42
|
+
current_version = npm_req.requirements.first.second
|
43
|
+
|
44
|
+
ruby_req.satisfied_by?(current_version)
|
45
|
+
rescue StandardError
|
46
|
+
true
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/vite_ruby/config.rb
CHANGED
@@ -52,6 +52,18 @@ class ViteRuby::Config
|
|
52
52
|
end.merge(ViteRuby.env)
|
53
53
|
end
|
54
54
|
|
55
|
+
# Internal: Files and directories that should be watched for changes.
|
56
|
+
def watched_paths
|
57
|
+
[
|
58
|
+
*(watch_additional_paths + additional_entrypoints).reject { |dir|
|
59
|
+
dir.start_with?('~/') || dir.start_with?(source_code_dir)
|
60
|
+
},
|
61
|
+
"#{ source_code_dir }/**/*",
|
62
|
+
config_path,
|
63
|
+
*DEFAULT_WATCHED_PATHS,
|
64
|
+
].freeze
|
65
|
+
end
|
66
|
+
|
55
67
|
private
|
56
68
|
|
57
69
|
# Internal: Coerces all the configuration values, in case they were passed
|
@@ -61,7 +73,7 @@ private
|
|
61
73
|
config['port'] = config['port'].to_i
|
62
74
|
config['root'] = Pathname.new(config['root'])
|
63
75
|
config['build_cache_dir'] = config['root'].join(config['build_cache_dir'])
|
64
|
-
coerce_booleans(config, 'auto_build', 'hide_build_console_output', 'https')
|
76
|
+
coerce_booleans(config, 'auto_build', 'hide_build_console_output', 'https', 'skip_compatibility_check')
|
65
77
|
end
|
66
78
|
|
67
79
|
# Internal: Coerces configuration options to boolean.
|
@@ -71,6 +83,7 @@ private
|
|
71
83
|
|
72
84
|
def initialize(attrs)
|
73
85
|
@config = attrs.tap { |config| coerce_values(config) }.freeze
|
86
|
+
ViteRuby::CompatibilityCheck.verify_plugin_version(root) unless skip_compatibility_check
|
74
87
|
end
|
75
88
|
|
76
89
|
class << self
|
@@ -134,7 +147,7 @@ private
|
|
134
147
|
multi_env_config.fetch('all', {})
|
135
148
|
.merge(multi_env_config.fetch(mode, {}))
|
136
149
|
rescue Errno::ENOENT => error
|
137
|
-
|
150
|
+
$stderr << "Check that your vite.json configuration file is available in the load path:\n\n\t#{ error.message }\n\n"
|
138
151
|
{}
|
139
152
|
end
|
140
153
|
end
|
@@ -143,11 +156,24 @@ private
|
|
143
156
|
DEFAULT_CONFIG = load_json("#{ __dir__ }/../../default.vite.json").freeze
|
144
157
|
|
145
158
|
# Internal: Configuration options that can not be provided as env vars.
|
146
|
-
NOT_CONFIGURABLE_WITH_ENV = %w[
|
159
|
+
NOT_CONFIGURABLE_WITH_ENV = %w[additional_entrypoints watch_additional_paths].freeze
|
147
160
|
|
148
161
|
# Internal: Configuration options that can be provided as env vars.
|
149
162
|
CONFIGURABLE_WITH_ENV = (DEFAULT_CONFIG.keys + %w[mode root] - NOT_CONFIGURABLE_WITH_ENV).freeze
|
150
163
|
|
164
|
+
# Internal: If any of these files is modified the build won't be skipped.
|
165
|
+
DEFAULT_WATCHED_PATHS = %w[
|
166
|
+
package-lock.json
|
167
|
+
package.json
|
168
|
+
pnpm-lock.yaml
|
169
|
+
postcss.config.js
|
170
|
+
tailwind.config.js
|
171
|
+
vite.config.js
|
172
|
+
vite.config.ts
|
173
|
+
windi.config.ts
|
174
|
+
yarn.lock
|
175
|
+
].freeze
|
176
|
+
|
151
177
|
public
|
152
178
|
|
153
179
|
# Define getters for the configuration options.
|
data/lib/vite_ruby/manifest.rb
CHANGED
@@ -85,6 +85,9 @@ protected
|
|
85
85
|
|
86
86
|
private
|
87
87
|
|
88
|
+
# Internal: The prefix used by Vite.js to request files with an absolute path.
|
89
|
+
FS_PREFIX = '/@fs/'
|
90
|
+
|
88
91
|
extend Forwardable
|
89
92
|
|
90
93
|
def_delegators :@vite_ruby, :config, :builder, :dev_server_running?
|
@@ -135,7 +138,9 @@ private
|
|
135
138
|
def resolve_references(manifest)
|
136
139
|
manifest.each_value do |entry|
|
137
140
|
entry['file'] = prefix_vite_asset(entry['file'])
|
138
|
-
|
141
|
+
%w[css assets].each do |key|
|
142
|
+
entry[key] = entry[key].map { |path| prefix_vite_asset(path) } if entry[key]
|
143
|
+
end
|
139
144
|
entry['imports']&.map! { |name| manifest.fetch(name) }
|
140
145
|
end
|
141
146
|
end
|
@@ -143,13 +148,26 @@ private
|
|
143
148
|
# Internal: Resolves the manifest entry name for the specified resource.
|
144
149
|
def resolve_entry_name(name, type: nil)
|
145
150
|
name = with_file_extension(name.to_s, type)
|
146
|
-
name = name[1..-1] if name.start_with?('/')
|
147
151
|
|
148
|
-
|
149
|
-
|
150
|
-
|
152
|
+
raise ArgumentError, "Asset names can not be relative. Found: #{ name }" if name.start_with?('.') && !name.include?('legacy-polyfills')
|
153
|
+
|
154
|
+
# Explicit path, relative to the source_code_dir.
|
155
|
+
name.sub(%r{^~/(.+)$}) { return Regexp.last_match(1) }
|
156
|
+
|
157
|
+
# Explicit path, relative to the project root.
|
158
|
+
name.sub(%r{^/(.+)$}) { return resolve_absolute_entry(Regexp.last_match(1)) }
|
159
|
+
|
160
|
+
# Sugar: Prefix with the entrypoints dir if the path is not nested.
|
161
|
+
name.include?('/') ? name : File.join(config.entrypoints_dir, name)
|
162
|
+
end
|
163
|
+
|
164
|
+
# Internal: Entry names in the manifest are relative to the Vite.js.
|
165
|
+
# During develoment, files outside the root must be requested explicitly.
|
166
|
+
def resolve_absolute_entry(name)
|
167
|
+
if dev_server_running?
|
168
|
+
File.join(FS_PREFIX, config.root, name)
|
151
169
|
else
|
152
|
-
name
|
170
|
+
config.root.join(name).relative_path_from(config.vite_root_dir).to_s
|
153
171
|
end
|
154
172
|
end
|
155
173
|
|
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 = '3.0.
|
4
|
+
VERSION = '3.0.1'
|
5
5
|
|
6
6
|
# Internal: Versions used by default when running `vite install`.
|
7
|
-
DEFAULT_VITE_VERSION = '^2.
|
8
|
-
DEFAULT_PLUGIN_VERSION = '^3.0.
|
7
|
+
DEFAULT_VITE_VERSION = '^2.6.13'
|
8
|
+
DEFAULT_PLUGIN_VERSION = '^3.0.2'
|
9
9
|
end
|
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: 3.0.
|
4
|
+
version: 3.0.1
|
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-10-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-cli
|
@@ -184,6 +184,7 @@ files:
|
|
184
184
|
- lib/vite_ruby/cli/version.rb
|
185
185
|
- lib/vite_ruby/cli/vite.rb
|
186
186
|
- lib/vite_ruby/commands.rb
|
187
|
+
- lib/vite_ruby/compatibility_check.rb
|
187
188
|
- lib/vite_ruby/config.rb
|
188
189
|
- lib/vite_ruby/dev_server_proxy.rb
|
189
190
|
- lib/vite_ruby/error.rb
|
@@ -200,8 +201,8 @@ homepage: https://github.com/ElMassimo/vite_ruby
|
|
200
201
|
licenses:
|
201
202
|
- MIT
|
202
203
|
metadata:
|
203
|
-
source_code_uri: https://github.com/ElMassimo/vite_ruby/tree/vite_ruby@3.0.
|
204
|
-
changelog_uri: https://github.com/ElMassimo/vite_ruby/blob/vite_ruby@3.0.
|
204
|
+
source_code_uri: https://github.com/ElMassimo/vite_ruby/tree/vite_ruby@3.0.1/vite_ruby
|
205
|
+
changelog_uri: https://github.com/ElMassimo/vite_ruby/blob/vite_ruby@3.0.1/vite_ruby/CHANGELOG.md
|
205
206
|
post_install_message: "Thanks for installing Vite Ruby!\n\nIf you upgraded the gem
|
206
207
|
manually, please run:\n\tbundle exec vite upgrade"
|
207
208
|
rdoc_options: []
|
@@ -214,9 +215,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
214
215
|
version: '2.4'
|
215
216
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
216
217
|
requirements:
|
217
|
-
- - "
|
218
|
+
- - ">="
|
218
219
|
- !ruby/object:Gem::Version
|
219
|
-
version:
|
220
|
+
version: '0'
|
220
221
|
requirements: []
|
221
222
|
rubygems_version: 3.1.4
|
222
223
|
signing_key:
|