vite_rails 1.0.4 → 1.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +26 -1
- data/CONTRIBUTING.md +0 -1
- data/README.md +27 -65
- 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 +19 -25
- data/lib/vite_rails/builder.rb +11 -4
- data/lib/vite_rails/commands.rb +50 -10
- data/lib/vite_rails/config.rb +35 -23
- data/lib/vite_rails/dev_server_proxy.rb +27 -16
- data/lib/vite_rails/helper.rb +36 -8
- data/lib/vite_rails/manifest.rb +20 -15
- data/lib/vite_rails/runner.rb +2 -5
- data/lib/vite_rails/version.rb +1 -1
- data/package.json +8 -20
- data/package/default.vite.json +1 -1
- data/test/builder_test.rb +27 -22
- data/test/commands_test.rb +67 -0
- data/test/configuration_test.rb +88 -46
- 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 +21 -23
- data/test/command_test.rb +0 -35
- 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
data/test/rake_tasks_test.rb
CHANGED
@@ -5,37 +5,23 @@ require 'test_helper'
|
|
5
5
|
class RakeTasksTest < Minitest::Test
|
6
6
|
def test_rake_tasks
|
7
7
|
output = Dir.chdir(test_app_path) { `rake -T` }
|
8
|
-
assert_includes output, '
|
9
|
-
assert_includes output, 'vite:check_binstubs'
|
10
|
-
assert_includes output, 'vite:check_node'
|
11
|
-
assert_includes output, 'vite:check_yarn'
|
8
|
+
assert_includes output, 'vite:build'
|
12
9
|
assert_includes output, 'vite:clean'
|
13
10
|
assert_includes output, 'vite:clobber'
|
14
|
-
assert_includes output, 'vite:compile'
|
15
11
|
assert_includes output, 'vite:install'
|
12
|
+
assert_includes output, 'vite:install_dependencies'
|
16
13
|
assert_includes output, 'vite:verify_install'
|
17
14
|
end
|
18
15
|
|
19
16
|
def test_rake_task_vite_check_binstubs
|
20
|
-
output = Dir.chdir(test_app_path) { `rake vite:
|
17
|
+
output = Dir.chdir(test_app_path) { `rake vite:verify_install 2>&1` }
|
21
18
|
refute_includes output, 'vite binstub not found.'
|
22
19
|
end
|
23
20
|
|
24
|
-
def test_check_node_version
|
25
|
-
output = Dir.chdir(test_app_path) { `rake vite:check_node 2>&1` }
|
26
|
-
refute_includes output, 'ViteRails requires Node.js'
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_check_yarn_version
|
30
|
-
output = Dir.chdir(test_app_path) { `rake vite:check_yarn 2>&1` }
|
31
|
-
refute_includes output, 'Yarn not installed'
|
32
|
-
refute_includes output, 'ViteRails requires Yarn'
|
33
|
-
end
|
34
|
-
|
35
21
|
def test_rake_vite_install_dependencies_in_non_production_environments
|
36
22
|
assert_includes test_app_dev_dependencies, 'right-pad'
|
37
23
|
|
38
|
-
ViteRails.with_node_env
|
24
|
+
ViteRails.commands.send(:with_node_env, 'test') do
|
39
25
|
Dir.chdir(test_app_path) do
|
40
26
|
`bundle exec rake vite:install_dependencies`
|
41
27
|
end
|
@@ -46,7 +32,7 @@ class RakeTasksTest < Minitest::Test
|
|
46
32
|
end
|
47
33
|
|
48
34
|
def test_rake_vite_install_dependencies_in_production_environment
|
49
|
-
ViteRails.with_node_env
|
35
|
+
ViteRails.commands.send(:with_node_env, 'production') do
|
50
36
|
Dir.chdir(test_app_path) do
|
51
37
|
`bundle exec rake vite:install_dependencies`
|
52
38
|
end
|
data/test/runner_test.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class RunnerTest < ViteRails::Test
|
6
|
+
def test_dev_server_command
|
7
|
+
assert_run_command(flags: ['--mode', 'production'])
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_dev_server_command_via_yarn
|
11
|
+
assert_run_command(flags: ['--mode', 'production'], use_yarn: true)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_dev_server_command_with_argument
|
15
|
+
assert_run_command('--quiet', flags: ['--mode', 'production'])
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_build_command
|
19
|
+
assert_run_command('build', flags: ['--mode', 'production'])
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_build_command_via_yarn
|
23
|
+
assert_run_command('build', flags: ['--mode', 'production'], use_yarn: true)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_build_command_with_argument
|
27
|
+
with_rails_env('development') do
|
28
|
+
assert_run_command('build', '--emptyOutDir', flags: ['--mode', 'development'])
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -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.9
|
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-22 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/
|
150
|
+
- test/commands_test.rb
|
151
151
|
- test/configuration_test.rb
|
152
|
-
- test/
|
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.9
|
189
|
+
changelog_uri: https://github.com/ElMassimo/vite_rails/blob/v1.0.9/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/
|
211
|
+
- test/commands_test.rb
|
213
212
|
- test/configuration_test.rb
|
214
|
-
- test/
|
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
|
@@ -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
|