vite_rails 1.0.5 → 1.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +22 -0
- data/CONTRIBUTING.md +0 -1
- data/README.md +31 -69
- data/lib/install/javascript/entrypoints/application.js +8 -4
- data/lib/install/template.rb +1 -1
- data/lib/tasks/vite/build.rake +2 -6
- data/lib/tasks/vite/clean.rake +1 -3
- data/lib/tasks/vite/info.rake +0 -1
- data/lib/tasks/vite/verify_install.rake +3 -3
- data/lib/vite_rails.rb +14 -25
- data/lib/vite_rails/builder.rb +11 -13
- data/lib/vite_rails/commands.rb +51 -10
- data/lib/vite_rails/config.rb +65 -30
- data/lib/vite_rails/dev_server_proxy.rb +26 -18
- data/lib/vite_rails/helper.rb +15 -8
- data/lib/vite_rails/manifest.rb +6 -4
- data/lib/vite_rails/runner.rb +3 -6
- data/lib/vite_rails/version.rb +1 -1
- data/package.json +5 -1
- data/package/default.vite.json +2 -1
- data/test/builder_test.rb +27 -22
- data/test/commands_test.rb +67 -0
- data/test/config_test.rb +133 -0
- data/test/dev_server_proxy_test.rb +101 -0
- data/test/dev_server_test.rb +0 -30
- data/test/engine_rake_tasks_test.rb +55 -17
- data/test/helper_test.rb +37 -105
- data/test/manifest_test.rb +33 -29
- data/test/mode_test.rb +6 -11
- data/test/mounted_app/test/dummy/config/vite.json +5 -11
- data/test/mounted_app/test/dummy/package.json +2 -1
- data/test/mounted_app/test/dummy/yarn.lock +208 -0
- data/test/rake_tasks_test.rb +5 -19
- data/test/runner_test.rb +31 -0
- data/test/test_app/app/frontend/entrypoints/application.js +2 -0
- data/test/test_app/config/vite.json +0 -2
- data/test/test_app/config/vite_additional_paths.json +5 -0
- data/test/test_app/config/vite_public_dir.json +5 -0
- data/test/test_app/public/vite-production/manifest.json +22 -0
- data/test/test_helper.rb +48 -14
- metadata +23 -25
- data/test/command_test.rb +0 -35
- data/test/configuration_test.rb +0 -80
- data/test/dev_server_runner_test.rb +0 -83
- data/test/test_app/app/javascript/entrypoints/application.js +0 -10
- data/test/test_app/app/javascript/entrypoints/multi_entry.css +0 -4
- data/test/test_app/app/javascript/entrypoints/multi_entry.js +0 -4
- data/test/test_app/config/vite_public_root.yml +0 -20
- data/test/test_app/public/vite/manifest.json +0 -36
- data/test/vite_runner_test.rb +0 -59
- data/test/webpacker_test.rb +0 -15
@@ -0,0 +1,22 @@
|
|
1
|
+
{
|
2
|
+
"application.js": {
|
3
|
+
"file": "assets/application.a0ba047e.js",
|
4
|
+
"imports": [
|
5
|
+
"assets/example_import.8e1fddc0.js"
|
6
|
+
]
|
7
|
+
},
|
8
|
+
"example_import.js": {
|
9
|
+
"file": "assets/example_import.8e1fddc0.js",
|
10
|
+
"imports": []
|
11
|
+
},
|
12
|
+
"colored.js": {
|
13
|
+
"file": "assets/colored.1173bfe0.js",
|
14
|
+
"imports": []
|
15
|
+
},
|
16
|
+
"application.css": {
|
17
|
+
"file": "assets/application.cccfef34.css"
|
18
|
+
},
|
19
|
+
"colored.css": {
|
20
|
+
"file": "assets/colored.84277fd6.css"
|
21
|
+
}
|
22
|
+
}
|
data/test/test_helper.rb
CHANGED
@@ -1,34 +1,68 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'simplecov'
|
4
|
+
SimpleCov.start {
|
5
|
+
add_filter '/test/'
|
6
|
+
}
|
7
|
+
|
3
8
|
require 'minitest/autorun'
|
4
9
|
require 'rails'
|
5
10
|
require 'rails/test_help'
|
6
|
-
require 'byebug'
|
11
|
+
require 'pry-byebug'
|
7
12
|
|
8
13
|
require_relative 'test_app/config/environment'
|
9
14
|
|
10
15
|
Rails.env = 'production'
|
11
16
|
|
12
|
-
ViteRails.instance =
|
17
|
+
ViteRails.instance = ViteRails.new
|
13
18
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
ViteRails.instance.instance_variable_set(:@config, nil)
|
19
|
-
ViteRails.instance.instance_variable_set(:@dev_server, nil)
|
20
|
-
ViteRails.env = {}
|
21
|
-
ViteRails.config
|
22
|
-
ViteRails.dev_server
|
19
|
+
module ViteRailsTestHelpers
|
20
|
+
def refresh_config(env_variables = ViteRails.load_env_variables)
|
21
|
+
ViteRails.env = env_variables
|
22
|
+
(ViteRails.instance = ViteRails.new).config
|
23
23
|
end
|
24
24
|
|
25
25
|
def with_rails_env(env)
|
26
26
|
original = Rails.env
|
27
27
|
Rails.env = ActiveSupport::StringInquirer.new(env)
|
28
|
-
|
29
|
-
yield
|
28
|
+
yield(refresh_config)
|
30
29
|
ensure
|
31
30
|
Rails.env = ActiveSupport::StringInquirer.new(original)
|
32
|
-
|
31
|
+
refresh_config
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_app_path
|
35
|
+
File.expand_path('test_app', __dir__)
|
36
|
+
end
|
37
|
+
|
38
|
+
def with_dev_server_running(&block)
|
39
|
+
ViteRails.instance.stub(:dev_server_running?, true, &block)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class ViteRails::Test < Minitest::Test
|
44
|
+
include ViteRailsTestHelpers
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def assert_run_command(*argv, use_yarn: false, flags: [])
|
49
|
+
command = use_yarn ? %w[yarn vite] : ["#{ test_app_path }/node_modules/.bin/vite"]
|
50
|
+
cwd = Dir.pwd
|
51
|
+
Dir.chdir(test_app_path)
|
52
|
+
|
53
|
+
klass = ViteRails::Runner
|
54
|
+
instance = klass.new(argv)
|
55
|
+
mock = Minitest::Mock.new
|
56
|
+
mock.expect(:call, nil, [ViteRails.env, *command, *argv, *flags])
|
57
|
+
|
58
|
+
klass.stub(:new, instance) do
|
59
|
+
instance.stub(:executable_exists?, !use_yarn) do
|
60
|
+
Kernel.stub(:exec, mock) { ViteRails.run(argv) }
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
mock.verify
|
65
|
+
ensure
|
66
|
+
Dir.chdir(cwd)
|
33
67
|
end
|
34
68
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vite_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Máximo Mussini
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-01-
|
11
|
+
date: 2021-01-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -147,9 +147,9 @@ files:
|
|
147
147
|
- package.json
|
148
148
|
- package/default.vite.json
|
149
149
|
- test/builder_test.rb
|
150
|
-
- test/
|
151
|
-
- test/
|
152
|
-
- test/
|
150
|
+
- test/commands_test.rb
|
151
|
+
- test/config_test.rb
|
152
|
+
- test/dev_server_proxy_test.rb
|
153
153
|
- test/dev_server_test.rb
|
154
154
|
- test/engine_rake_tasks_test.rb
|
155
155
|
- test/helper_test.rb
|
@@ -164,30 +164,29 @@ files:
|
|
164
164
|
- test/mounted_app/test/dummy/config/environment.rb
|
165
165
|
- test/mounted_app/test/dummy/config/vite.json
|
166
166
|
- test/mounted_app/test/dummy/package.json
|
167
|
+
- test/mounted_app/test/dummy/yarn.lock
|
167
168
|
- test/rake_tasks_test.rb
|
169
|
+
- test/runner_test.rb
|
168
170
|
- test/test_app/Rakefile
|
169
|
-
- test/test_app/app/
|
170
|
-
- test/test_app/app/javascript/entrypoints/multi_entry.css
|
171
|
-
- test/test_app/app/javascript/entrypoints/multi_entry.js
|
171
|
+
- test/test_app/app/frontend/entrypoints/application.js
|
172
172
|
- test/test_app/bin/vite
|
173
173
|
- test/test_app/config.ru
|
174
174
|
- test/test_app/config/application.rb
|
175
175
|
- test/test_app/config/environment.rb
|
176
176
|
- test/test_app/config/vite.json
|
177
|
-
- test/test_app/config/
|
177
|
+
- test/test_app/config/vite_additional_paths.json
|
178
|
+
- test/test_app/config/vite_public_dir.json
|
178
179
|
- test/test_app/package.json
|
179
|
-
- test/test_app/public/vite/manifest.json
|
180
|
+
- test/test_app/public/vite-production/manifest.json
|
180
181
|
- test/test_app/some.config.js
|
181
182
|
- test/test_app/yarn.lock
|
182
183
|
- test/test_helper.rb
|
183
|
-
- test/vite_runner_test.rb
|
184
|
-
- test/webpacker_test.rb
|
185
184
|
homepage: https://github.com/ElMassimo/vite_rails
|
186
185
|
licenses:
|
187
186
|
- MIT
|
188
187
|
metadata:
|
189
|
-
source_code_uri: https://github.com/ElMassimo/vite_rails/tree/v1.0.
|
190
|
-
changelog_uri: https://github.com/ElMassimo/vite_rails/blob/v1.0.
|
188
|
+
source_code_uri: https://github.com/ElMassimo/vite_rails/tree/v1.0.10
|
189
|
+
changelog_uri: https://github.com/ElMassimo/vite_rails/blob/v1.0.10/CHANGELOG.md
|
191
190
|
post_install_message:
|
192
191
|
rdoc_options: []
|
193
192
|
require_paths:
|
@@ -196,7 +195,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
196
195
|
requirements:
|
197
196
|
- - ">="
|
198
197
|
- !ruby/object:Gem::Version
|
199
|
-
version: 2.
|
198
|
+
version: 2.5.0
|
200
199
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
201
200
|
requirements:
|
202
201
|
- - ">="
|
@@ -209,9 +208,9 @@ specification_version: 4
|
|
209
208
|
summary: Use Vite in Rails and bring joy to your JavaScript experience
|
210
209
|
test_files:
|
211
210
|
- test/builder_test.rb
|
212
|
-
- test/
|
213
|
-
- test/
|
214
|
-
- test/
|
211
|
+
- test/commands_test.rb
|
212
|
+
- test/config_test.rb
|
213
|
+
- test/dev_server_proxy_test.rb
|
215
214
|
- test/dev_server_test.rb
|
216
215
|
- test/engine_rake_tasks_test.rb
|
217
216
|
- test/helper_test.rb
|
@@ -226,21 +225,20 @@ test_files:
|
|
226
225
|
- test/mounted_app/test/dummy/config/environment.rb
|
227
226
|
- test/mounted_app/test/dummy/config/vite.json
|
228
227
|
- test/mounted_app/test/dummy/package.json
|
228
|
+
- test/mounted_app/test/dummy/yarn.lock
|
229
229
|
- test/rake_tasks_test.rb
|
230
|
+
- test/runner_test.rb
|
230
231
|
- test/test_app/Rakefile
|
231
|
-
- test/test_app/app/
|
232
|
-
- test/test_app/app/javascript/entrypoints/multi_entry.css
|
233
|
-
- test/test_app/app/javascript/entrypoints/multi_entry.js
|
232
|
+
- test/test_app/app/frontend/entrypoints/application.js
|
234
233
|
- test/test_app/bin/vite
|
235
234
|
- test/test_app/config.ru
|
236
235
|
- test/test_app/config/application.rb
|
237
236
|
- test/test_app/config/environment.rb
|
238
237
|
- test/test_app/config/vite.json
|
239
|
-
- test/test_app/config/
|
238
|
+
- test/test_app/config/vite_additional_paths.json
|
239
|
+
- test/test_app/config/vite_public_dir.json
|
240
240
|
- test/test_app/package.json
|
241
|
-
- test/test_app/public/vite/manifest.json
|
241
|
+
- test/test_app/public/vite-production/manifest.json
|
242
242
|
- test/test_app/some.config.js
|
243
243
|
- test/test_app/yarn.lock
|
244
244
|
- test/test_helper.rb
|
245
|
-
- test/vite_runner_test.rb
|
246
|
-
- test/webpacker_test.rb
|
data/test/command_test.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class CommandTest < Minitest::Test
|
6
|
-
def test_compile_command_returns_success_status_when_stale
|
7
|
-
ViteRails.builder.stub :stale?, true do
|
8
|
-
ViteRails.builder.stub :run_vite, true do
|
9
|
-
assert_equal true, ViteRails.commands.compile
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_compile_command_returns_success_status_when_fresh
|
15
|
-
ViteRails.builder.stub :stale?, false do
|
16
|
-
ViteRails.builder.stub :run_vite, true do
|
17
|
-
assert_equal true, ViteRails.commands.compile
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_compile_command_returns_failure_status_when_stale
|
23
|
-
ViteRails.builder.stub :stale?, true do
|
24
|
-
ViteRails.builder.stub :run_vite, false do
|
25
|
-
assert_equal false, ViteRails.commands.compile
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_clean_command_works_with_nested_hashes_and_without_any_compiled_files
|
31
|
-
File.stub :delete, true do
|
32
|
-
assert ViteRails.commands.clean
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
data/test/configuration_test.rb
DELETED
@@ -1,80 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class ConfigurationTest < ViteRails::Test
|
6
|
-
def setup
|
7
|
-
@config = ViteRails::Configuration.new(
|
8
|
-
root_path: Pathname.new(File.expand_path('test_app', __dir__)),
|
9
|
-
config_path: Pathname.new(File.expand_path('./test_app/config/vite.yml', __dir__)),
|
10
|
-
env: 'production',
|
11
|
-
)
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_source_path
|
15
|
-
source_path = File.expand_path File.join(File.dirname(__FILE__), 'test_app/app/javascript').to_s
|
16
|
-
assert_equal source_path, @config.source_path.to_s
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_source_entry_path
|
20
|
-
source_entry_path = File.expand_path File.join(File.dirname(__FILE__), 'test_app/app/javascript', 'packs').to_s
|
21
|
-
assert_equal @config.source_entry_path.to_s, source_entry_path
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_public_root_path
|
25
|
-
public_root_path = File.expand_path File.join(File.dirname(__FILE__), 'test_app/public').to_s
|
26
|
-
assert_equal @config.public_path.to_s, public_root_path
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_public_output_path
|
30
|
-
public_output_path = File.expand_path File.join(File.dirname(__FILE__), 'test_app/public/packs').to_s
|
31
|
-
assert_equal @config.public_output_path.to_s, public_output_path
|
32
|
-
|
33
|
-
@config = ViteRails::Configuration.new(
|
34
|
-
root_path: @config.root_path,
|
35
|
-
config_path: Pathname.new(File.expand_path('./test_app/config/vite_public_root.yml', __dir__)),
|
36
|
-
env: 'production',
|
37
|
-
)
|
38
|
-
|
39
|
-
public_output_path = File.expand_path File.join(File.dirname(__FILE__), 'public/packs').to_s
|
40
|
-
assert_equal @config.public_output_path.to_s, public_output_path
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_public_manifest_path
|
44
|
-
public_manifest_path = File.expand_path File.join(File.dirname(__FILE__), 'test_app/public/packs', 'manifest.json').to_s
|
45
|
-
assert_equal @config.public_manifest_path.to_s, public_manifest_path
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_cache_path
|
49
|
-
cache_path = File.expand_path File.join(File.dirname(__FILE__), 'test_app/tmp/cache/vite').to_s
|
50
|
-
assert_equal @config.cache_path.to_s, cache_path
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_additional_paths
|
54
|
-
assert_equal @config.additional_paths, ['app/assets', '/etc/yarn', 'some.config.js', 'app/elm']
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_cache_manifest?
|
58
|
-
assert @config.cache_manifest?
|
59
|
-
|
60
|
-
with_rails_env('development') do
|
61
|
-
refute ViteRails.config.cache_manifest?
|
62
|
-
end
|
63
|
-
|
64
|
-
with_rails_env('test') do
|
65
|
-
refute ViteRails.config.cache_manifest?
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_compile?
|
70
|
-
refute @config.compile?
|
71
|
-
|
72
|
-
with_rails_env('development') do
|
73
|
-
assert ViteRails.config.compile?
|
74
|
-
end
|
75
|
-
|
76
|
-
with_rails_env('test') do
|
77
|
-
assert ViteRails.config.compile?
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
@@ -1,83 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class DevServerRunnerTest < ViteRails::Test
|
6
|
-
def setup
|
7
|
-
@original_node_env, ENV['NODE_ENV'] = ENV['NODE_ENV'], 'development'
|
8
|
-
@original_rails_env, ENV['RAILS_ENV'] = ENV['RAILS_ENV'], 'development'
|
9
|
-
end
|
10
|
-
|
11
|
-
def teardown
|
12
|
-
ENV['NODE_ENV'] = @original_node_env
|
13
|
-
ENV['RAILS_ENV'] = @original_rails_env
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_run_cmd_via_node_modules
|
17
|
-
cmd = ["#{ test_app_path }/node_modules/.bin/vite", '--mode', 'development']
|
18
|
-
|
19
|
-
verify_command(cmd, use_node_modules: true)
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_run_cmd_via_yarn
|
23
|
-
cmd = ['yarn', 'vite', '--mode', 'development']
|
24
|
-
|
25
|
-
verify_command(cmd, use_node_modules: false)
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_run_cmd_argv
|
29
|
-
cmd = ["#{ test_app_path }/node_modules/.bin/vite", '--quiet', '--mode', 'development']
|
30
|
-
|
31
|
-
verify_command(cmd, argv: ['--quiet'])
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_run_cmd_argv_with_https
|
35
|
-
cmd = ["#{ test_app_path }/node_modules/.bin/vite", '--https', '--mode', 'development']
|
36
|
-
|
37
|
-
dev_server = ViteRails::DevServer.new({})
|
38
|
-
def dev_server.host
|
39
|
-
'localhost'
|
40
|
-
end
|
41
|
-
|
42
|
-
def dev_server.port
|
43
|
-
'3035'
|
44
|
-
end
|
45
|
-
|
46
|
-
def dev_server.pretty?
|
47
|
-
false
|
48
|
-
end
|
49
|
-
|
50
|
-
def dev_server.https?
|
51
|
-
true
|
52
|
-
end
|
53
|
-
ViteRails::DevServer.stub(:new, dev_server) do
|
54
|
-
verify_command(cmd, argv: ['--https'])
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
private
|
59
|
-
|
60
|
-
def test_app_path
|
61
|
-
File.expand_path('test_app', __dir__)
|
62
|
-
end
|
63
|
-
|
64
|
-
def verify_command(cmd, use_node_modules: true, argv: [])
|
65
|
-
cwd = Dir.pwd
|
66
|
-
Dir.chdir(test_app_path)
|
67
|
-
|
68
|
-
klass = ViteRails::Runner
|
69
|
-
instance = klass.new(argv)
|
70
|
-
mock = Minitest::Mock.new
|
71
|
-
mock.expect(:call, nil, [ViteRails.env, *cmd])
|
72
|
-
|
73
|
-
klass.stub(:new, instance) do
|
74
|
-
instance.stub(:executable_exists?, use_node_modules) do
|
75
|
-
Kernel.stub(:exec, mock) { ViteRails.run(argv) }
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
mock.verify
|
80
|
-
ensure
|
81
|
-
Dir.chdir(cwd)
|
82
|
-
end
|
83
|
-
end
|