vite_rails 1.0.6 → 1.0.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +24 -0
  3. data/CONTRIBUTING.md +0 -1
  4. data/README.md +43 -70
  5. data/lib/install/config/vite.config.ts +1 -1
  6. data/lib/install/javascript/entrypoints/application.js +8 -4
  7. data/lib/install/template.rb +3 -3
  8. data/lib/tasks/vite/build.rake +12 -6
  9. data/lib/tasks/vite/clean.rake +1 -3
  10. data/lib/tasks/vite/install_dependencies.rake +3 -9
  11. data/lib/tasks/vite/verify_install.rake +3 -3
  12. data/lib/vite_rails.rb +23 -34
  13. data/lib/vite_rails/builder.rb +11 -13
  14. data/lib/vite_rails/commands.rb +51 -10
  15. data/lib/vite_rails/config.rb +65 -35
  16. data/lib/vite_rails/dev_server_proxy.rb +26 -18
  17. data/lib/vite_rails/helper.rb +17 -8
  18. data/lib/vite_rails/manifest.rb +14 -12
  19. data/lib/vite_rails/runner.rb +3 -6
  20. data/lib/vite_rails/version.rb +1 -1
  21. data/package.json +9 -2
  22. data/package/default.vite.json +2 -1
  23. data/test/builder_test.rb +27 -22
  24. data/test/commands_test.rb +67 -0
  25. data/test/config_test.rb +133 -0
  26. data/test/dev_server_proxy_test.rb +102 -0
  27. data/test/dev_server_test.rb +0 -30
  28. data/test/engine_rake_tasks_test.rb +56 -17
  29. data/test/helper_test.rb +37 -105
  30. data/test/manifest_test.rb +33 -29
  31. data/test/mode_test.rb +6 -11
  32. data/test/mounted_app/test/dummy/config/vite.json +5 -11
  33. data/test/mounted_app/test/dummy/package.json +5 -4
  34. data/test/mounted_app/test/dummy/yarn.lock +208 -0
  35. data/test/rake_tasks_test.rb +7 -21
  36. data/test/runner_test.rb +31 -0
  37. data/test/test_app/app/frontend/entrypoints/application.js +2 -0
  38. data/test/test_app/config/vite.json +0 -2
  39. data/test/test_app/config/vite_additional_paths.json +5 -0
  40. data/test/test_app/config/vite_public_dir.json +5 -0
  41. data/test/test_app/public/vite-production/manifest.json +22 -0
  42. data/test/test_helper.rb +48 -14
  43. metadata +23 -25
  44. data/test/command_test.rb +0 -35
  45. data/test/configuration_test.rb +0 -80
  46. data/test/dev_server_runner_test.rb +0 -83
  47. data/test/test_app/app/javascript/entrypoints/application.js +0 -10
  48. data/test/test_app/app/javascript/entrypoints/multi_entry.css +0 -4
  49. data/test/test_app/app/javascript/entrypoints/multi_entry.js +0 -4
  50. data/test/test_app/config/vite_public_root.yml +0 -20
  51. data/test/test_app/public/vite/manifest.json +0 -36
  52. data/test/vite_runner_test.rb +0 -59
  53. data/test/webpacker_test.rb +0 -15
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.6
4
+ version: 1.0.11
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-20 00:00:00.000000000 Z
11
+ date: 2021-01-24 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/command_test.rb
151
- - test/configuration_test.rb
152
- - test/dev_server_runner_test.rb
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/javascript/entrypoints/application.js
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/vite_public_root.yml
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.6
190
- changelog_uri: https://github.com/ElMassimo/vite_rails/blob/v1.0.6/CHANGELOG.md
188
+ source_code_uri: https://github.com/ElMassimo/vite_rails/tree/v1.0.11
189
+ changelog_uri: https://github.com/ElMassimo/vite_rails/blob/v1.0.11/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.4.0
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/command_test.rb
213
- - test/configuration_test.rb
214
- - test/dev_server_runner_test.rb
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/javascript/entrypoints/application.js
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/vite_public_root.yml
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
@@ -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,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
@@ -1,10 +0,0 @@
1
- /* eslint no-console:0 */
2
- // This file is automatically compiled by Vite, along with any other files
3
- // present in this directory. You're encouraged to place your actual application logic in
4
- // a relevant structure within app/javascript and only use these pack files to reference
5
- // that code so it'll be compiled.
6
- //
7
- // To reference this file, add <%= javascript_pack_tag 'application' %> to the appropriate
8
- // layout file, like app/views/layouts/application.html.erb
9
-
10
- console.log('Hello World from ViteRails')
@@ -1,4 +0,0 @@
1
- /*
2
- * Dummy file #1 for Multi File Entry points: https://vite.js.org/guides/entry-advanced/
3
- * This file must be named the same
4
- */
@@ -1,4 +0,0 @@
1
- /*
2
- * Dummy file #2 for Multi File Entry points: https://vite.js.org/guides/entry-advanced/
3
- * This file must be named the same
4
- */
@@ -1,20 +0,0 @@
1
- {
2
- "development": {
3
- "autoBuild": true,
4
- "port": "3535",
5
- "https": true,
6
- "publicDir": "../public"
7
- },
8
- "test": {
9
- "autoBuild": true,
10
- "publicOutputDir": "vite-test"
11
- },
12
- "production": {
13
- "autoBuild": false,
14
- "publicOutputDir": "vite-production"
15
- },
16
- "staging": {
17
- "autoBuild": false,
18
- "publicOutputDir": "vite-staging"
19
- }
20
- }
@@ -1,36 +0,0 @@
1
- {
2
- "bootstrap.css": "/packs/bootstrap-c38deda30895059837cf.css",
3
- "application.css": "/packs/application-dd6b1cd38bfa093df600.css",
4
- "bootstrap.js": "/packs/bootstrap-300631c4f0e0f9c865bc.js",
5
- "application.js": "/packs/application-k344a6d59eef8632c9d1.js",
6
- "application.png": "/packs/application-k344a6d59eef8632c9d1.png",
7
- "fonts/fa-regular-400.woff2": "/packs/fonts/fa-regular-400-944fb546bd7018b07190a32244f67dc9.woff2",
8
- "media/images/image.jpg": "/packs/media/images/image-c38deda30895059837cf.jpg",
9
- "media/images/image-2x.jpg": "/packs/media/images/image-2x-7cca48e6cae66ec07b8e.jpg",
10
- "media/images/nested/image.jpg": "/packs/media/images/nested/image-c38deda30895059837cf.jpg",
11
- "media/images/mb-icon.png": "/packs/media/images/mb-icon-c38deda30895059837cf.png",
12
- "media/images/nested/mb-icon.png": "/packs/media/images/nested/mb-icon-c38deda30895059837cf.png",
13
- "entrypoints": {
14
- "application": {
15
- "assets": {
16
- "js": [
17
- "/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js",
18
- "/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js",
19
- "/packs/application-k344a6d59eef8632c9d1.js"
20
- ],
21
- "css": [
22
- "/packs/1-c20632e7baf2c81200d3.chunk.css",
23
- "/packs/application-k344a6d59eef8632c9d1.chunk.css"
24
- ]
25
- }
26
- },
27
- "hello_stimulus": {
28
- "assets": {
29
- "css": [
30
- "/packs/1-c20632e7baf2c81200d3.chunk.css",
31
- "/packs/hello_stimulus-k344a6d59eef8632c9d1.chunk.css"
32
- ]
33
- }
34
- }
35
- }
36
- }
@@ -1,59 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class ViteRunnerTest < 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", 'build', '--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', 'build', '--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", 'build', '--mode', 'development', '--emptyOutDir']
30
-
31
- verify_command(cmd, argv: ['--emptyOutDir'])
32
- end
33
-
34
- private
35
-
36
- def test_app_path
37
- File.expand_path('test_app', __dir__)
38
- end
39
-
40
- def verify_command(cmd, use_node_modules: true, argv: [])
41
- cwd = Dir.pwd
42
- Dir.chdir(test_app_path)
43
-
44
- klass = ViteRails::ViteRunner
45
- instance = klass.new(argv)
46
- mock = Minitest::Mock.new
47
- mock.expect(:call, nil, [ViteRails::Compiler.env, *cmd])
48
-
49
- klass.stub(:new, instance) do
50
- instance.stub(:executable_exists?, use_node_modules) do
51
- Kernel.stub(:exec, mock) { klass.run(argv) }
52
- end
53
- end
54
-
55
- mock.verify
56
- ensure
57
- Dir.chdir(cwd)
58
- end
59
- end