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.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +22 -0
  3. data/CONTRIBUTING.md +0 -1
  4. data/README.md +31 -69
  5. data/lib/install/javascript/entrypoints/application.js +8 -4
  6. data/lib/install/template.rb +1 -1
  7. data/lib/tasks/vite/build.rake +2 -6
  8. data/lib/tasks/vite/clean.rake +1 -3
  9. data/lib/tasks/vite/info.rake +0 -1
  10. data/lib/tasks/vite/verify_install.rake +3 -3
  11. data/lib/vite_rails.rb +14 -25
  12. data/lib/vite_rails/builder.rb +11 -13
  13. data/lib/vite_rails/commands.rb +51 -10
  14. data/lib/vite_rails/config.rb +65 -30
  15. data/lib/vite_rails/dev_server_proxy.rb +26 -18
  16. data/lib/vite_rails/helper.rb +15 -8
  17. data/lib/vite_rails/manifest.rb +6 -4
  18. data/lib/vite_rails/runner.rb +3 -6
  19. data/lib/vite_rails/version.rb +1 -1
  20. data/package.json +5 -1
  21. data/package/default.vite.json +2 -1
  22. data/test/builder_test.rb +27 -22
  23. data/test/commands_test.rb +67 -0
  24. data/test/config_test.rb +133 -0
  25. data/test/dev_server_proxy_test.rb +101 -0
  26. data/test/dev_server_test.rb +0 -30
  27. data/test/engine_rake_tasks_test.rb +55 -17
  28. data/test/helper_test.rb +37 -105
  29. data/test/manifest_test.rb +33 -29
  30. data/test/mode_test.rb +6 -11
  31. data/test/mounted_app/test/dummy/config/vite.json +5 -11
  32. data/test/mounted_app/test/dummy/package.json +2 -1
  33. data/test/mounted_app/test/dummy/yarn.lock +208 -0
  34. data/test/rake_tasks_test.rb +5 -19
  35. data/test/runner_test.rb +31 -0
  36. data/test/test_app/app/frontend/entrypoints/application.js +2 -0
  37. data/test/test_app/config/vite.json +0 -2
  38. data/test/test_app/config/vite_additional_paths.json +5 -0
  39. data/test/test_app/config/vite_public_dir.json +5 -0
  40. data/test/test_app/public/vite-production/manifest.json +22 -0
  41. data/test/test_helper.rb +48 -14
  42. metadata +23 -25
  43. data/test/command_test.rb +0 -35
  44. data/test/configuration_test.rb +0 -80
  45. data/test/dev_server_runner_test.rb +0 -83
  46. data/test/test_app/app/javascript/entrypoints/application.js +0 -10
  47. data/test/test_app/app/javascript/entrypoints/multi_entry.css +0 -4
  48. data/test/test_app/app/javascript/entrypoints/multi_entry.js +0 -4
  49. data/test/test_app/config/vite_public_root.yml +0 -20
  50. data/test/test_app/public/vite/manifest.json +0 -36
  51. data/test/vite_runner_test.rb +0 -59
  52. data/test/webpacker_test.rb +0 -15
@@ -1,16 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'json'
4
+
3
5
  # Public: Allows to resolve configuration sourced from `config/vite.json` and
4
6
  # environment variables, combining them with the default options.
5
7
  class ViteRails::Config
6
8
  delegate :as_json, :inspect, to: :@config
7
9
 
8
- def initialize(config)
9
- @config = config.tap { coerce_values(config) }.freeze
10
-
11
- config.each_key do |option|
12
- define_singleton_method(option) { @config[option] }
13
- end
10
+ def initialize(attrs)
11
+ @config = attrs.tap { |config| coerce_values(config) }.freeze
14
12
  end
15
13
 
16
14
  def protocol
@@ -28,7 +26,26 @@ class ViteRails::Config
28
26
 
29
27
  # Public: The directory where Vite will store the built assets.
30
28
  def build_output_dir
31
- public_dir.join(public_output_dir)
29
+ root.join(public_dir, public_output_dir)
30
+ end
31
+
32
+ # Public: The directory where the entries are located.
33
+ def resolved_entrypoints_dir
34
+ root.join(source_code_dir, entrypoints_dir)
35
+ end
36
+
37
+ # Internal: The directory where Vite stores its processing cache.
38
+ def vite_cache_dir
39
+ root.join('node_modules/.vite')
40
+ end
41
+
42
+ # Public: Sets additional environment variables for vite-plugin-ruby.
43
+ def to_env
44
+ CONFIGURABLE_WITH_ENV.each_with_object({}) do |option, env|
45
+ unless (value = @config[option]).nil?
46
+ env["#{ ViteRails::ENV_PREFIX }_#{ option.upcase }"] = value.to_s
47
+ end
48
+ end.merge(ViteRails.env)
32
49
  end
33
50
 
34
51
  private
@@ -36,10 +53,11 @@ private
36
53
  # Internal: Coerces all the configuration values, in case they were passed
37
54
  # as environment variables which are always strings.
38
55
  def coerce_values(config)
39
- coerce_booleans(config, 'auto_build', 'https')
40
- coerce_paths(config, 'assets_dir', 'build_cache_dir', 'config_path', 'public_dir', 'source_code_dir', 'public_output_dir', 'root')
56
+ config['mode'] = config['mode'].to_s
41
57
  config['port'] = config['port'].to_i
42
- config['root'] ||= Rails.root
58
+ coerce_paths(config, 'root', 'public_output_dir')
59
+ config['build_cache_dir'] = config['root'].join(config['build_cache_dir'])
60
+ coerce_booleans(config, 'auto_build', 'hide_build_console_output', 'https')
43
61
  end
44
62
 
45
63
  # Internal: Coerces configuration options to boolean.
@@ -54,51 +72,68 @@ private
54
72
 
55
73
  class << self
56
74
  # Public: Returns the project configuration for Vite.
57
- def resolve_config
58
- new DEFAULT_CONFIG.merge(config_from_file).merge(config_from_env)
59
- rescue Errno::ENOENT => error
60
- warn "Check that your vite.json configuration file is available in the load path. #{ error.message }"
61
- new DEFAULT_CONFIG.merge(config_from_env)
75
+ def resolve_config(attrs = {})
76
+ config = attrs.transform_keys(&:to_s).reverse_merge(config_defaults)
77
+ file_path = File.join(config['root'], config['config_path'])
78
+ file_config = config_from_file(file_path, mode: config['mode'])
79
+ new DEFAULT_CONFIG.merge(file_config).merge(config_from_env).merge(config)
62
80
  end
63
81
 
64
82
  private
65
83
 
84
+ # Internal: Default values for a Rails application.
85
+ def config_defaults
86
+ {
87
+ 'asset_host' => option_from_env('asset_host') || Rails.application&.config&.action_controller&.asset_host,
88
+ 'config_path' => option_from_env('config_path') || DEFAULT_CONFIG.fetch('config_path'),
89
+ 'mode' => option_from_env('mode') || Rails.env.to_s,
90
+ 'root' => option_from_env('root') || Rails.root || Dir.pwd,
91
+ }
92
+ end
93
+
66
94
  # Internal: Used to load a JSON file from the specified path.
67
95
  def load_json(path)
68
96
  JSON.parse(File.read(File.expand_path(path))).deep_transform_keys(&:underscore)
69
97
  end
70
98
 
71
99
  # Internal: Retrieves a configuration option from environment variables.
72
- def config_option_from_env(name)
73
- ENV["#{ ViteRails::ENV_PREFIX }_#{ name.upcase }"]
100
+ def option_from_env(name)
101
+ ViteRails.env["#{ ViteRails::ENV_PREFIX }_#{ name.upcase }"]
74
102
  end
75
103
 
76
104
  # Internal: Extracts the configuration options provided as env vars.
77
105
  def config_from_env
78
- CONFIGURABLE_WITH_ENV.each_with_object({}) do |key, env_vars|
79
- if value = config_option_from_env(key)
80
- env_vars[key] = value
106
+ CONFIGURABLE_WITH_ENV.each_with_object({}) do |option, env_vars|
107
+ if value = option_from_env(option)
108
+ env_vars[option] = value
81
109
  end
82
- end.merge(mode: vite_mode)
83
- end
84
-
85
- # Internal: The mode Vite should run on.
86
- def vite_mode
87
- config_option_from_env('mode') || Rails.env.to_s
110
+ end
88
111
  end
89
112
 
90
113
  # Internal: Loads the configuration options provided in a JSON file.
91
- def config_from_file
92
- path = config_option_from_env('config_path') || DEFAULT_CONFIG.fetch('config_path')
114
+ def config_from_file(path, mode:)
93
115
  multi_env_config = load_json(path)
94
116
  multi_env_config.fetch('all', {})
95
- .merge(multi_env_config.fetch(vite_mode, {}))
117
+ .merge(multi_env_config.fetch(mode, {}))
118
+ rescue Errno::ENOENT => error
119
+ warn "Check that your vite.json configuration file is available in the load path. #{ error.message }"
120
+ {}
96
121
  end
97
122
  end
98
123
 
99
124
  # Internal: Shared configuration with the Vite plugin for Ruby.
100
125
  DEFAULT_CONFIG = load_json("#{ __dir__ }/../../package/default.vite.json").freeze
101
126
 
127
+ # Internal: Configuration options that can not be provided as env vars.
128
+ NOT_CONFIGURABLE_WITH_ENV = %w[watch_additional_paths].freeze
129
+
102
130
  # Internal: Configuration options that can be provided as env vars.
103
- CONFIGURABLE_WITH_ENV = (DEFAULT_CONFIG.keys + ['root']).freeze
131
+ CONFIGURABLE_WITH_ENV = (DEFAULT_CONFIG.keys + %w[mode root] - NOT_CONFIGURABLE_WITH_ENV).freeze
132
+
133
+ public
134
+
135
+ # Define getters for the configuration options.
136
+ (CONFIGURABLE_WITH_ENV + NOT_CONFIGURABLE_WITH_ENV).each do |option|
137
+ define_method(option) { @config[option] }
138
+ end
104
139
  end
@@ -14,18 +14,8 @@ class ViteRails::DevServerProxy < Rack::Proxy
14
14
 
15
15
  # Rack: Intercept asset requests and send them to the Vite server.
16
16
  def perform_request(env)
17
- if vite_should_handle?(env['REQUEST_URI'], env['HTTP_REFERER']) && dev_server.running?
18
- env['REQUEST_URI'] = env['REQUEST_URI']
19
- .sub(vite_asset_url_prefix, '/')
20
- .sub('.ts.js', '.ts') # Patch: Rails helpers always append the extension.
21
- env['PATH_INFO'], env['QUERY_STRING'] = env['REQUEST_URI'].split('?')
22
-
23
- env['HTTP_HOST'] = env['HTTP_X_FORWARDED_HOST'] = config.host
24
- env['HTTP_X_FORWARDED_SERVER'] = config.host_with_port
25
- env['HTTP_PORT'] = env['HTTP_X_FORWARDED_PORT'] = config.port.to_s
26
- env['HTTP_X_FORWARDED_PROTO'] = env['HTTP_X_FORWARDED_SCHEME'] = config.protocol
27
- env['HTTPS'] = env['HTTP_X_FORWARDED_SSL'] = 'off' unless config.https
28
- env['SCRIPT_NAME'] = ''
17
+ if vite_should_handle?(env) && dev_server_running?
18
+ forward_to_vite_dev_server(env)
29
19
  super(env)
30
20
  else
31
21
  @app.call(env)
@@ -34,13 +24,31 @@ class ViteRails::DevServerProxy < Rack::Proxy
34
24
 
35
25
  private
36
26
 
37
- delegate :config, :dev_server, to: :@vite_rails
27
+ delegate :config, :dev_server_running?, to: :@vite_rails
38
28
 
39
- def vite_should_handle?(url, referer)
40
- return true if url.start_with?(vite_asset_url_prefix) # Vite Asset
41
- return true if url.start_with?(VITE_DEPENDENCY_PREFIX) # Vite Package Asset
42
- return true if url.include?('?t=') # Hot Reload
43
- return true if referer && URI.parse(referer).path.start_with?(vite_asset_url_prefix) # Entry Imported from another Entry.
29
+ def rewrite_uri_for_vite(env)
30
+ uri = env.fetch('REQUEST_URI') { [env['PATH_INFO'], env['QUERY_STRING']].reject(&:blank?).join('?') }
31
+ .sub(vite_asset_url_prefix, '/')
32
+ env['PATH_INFO'], env['QUERY_STRING'] = (env['REQUEST_URI'] = uri).split('?')
33
+ end
34
+
35
+ def forward_to_vite_dev_server(env)
36
+ rewrite_uri_for_vite(env)
37
+ env['HTTP_HOST'] = env['HTTP_X_FORWARDED_HOST'] = config.host
38
+ env['HTTP_X_FORWARDED_SERVER'] = config.host_with_port
39
+ env['HTTP_PORT'] = env['HTTP_X_FORWARDED_PORT'] = config.port.to_s
40
+ env['HTTP_X_FORWARDED_PROTO'] = env['HTTP_X_FORWARDED_SCHEME'] = config.protocol
41
+ env['HTTPS'] = env['HTTP_X_FORWARDED_SSL'] = 'off' unless config.https
42
+ env['SCRIPT_NAME'] = ''
43
+ end
44
+
45
+ def vite_should_handle?(env)
46
+ path, query, referer = env['PATH_INFO'], env['QUERY_STRING'], env['HTTP_REFERER']
47
+ return true if path.start_with?(vite_asset_url_prefix) # Vite asset
48
+ return true if path.start_with?(VITE_DEPENDENCY_PREFIX) # Packages and imports
49
+ return true if query&.start_with?('t=') # Hot Reload for a stylesheet
50
+ return true if query&.start_with?('import&') # Hot Reload for an imported entrypoint
51
+ return true if referer && URI.parse(referer).path.start_with?(vite_asset_url_prefix) # Entry imported from another entry.
44
52
  end
45
53
 
46
54
  def vite_asset_url_prefix
@@ -2,19 +2,24 @@
2
2
 
3
3
  # Public: Allows to render HTML tags for scripts and styles processed by Vite.
4
4
  module ViteRails::Helper
5
- DEFAULT_VITE_SKIP_PRELOAD_TAGS = Rails::VERSION::MAJOR <= 5 && Rails::VERSION::MINOR < 2
5
+ DEFAULT_VITE_SKIP_PRELOAD_TAGS = Rails.gem_version < Gem::Version.new('5.2.0')
6
6
 
7
7
  # Public: Returns the current Vite Rails instance.
8
8
  def current_vite_instance
9
9
  ViteRails.instance
10
10
  end
11
11
 
12
- # Public: Computes the relative path for the specified given Vite asset.
12
+ # Public: Renders a script tag for vite/client to enable HMR in development.
13
+ def vite_client_tag
14
+ content_tag('script', '', src: '/@vite/client', type: 'module') if ViteRails.dev_server_running?
15
+ end
16
+
17
+ # Public: Resolves the path for the specified Vite asset.
13
18
  #
14
19
  # Example:
15
20
  # <%= vite_asset_path 'calendar.css' %> # => "/vite/assets/calendar-1016838bab065ae1e122.css"
16
21
  def vite_asset_path(name, **options)
17
- current_vite_instance.manifest.lookup!(name, **options).fetch('file')
22
+ path_to_asset current_vite_instance.manifest.lookup!(name, **options).fetch('file')
18
23
  end
19
24
 
20
25
  # Public: Renders a <script> tag for the specified Vite entrypoints.
@@ -26,15 +31,17 @@ module ViteRails::Helper
26
31
  crossorigin: 'anonymous',
27
32
  **options)
28
33
  js_entries = names.map { |name| current_vite_instance.manifest.lookup!(name, type: asset_type) }
29
- js_tags = javascript_include_tag(*js_entries.map { |entry| entry['file'] }, type: type, crossorigin: crossorigin, **options)
34
+ js_tags = javascript_include_tag(*js_entries.map { |entry| entry['file'] }, crossorigin: crossorigin, type: type, **options)
30
35
 
31
- unless skip_preload_tags || ViteRails.dev_server.running?
36
+ unless skip_preload_tags || ViteRails.dev_server_running?
32
37
  preload_paths = js_entries.flat_map { |entry| entry['imports'] }.compact.uniq
33
38
  preload_tags = preload_paths.map { |path| preload_link_tag(path, crossorigin: crossorigin) }
34
39
  end
35
40
 
36
- unless skip_style_tags || ViteRails.dev_server.running?
37
- style_paths = names.map { |name| current_vite_instance.manifest.lookup(name, type: :stylesheet)&.fetch('file') }.compact
41
+ unless skip_style_tags || ViteRails.dev_server_running?
42
+ style_paths = names.map { |name|
43
+ current_vite_instance.manifest.lookup(name.delete_suffix('.js'), type: :stylesheet)&.fetch('file')
44
+ }.compact
38
45
  style_tags = stylesheet_link_tag(*style_paths)
39
46
  end
40
47
 
@@ -46,7 +53,7 @@ module ViteRails::Helper
46
53
  # NOTE: Because TypeScript is not a valid target in browsers, we only specify
47
54
  # the ts file when running the Vite development server.
48
55
  def vite_typescript_tag(*names, **options)
49
- vite_javascript_tag(*names, asset_type: :typescript, **options)
56
+ vite_javascript_tag(*names, asset_type: :typescript, extname: false, **options)
50
57
  end
51
58
 
52
59
  # Public: Renders a <link> tag for the specified Vite entrypoints.
@@ -31,7 +31,7 @@ class ViteRails::Manifest
31
31
  # Example:
32
32
  # ViteRails.manifest.lookup('calendar.js')
33
33
  # # { "file" => "/vite/assets/calendar-1016838bab065ae1e122.js", "imports" => [] }
34
- def lookup(name, type:)
34
+ def lookup(name, type: nil)
35
35
  build if should_build?
36
36
 
37
37
  find_manifest_entry(with_file_extension(name, type))
@@ -92,7 +92,8 @@ private
92
92
  def with_file_extension(name, entry_type)
93
93
  return name unless File.extname(name.to_s).empty?
94
94
 
95
- "#{ name }.#{ extension_for_type(entry_type) }"
95
+ extension = extension_for_type(entry_type)
96
+ extension ? "#{ name }.#{ extension }" : name
96
97
  end
97
98
 
98
99
  # Internal: Scopes the paths in the manifest to the output folder in public.
@@ -106,7 +107,7 @@ private
106
107
  when :javascript then 'js'
107
108
  when :stylesheet then 'css'
108
109
  when :typescript then dev_server_running? ? 'ts' : 'js'
109
- else entry_type.to_s
110
+ else entry_type
110
111
  end
111
112
  end
112
113
 
@@ -129,9 +130,10 @@ private
129
130
  [
130
131
  (dev_server_running? && 'Vite has not yet re-built your latest changes.'),
131
132
  (local && !dev_server_running? && "\"autoBuild\": false in your #{ config.mode } configuration."),
133
+ (local && !dev_server_running? && 'The Vite development server has crashed or is no longer available.'),
132
134
  'You have misconfigured config/vite.json file.',
133
135
  (!local && 'Assets have not been precompiled'),
134
- ].select(&:itself)
136
+ ].compact
135
137
  rescue StandardError
136
138
  []
137
139
  end
@@ -31,10 +31,9 @@ private
31
31
  cmd = vite_executable
32
32
  cmd.prepend('node', '--inspect-brk') if args.include?('--debug')
33
33
  cmd.prepend('node', '--trace-deprecation') if args.delete('--trace-deprecation')
34
- args.append('--mode', ENV['RAILS_ENV']) unless args.include?('--mode') || args.include?('-m')
34
+ args.append('--mode', ViteRails.mode) unless args.include?('--mode') || args.include?('-m')
35
35
  cmd += args
36
- puts cmd.join(' ')
37
- Dir.chdir(File.expand_path('.', Dir.pwd)) { Kernel.exec(ViteRails.env, *cmd) }
36
+ Dir.chdir(File.expand_path('.', Dir.pwd)) { Kernel.exec(ViteRails.config.to_env, *cmd) }
38
37
  end
39
38
 
40
39
  # Internal: Resolves to an executable for Vite.
@@ -49,8 +48,6 @@ private
49
48
 
50
49
  # Internal: Returns a path where a Vite executable should be found.
51
50
  def vite_bin_path
52
- ENV["#{ ViteRails::ENV_PREFIX }_VITE_BIN_PATH"] || `yarn bin vite`.chomp
53
- rescue StandardError
54
- "#{ `npm bin`.chomp }/vite"
51
+ ENV["#{ ViteRails::ENV_PREFIX }_VITE_BIN_PATH"] || `yarn bin vite`.chomp.presence || "#{ `npm bin`.chomp }/vite"
55
52
  end
56
53
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ViteRails
4
- VERSION = '1.0.5'
4
+ VERSION = '1.0.10'
5
5
  end
@@ -2,11 +2,15 @@
2
2
  "name": "only-for-workflows",
3
3
  "version": "unknown",
4
4
  "scripts": {
5
+ "docs": "npm -C docs run docs",
6
+ "docs:build": "npm -C docs run docs:build",
7
+ "docs:search": "npm -C docs run docs:search",
8
+ "docs:lint": "npm -C docs run lint",
5
9
  "lint": "npm -C package run lint",
6
10
  "test": "npm -C package run test"
7
11
  },
8
12
  "dependencies": {
9
13
  "vite": "^2.0.0-beta.34",
10
- "vite-plugin-ruby": "^1.0.1"
14
+ "vite-plugin-ruby": "^1.0.4"
11
15
  }
12
16
  }
@@ -1,4 +1,5 @@
1
1
  {
2
+ "assetHost": null,
2
3
  "assetsDir": "assets",
3
4
  "autoBuild": false,
4
5
  "buildCacheDir": "tmp/cache/vite",
@@ -6,7 +7,7 @@
6
7
  "configPath": "config/vite.json",
7
8
  "publicDir": "public",
8
9
  "entrypointsDir": "entrypoints",
9
- "sourceCodeDir": "app/javascript",
10
+ "sourceCodeDir": "app/frontend",
10
11
  "host": "localhost",
11
12
  "https": null,
12
13
  "port": 3036,
@@ -2,27 +2,26 @@
2
2
 
3
3
  require 'test_helper'
4
4
 
5
- class BuilderTest < Minitest::Test
6
- def remove_files_digest_path
5
+ class BuilderTest < ViteRails::Test
6
+ def setup
7
+ refresh_config
7
8
  ViteRails.builder.send(:files_digest_path).tap do |path|
8
9
  path.delete if path.exist?
9
10
  end
10
11
  end
11
12
 
12
- def setup
13
- remove_files_digest_path
13
+ def teardown
14
+ setup
14
15
  end
15
16
 
16
- def teardown
17
- remove_files_digest_path
17
+ def vite_env
18
+ ViteRails.config.to_env
18
19
  end
19
20
 
20
21
  def test_custom_environment_variables
21
- assert_nil ViteRails.builder.send(:vite_env)['FOO']
22
+ assert_nil vite_env['FOO']
22
23
  ViteRails.env['FOO'] = 'BAR'
23
- assert ViteRails.builder.send(:vite_env)['FOO'] == 'BAR'
24
- ensure
25
- ViteRails.env = {}
24
+ assert vite_env['FOO'] == 'BAR'
26
25
  end
27
26
 
28
27
  def test_freshness
@@ -35,21 +34,19 @@ class BuilderTest < Minitest::Test
35
34
  end
36
35
 
37
36
  def test_freshness_on_build_success
38
- status = OpenStruct.new(success?: true)
39
-
40
37
  assert ViteRails.builder.stale?
38
+ status = OpenStruct.new(success?: true)
41
39
  Open3.stub :capture3, [:sterr, :stdout, status] do
42
- ViteRails.builder.build
40
+ assert ViteRails.builder.build
43
41
  assert ViteRails.builder.fresh?
44
42
  end
45
43
  end
46
44
 
47
45
  def test_freshness_on_build_fail
48
- status = OpenStruct.new(success?: false)
49
-
50
46
  assert ViteRails.builder.stale?
47
+ status = OpenStruct.new(success?: false)
51
48
  Open3.stub :capture3, [:sterr, :stdout, status] do
52
- ViteRails.builder.build
49
+ assert !ViteRails.builder.build
53
50
  assert ViteRails.builder.fresh?
54
51
  end
55
52
  end
@@ -58,15 +55,23 @@ class BuilderTest < Minitest::Test
58
55
  assert_equal ViteRails.builder.send(:files_digest_path).basename.to_s, "last-compilation-digest-#{ ViteRails.config.mode }"
59
56
  end
60
57
 
58
+ def test_watched_files_digest
59
+ previous_digest = ViteRails.builder.send(:watched_files_digest)
60
+ refresh_config
61
+ assert_equal previous_digest, ViteRails.builder.send(:watched_files_digest)
62
+ end
63
+
61
64
  def test_external_env_variables
62
- ViteRails.env = {}
63
- assert_equal ViteRails.builder.send(:vite_env)['VITE_RUBY_MODE'], 'production'
64
- assert_equal ViteRails.builder.send(:vite_env)['VITE_RUBY_ROOT'], Rails.root.to_s
65
+ assert_equal 'production', vite_env['VITE_RUBY_MODE']
66
+ assert_equal Rails.root.to_s, vite_env['VITE_RUBY_ROOT']
65
67
 
66
68
  ENV['VITE_RUBY_MODE'] = 'foo.bar'
67
69
  ENV['VITE_RUBY_ROOT'] = '/baz'
68
-
69
- assert_equal ViteRails.builder.send(:vite_env)['VITE_RUBY_MODE'], 'foo.bar'
70
- assert_equal ViteRails.builder.send(:vite_env)['VITE_RUBY_ROOT'], '/baz'
70
+ refresh_config
71
+ assert_equal 'foo.bar', vite_env['VITE_RUBY_MODE']
72
+ assert_equal '/baz', vite_env['VITE_RUBY_ROOT']
73
+ ensure
74
+ ENV.delete('VITE_RUBY_MODE')
75
+ ENV.delete('VITE_RUBY_ROOT')
71
76
  end
72
77
  end