vite_rails 1.0.7 → 1.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -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, 'vite_rails'
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:check_binstubs 2>&1` }
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('test') do
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,14 +32,14 @@ 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('production') do
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
53
39
  end
54
40
 
55
- refute_includes installed_node_module_names, 'right-pad',
56
- 'Expected only production dependencies to be installed'
41
+ assert_includes installed_node_module_names, 'right-pad',
42
+ 'Expected development dependencies to be installed as well'
57
43
  end
58
44
 
59
45
  private
@@ -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,2 @@
1
+ /* eslint no-console:0 */
2
+ console.log('Hello World from ViteRails')
@@ -10,11 +10,9 @@
10
10
  "publicOutputDir": "vite-test"
11
11
  },
12
12
  "production": {
13
- "autoBuild": false,
14
13
  "publicOutputDir": "vite-production"
15
14
  },
16
15
  "staging": {
17
- "autoBuild": false,
18
16
  "publicOutputDir": "vite-staging"
19
17
  }
20
18
  }
@@ -0,0 +1,5 @@
1
+ {
2
+ "all": {
3
+ "watchAdditionalPaths": ["config/*"]
4
+ }
5
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "all": {
3
+ "publicDir": "../public"
4
+ }
5
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "logo.svg": {
3
+ "file": "assets/logo.490fa4f8.svg",
4
+ "src": "logo.svg"
5
+ },
6
+ "styles.css": {
7
+ "file": "assets/styles.0e53e684.css",
8
+ "src": "styles.css"
9
+ }
10
+ }
@@ -0,0 +1,39 @@
1
+ {
2
+ "application.js": {
3
+ "file": "assets/application.d9514acc.js",
4
+ "src": "application.js",
5
+ "isEntry": true,
6
+ "imports": [
7
+ "_vendor.880705da.js",
8
+ "example_import.js"
9
+ ],
10
+ "css": [
11
+ "assets/application.f510c1e9.css"
12
+ ]
13
+ },
14
+ "application.ts": {
15
+ "file": "assets/application.d9514acc.js",
16
+ "src": "application.ts",
17
+ "isEntry": true,
18
+ "imports": [
19
+ "_vendor.880705da.js",
20
+ "example_import.js"
21
+ ],
22
+ "css": [
23
+ "assets/application.f510c1e9.css"
24
+ ]
25
+ },
26
+ "example_import.js": {
27
+ "file": "assets/example_import.8e1fddc0.js",
28
+ "src": "example_import.js",
29
+ "isEntry": true
30
+ },
31
+ "logo.svg": {
32
+ "file": "assets/logo.f1745d22.js",
33
+ "src": "logo.svg",
34
+ "isEntry": true
35
+ },
36
+ "_vendor.880705da.js": {
37
+ "file": "assets/vendor.880705da.js"
38
+ }
39
+ }
@@ -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 = ::ViteRails.new
17
+ ViteRails.instance = ViteRails.new
13
18
 
14
- class ViteRails::Test < Minitest::Test
15
- private
16
-
17
- def reloaded_config
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
- reloaded_config
29
- yield
28
+ yield(refresh_config)
30
29
  ensure
31
30
  Rails.env = ActiveSupport::StringInquirer.new(original)
32
- reloaded_config
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.config.to_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.7
4
+ version: 1.0.12
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-29 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,30 @@ 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-assets.json
181
+ - test/test_app/public/vite-production/manifest.json
180
182
  - test/test_app/some.config.js
181
183
  - test/test_app/yarn.lock
182
184
  - test/test_helper.rb
183
- - test/vite_runner_test.rb
184
- - test/webpacker_test.rb
185
185
  homepage: https://github.com/ElMassimo/vite_rails
186
186
  licenses:
187
187
  - MIT
188
188
  metadata:
189
- source_code_uri: https://github.com/ElMassimo/vite_rails/tree/v1.0.7
190
- changelog_uri: https://github.com/ElMassimo/vite_rails/blob/v1.0.7/CHANGELOG.md
189
+ source_code_uri: https://github.com/ElMassimo/vite_rails/tree/v1.0.12
190
+ changelog_uri: https://github.com/ElMassimo/vite_rails/blob/v1.0.12/CHANGELOG.md
191
191
  post_install_message:
192
192
  rdoc_options: []
193
193
  require_paths:
@@ -196,7 +196,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
196
196
  requirements:
197
197
  - - ">="
198
198
  - !ruby/object:Gem::Version
199
- version: 2.4.0
199
+ version: 2.5.0
200
200
  required_rubygems_version: !ruby/object:Gem::Requirement
201
201
  requirements:
202
202
  - - ">="
@@ -209,9 +209,9 @@ specification_version: 4
209
209
  summary: Use Vite in Rails and bring joy to your JavaScript experience
210
210
  test_files:
211
211
  - test/builder_test.rb
212
- - test/command_test.rb
213
- - test/configuration_test.rb
214
- - test/dev_server_runner_test.rb
212
+ - test/commands_test.rb
213
+ - test/config_test.rb
214
+ - test/dev_server_proxy_test.rb
215
215
  - test/dev_server_test.rb
216
216
  - test/engine_rake_tasks_test.rb
217
217
  - test/helper_test.rb
@@ -226,21 +226,21 @@ test_files:
226
226
  - test/mounted_app/test/dummy/config/environment.rb
227
227
  - test/mounted_app/test/dummy/config/vite.json
228
228
  - test/mounted_app/test/dummy/package.json
229
+ - test/mounted_app/test/dummy/yarn.lock
229
230
  - test/rake_tasks_test.rb
231
+ - test/runner_test.rb
230
232
  - 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
233
+ - test/test_app/app/frontend/entrypoints/application.js
234
234
  - test/test_app/bin/vite
235
235
  - test/test_app/config.ru
236
236
  - test/test_app/config/application.rb
237
237
  - test/test_app/config/environment.rb
238
238
  - test/test_app/config/vite.json
239
- - test/test_app/config/vite_public_root.yml
239
+ - test/test_app/config/vite_additional_paths.json
240
+ - test/test_app/config/vite_public_dir.json
240
241
  - test/test_app/package.json
241
- - test/test_app/public/vite/manifest.json
242
+ - test/test_app/public/vite-production/manifest-assets.json
243
+ - test/test_app/public/vite-production/manifest.json
242
244
  - test/test_app/some.config.js
243
245
  - test/test_app/yarn.lock
244
246
  - 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