vite_rails 1.0.7 → 1.0.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +25 -0
  3. data/CONTRIBUTING.md +0 -1
  4. data/README.md +34 -8
  5. data/lib/install/config/vite.config.ts +0 -3
  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 +70 -35
  16. data/lib/vite_rails/dev_server_proxy.rb +26 -18
  17. data/lib/vite_rails/helper.rb +14 -10
  18. data/lib/vite_rails/manifest.rb +27 -22
  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 +40 -103
  30. data/test/manifest_test.rb +39 -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-assets.json +10 -0
  42. data/test/test_app/public/vite-production/manifest.json +39 -0
  43. data/test/test_helper.rb +48 -14
  44. metadata +25 -25
  45. data/test/command_test.rb +0 -35
  46. data/test/configuration_test.rb +0 -80
  47. data/test/dev_server_runner_test.rb +0 -83
  48. data/test/test_app/app/javascript/entrypoints/application.js +0 -10
  49. data/test/test_app/app/javascript/entrypoints/multi_entry.css +0 -4
  50. data/test/test_app/app/javascript/entrypoints/multi_entry.js +0 -4
  51. data/test/test_app/config/vite_public_root.yml +0 -20
  52. data/test/test_app/public/vite/manifest.json +0 -36
  53. data/test/vite_runner_test.rb +0 -59
  54. data/test/webpacker_test.rb +0 -15
@@ -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
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class ViteRailsTest < ViteRails::Test
6
- def test_config_params
7
- assert_equal Rails.env, ViteRails.config.mode
8
- assert_equal ViteRails.instance.root_path, ViteRails.config.root_path
9
- assert_equal ViteRails.instance.config_path, ViteRails.config.config_path
10
-
11
- with_rails_env('test') do
12
- assert_equal 'test', ViteRails.config.env
13
- end
14
- end
15
- end