vite_rails 1.0.12 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +39 -34
- data/lib/tasks/vite.rake +17 -0
- data/lib/vite_rails.rb +5 -82
- data/lib/vite_rails/config.rb +11 -135
- data/lib/vite_rails/engine.rb +7 -11
- data/lib/vite_rails/installation.rb +47 -0
- data/lib/vite_rails/tag_helpers.rb +61 -0
- data/lib/vite_rails/version.rb +2 -2
- data/{test/mounted_app/test/dummy/config/vite.json → templates/config/rails-vite.json} +1 -0
- data/{lib/install/javascript → templates}/entrypoints/application.js +0 -0
- metadata +25 -129
- data/lib/install/bin/vite +0 -17
- data/lib/install/binstubs.rb +0 -6
- data/lib/install/config/vite.config.ts +0 -8
- data/lib/install/config/vite.json +0 -14
- data/lib/install/template.rb +0 -40
- data/lib/tasks/vite/binstubs.rake +0 -12
- data/lib/tasks/vite/build.rake +0 -39
- data/lib/tasks/vite/clean.rake +0 -23
- data/lib/tasks/vite/clobber.rake +0 -20
- data/lib/tasks/vite/info.rake +0 -20
- data/lib/tasks/vite/install.rake +0 -12
- data/lib/tasks/vite/install_dependencies.rake +0 -14
- data/lib/tasks/vite/verify_install.rake +0 -23
- data/lib/vite_rails/builder.rb +0 -111
- data/lib/vite_rails/commands.rb +0 -109
- data/lib/vite_rails/dev_server.rb +0 -23
- data/lib/vite_rails/dev_server_proxy.rb +0 -57
- data/lib/vite_rails/helper.rb +0 -71
- data/lib/vite_rails/manifest.rb +0 -143
- data/lib/vite_rails/runner.rb +0 -53
- data/package.json +0 -19
- data/package/default.vite.json +0 -16
- data/test/builder_test.rb +0 -77
- data/test/commands_test.rb +0 -67
- data/test/config_test.rb +0 -133
- data/test/dev_server_proxy_test.rb +0 -102
- data/test/dev_server_test.rb +0 -9
- data/test/engine_rake_tasks_test.rb +0 -81
- data/test/helper_test.rb +0 -75
- data/test/manifest_test.rb +0 -85
- data/test/mode_test.rb +0 -16
- data/test/mounted_app/Rakefile +0 -6
- data/test/mounted_app/test/dummy/Rakefile +0 -5
- data/test/mounted_app/test/dummy/bin/rails +0 -5
- data/test/mounted_app/test/dummy/bin/rake +0 -5
- data/test/mounted_app/test/dummy/config.ru +0 -7
- data/test/mounted_app/test/dummy/config/application.rb +0 -12
- data/test/mounted_app/test/dummy/config/environment.rb +0 -5
- data/test/mounted_app/test/dummy/package.json +0 -8
- data/test/mounted_app/test/dummy/yarn.lock +0 -208
- data/test/rake_tasks_test.rb +0 -60
- data/test/runner_test.rb +0 -31
- data/test/test_app/Rakefile +0 -5
- data/test/test_app/app/frontend/entrypoints/application.js +0 -2
- data/test/test_app/bin/vite +0 -17
- data/test/test_app/config.ru +0 -7
- data/test/test_app/config/application.rb +0 -13
- data/test/test_app/config/environment.rb +0 -6
- data/test/test_app/config/vite.json +0 -18
- data/test/test_app/config/vite_additional_paths.json +0 -5
- data/test/test_app/config/vite_public_dir.json +0 -5
- data/test/test_app/package.json +0 -13
- data/test/test_app/public/vite-production/manifest-assets.json +0 -10
- data/test/test_app/public/vite-production/manifest.json +0 -39
- data/test/test_app/some.config.js +0 -0
- data/test/test_app/yarn.lock +0 -11
- data/test/test_helper.rb +0 -68
@@ -1,102 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class DevServerProxyTest < ViteRails::Test
|
6
|
-
include Rack::Test::Methods
|
7
|
-
|
8
|
-
def app
|
9
|
-
# Capture all changes to the env made by the proxy.
|
10
|
-
capture_app = Rack::Builder.new.run(->(env) {
|
11
|
-
[200, { 'Content-Type' => 'application/json' }, env.to_json]
|
12
|
-
})
|
13
|
-
# Avoid actually using the proxy.
|
14
|
-
Rack::Proxy.remove_method(:perform_request)
|
15
|
-
Rack::Proxy.define_method(:perform_request) { |env| capture_app.call(env) }
|
16
|
-
|
17
|
-
ViteRails::DevServerProxy.new(capture_app)
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_non_asset
|
21
|
-
get_with_dev_server_running '/'
|
22
|
-
assert_not_forwarded
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_non_vite_asset
|
26
|
-
get_with_dev_server_running '/example_import.js'
|
27
|
-
assert_not_forwarded
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_vite_asset
|
31
|
-
get_with_dev_server_running '/vite-production/application.js'
|
32
|
-
assert_forwarded to: '/application.js'
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_vite_client
|
36
|
-
get_with_dev_server_running '/@vite/client'
|
37
|
-
assert_forwarded to: '/@vite/client'
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_vite_import
|
41
|
-
get_with_dev_server_running '/@fs//package/example/app/frontend/App.vue?import&t=1611322300214&vue&type=style&index=0&lang.css'
|
42
|
-
assert_forwarded to: '/@fs//package/example/app/frontend/App.vue?import&t=1611322300214&vue&type=style&index=0&lang.css'
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_hmr_for_stylesheet
|
46
|
-
get_with_dev_server_running '/colored.css?t=1611322562923'
|
47
|
-
assert_forwarded to: '/colored.css?t=1611322562923'
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_hmr_for_imported_entrypoint
|
51
|
-
get_with_dev_server_running '/colored.css?import&t=1611322562923'
|
52
|
-
assert_forwarded to: '/colored.css?import&t=1611322562923'
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_entrypoint_imported_from_entrypoint
|
56
|
-
header 'Referer', 'http://localhost:3000/vite-production/application.js'
|
57
|
-
get_with_dev_server_running '/example_import.js'
|
58
|
-
assert_forwarded to: '/example_import.js'
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_without_dev_server_running
|
62
|
-
get '/vite-production/application.js'
|
63
|
-
assert_not_forwarded
|
64
|
-
|
65
|
-
get '/colored.css?import&t=1611322562923'
|
66
|
-
assert_not_forwarded
|
67
|
-
|
68
|
-
header 'Referer', 'http://localhost:3000/vite-production/application.js'
|
69
|
-
get '/example_import.js'
|
70
|
-
assert_not_forwarded
|
71
|
-
end
|
72
|
-
|
73
|
-
private
|
74
|
-
|
75
|
-
def get_with_dev_server_running(*args)
|
76
|
-
with_dev_server_running {
|
77
|
-
get(*args)
|
78
|
-
}
|
79
|
-
end
|
80
|
-
|
81
|
-
def assert_not_forwarded
|
82
|
-
assert last_response.ok?
|
83
|
-
env = JSON.parse(last_response.body)
|
84
|
-
assert_nil env['HTTP_X_FORWARDED_HOST']
|
85
|
-
assert_nil env['HTTP_X_FORWARDED_PORT']
|
86
|
-
end
|
87
|
-
|
88
|
-
def assert_forwarded(to: nil)
|
89
|
-
assert last_response.ok?
|
90
|
-
env = JSON.parse(last_response.body)
|
91
|
-
|
92
|
-
assert_equal ViteRails.config.host, env['HTTP_X_FORWARDED_HOST']
|
93
|
-
assert_equal ViteRails.config.port, Integer(env['HTTP_X_FORWARDED_PORT'])
|
94
|
-
|
95
|
-
return unless to
|
96
|
-
|
97
|
-
path, query = to.split('?')
|
98
|
-
assert_equal path, env['PATH_INFO']
|
99
|
-
assert_equal query.to_s, env['QUERY_STRING'].to_s
|
100
|
-
assert_equal to, env['REQUEST_URI']
|
101
|
-
end
|
102
|
-
end
|
data/test/dev_server_test.rb
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class EngineRakeTasksTest < Minitest::Test
|
6
|
-
def setup
|
7
|
-
remove_vite_files
|
8
|
-
end
|
9
|
-
|
10
|
-
def teardown
|
11
|
-
remove_vite_files
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_tasks_mounted
|
15
|
-
output = within_mounted_app { `bundle exec rake -T` }
|
16
|
-
assert_includes output, 'app:vite'
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_rake_tasks
|
20
|
-
within_mounted_app { `bundle exec rake app:vite:binstubs` }
|
21
|
-
assert vite_binstub_path.exist?
|
22
|
-
|
23
|
-
within_mounted_app { `bundle exec rake app:vite:install` }
|
24
|
-
assert vite_config_ts_path.exist?
|
25
|
-
assert app_frontend_dir.exist?
|
26
|
-
|
27
|
-
within_mounted_app { `bundle exec rake app:vite:build` }
|
28
|
-
assert app_public_dir.exist?
|
29
|
-
assert app_public_dir.join('manifest.json').exist?
|
30
|
-
assert app_public_dir.join('assets').exist?
|
31
|
-
|
32
|
-
within_mounted_app { `bundle exec rake app:vite:clean` }
|
33
|
-
assert app_public_dir.join('manifest.json').exist? # Still fresh
|
34
|
-
|
35
|
-
within_mounted_app { `bundle exec rake app:vite:clean[0,0]` }
|
36
|
-
refute app_public_dir.join('manifest.json').exist?
|
37
|
-
|
38
|
-
within_mounted_app { `bundle exec rake app:vite:clobber` }
|
39
|
-
refute app_public_dir.exist?
|
40
|
-
rescue Minitest::Assertion => error
|
41
|
-
raise error, [error.message, @command_results.join("\n\n")].join("\n")
|
42
|
-
end
|
43
|
-
|
44
|
-
private
|
45
|
-
|
46
|
-
def within_mounted_app
|
47
|
-
Dir.chdir(mounted_app_path) { yield }.tap { |result| @command_results << result }
|
48
|
-
end
|
49
|
-
|
50
|
-
def mounted_app_path
|
51
|
-
Pathname.new(File.expand_path(__dir__)).join('mounted_app')
|
52
|
-
end
|
53
|
-
|
54
|
-
def root_dir
|
55
|
-
mounted_app_path.join('test/dummy')
|
56
|
-
end
|
57
|
-
|
58
|
-
def vite_binstub_path
|
59
|
-
root_dir.join('bin/vite')
|
60
|
-
end
|
61
|
-
|
62
|
-
def vite_config_ts_path
|
63
|
-
root_dir.join('vite.config.ts')
|
64
|
-
end
|
65
|
-
|
66
|
-
def app_frontend_dir
|
67
|
-
root_dir.join('app/frontend')
|
68
|
-
end
|
69
|
-
|
70
|
-
def app_public_dir
|
71
|
-
root_dir.join('public/vite-dev')
|
72
|
-
end
|
73
|
-
|
74
|
-
def remove_vite_files
|
75
|
-
vite_binstub_path.delete if vite_binstub_path.exist?
|
76
|
-
vite_config_ts_path.delete if vite_config_ts_path.exist?
|
77
|
-
app_frontend_dir.rmtree if app_frontend_dir.exist?
|
78
|
-
app_public_dir.rmtree if app_public_dir.exist?
|
79
|
-
@command_results = []
|
80
|
-
end
|
81
|
-
end
|
data/test/helper_test.rb
DELETED
@@ -1,75 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class HelperTest < ActionView::TestCase
|
6
|
-
include ViteRailsTestHelpers
|
7
|
-
|
8
|
-
tests ViteRails::Helper
|
9
|
-
|
10
|
-
attr_reader :request
|
11
|
-
|
12
|
-
def setup
|
13
|
-
@request = Class.new do
|
14
|
-
def send_early_hints(links) end
|
15
|
-
|
16
|
-
def base_url
|
17
|
-
'https://example.com'
|
18
|
-
end
|
19
|
-
end.new
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_vite_client_tag
|
23
|
-
assert_nil vite_client_tag
|
24
|
-
with_dev_server_running {
|
25
|
-
assert_equal '<script src="/vite-production/@vite/client" type="module"></script>', vite_client_tag
|
26
|
-
}
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_vite_asset_path
|
30
|
-
assert_equal '/vite-production/assets/application.d9514acc.js', vite_asset_path('application.ts')
|
31
|
-
assert_equal '/vite-production/assets/styles.0e53e684.css', vite_asset_path('styles.css')
|
32
|
-
with_dev_server_running {
|
33
|
-
assert_equal '/vite-production/application.ts', vite_asset_path('application.ts')
|
34
|
-
assert_equal '/vite-production/styles.css', vite_asset_path('styles.css')
|
35
|
-
}
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_vite_stylesheet_tag
|
39
|
-
assert_equal link(href: '/vite-production/assets/styles.0e53e684.css'), vite_stylesheet_tag('styles')
|
40
|
-
|
41
|
-
assert_equal vite_stylesheet_tag('styles'), vite_stylesheet_tag('styles.css')
|
42
|
-
|
43
|
-
with_dev_server_running {
|
44
|
-
assert_equal link(href: '/vite-production/styles.css'), vite_stylesheet_tag('styles')
|
45
|
-
|
46
|
-
assert_equal vite_stylesheet_tag('styles'), vite_stylesheet_tag('styles.css')
|
47
|
-
}
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_vite_javascript_tag
|
51
|
-
assert_equal [
|
52
|
-
%(<script src="/vite-production/assets/application.d9514acc.js" crossorigin="anonymous" type="module"></script>),
|
53
|
-
%(<link rel="preload" href="/vite-production/assets/vendor.880705da.js" as="script" type="text/javascript" crossorigin="anonymous">),
|
54
|
-
%(<link rel="preload" href="/vite-production/assets/example_import.8e1fddc0.js" as="script" type="text/javascript" crossorigin="anonymous">),
|
55
|
-
link(href: '/vite-production/assets/application.f510c1e9.css'),
|
56
|
-
].join, vite_javascript_tag('application')
|
57
|
-
|
58
|
-
assert_equal vite_javascript_tag('application'), vite_javascript_tag('application.js')
|
59
|
-
assert_equal vite_javascript_tag('application'), vite_typescript_tag('application')
|
60
|
-
|
61
|
-
with_dev_server_running {
|
62
|
-
assert_equal %(<script src="/vite-production/application.js" crossorigin="anonymous" type="module"></script>),
|
63
|
-
vite_javascript_tag('application')
|
64
|
-
|
65
|
-
assert_equal %(<script src="/vite-production/application.ts" crossorigin="anonymous" type="module"></script>),
|
66
|
-
vite_typescript_tag('application')
|
67
|
-
}
|
68
|
-
end
|
69
|
-
|
70
|
-
def link(href:, rel: 'stylesheet', media: 'screen')
|
71
|
-
attrs = [%(media="#{ media }"), %(href="#{ href }")]
|
72
|
-
attrs.reverse! if Rails.gem_version > Gem::Version.new('6.1.1')
|
73
|
-
%(<link rel="#{ rel }" #{ attrs.join(' ') } />)
|
74
|
-
end
|
75
|
-
end
|
data/test/manifest_test.rb
DELETED
@@ -1,85 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class ManifestTest < ViteRails::Test
|
6
|
-
def test_lookup_exception!
|
7
|
-
asset_file = 'calendar.js'
|
8
|
-
|
9
|
-
error = assert_raises_manifest_missing_entry_error do
|
10
|
-
ViteRails.manifest.lookup!(asset_file)
|
11
|
-
end
|
12
|
-
|
13
|
-
assert_match "Vite Rails can't find #{ asset_file } in #{ manifest_path }", error.message
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_lookup_with_type_exception!
|
17
|
-
asset_file = 'calendar'
|
18
|
-
|
19
|
-
error = assert_raises_manifest_missing_entry_error do
|
20
|
-
ViteRails.manifest.lookup!(asset_file, type: :javascript)
|
21
|
-
end
|
22
|
-
|
23
|
-
assert_match "Vite Rails can't find #{ asset_file }.js in #{ manifest_path }", error.message
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_lookup_success!
|
27
|
-
entry = {
|
28
|
-
'file' => '/vite-production/assets/application.d9514acc.js',
|
29
|
-
'src' => 'application.js',
|
30
|
-
'isEntry' => true,
|
31
|
-
'imports' => [
|
32
|
-
{ 'file' => '/vite-production/assets/vendor.880705da.js' },
|
33
|
-
{ 'file' => '/vite-production/assets/example_import.8e1fddc0.js', 'src' => 'example_import.js', 'isEntry' => true },
|
34
|
-
],
|
35
|
-
'css' => [
|
36
|
-
'/vite-production/assets/application.f510c1e9.css',
|
37
|
-
],
|
38
|
-
}
|
39
|
-
assert_equal entry, ViteRails.manifest.lookup!('application.js', type: :javascript)
|
40
|
-
assert_equal entry.merge('src' => 'application.ts'), ViteRails.manifest.lookup!('application', type: :typescript)
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_lookup_success_with_dev_server_running!
|
44
|
-
entry = { 'file' => '/vite-production/application.js' }
|
45
|
-
with_dev_server_running {
|
46
|
-
assert_equal entry, ViteRails.manifest.lookup!('application.js')
|
47
|
-
}
|
48
|
-
entry = { 'file' => '/vite-production/application.ts' }
|
49
|
-
with_dev_server_running {
|
50
|
-
assert_equal entry, ViteRails.manifest.lookup!('application', type: :typescript)
|
51
|
-
}
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_lookup_nil
|
55
|
-
assert_nil ViteRails.manifest.lookup('foo.js')
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_lookup_success
|
59
|
-
entry = { 'file' => '/vite-production/assets/styles.0e53e684.css', 'src' => 'styles.css' }
|
60
|
-
assert_equal entry, ViteRails.manifest.lookup('styles.css')
|
61
|
-
assert_equal entry, ViteRails.manifest.lookup('styles.css', type: :stylesheet)
|
62
|
-
assert_equal entry, ViteRails.manifest.lookup('styles', type: :stylesheet)
|
63
|
-
end
|
64
|
-
|
65
|
-
def test_lookup_success_with_dev_server_running
|
66
|
-
entry = { 'file' => '/vite-production/styles.css' }
|
67
|
-
with_dev_server_running {
|
68
|
-
assert_equal entry, ViteRails.manifest.lookup('styles', type: :stylesheet)
|
69
|
-
}
|
70
|
-
end
|
71
|
-
|
72
|
-
private
|
73
|
-
|
74
|
-
def assert_raises_manifest_missing_entry_error(&block)
|
75
|
-
error = nil
|
76
|
-
ViteRails.config.stub :auto_build, false do
|
77
|
-
error = assert_raises ViteRails::Manifest::MissingEntryError, &block
|
78
|
-
end
|
79
|
-
error
|
80
|
-
end
|
81
|
-
|
82
|
-
def manifest_path
|
83
|
-
File.expand_path File.join(File.dirname(__FILE__), 'test_app/public/vite-production', 'manifest.json').to_s
|
84
|
-
end
|
85
|
-
end
|
data/test/mode_test.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class ModeTest < ViteRails::Test
|
6
|
-
def test_mode
|
7
|
-
assert_equal Rails.env, ViteRails.config.mode
|
8
|
-
assert_equal ViteRails.config.mode, ViteRails.mode
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_mode_with_rails_env
|
12
|
-
with_rails_env('staging') do |config|
|
13
|
-
assert_equal 'staging', config.mode
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
data/test/mounted_app/Rakefile
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'action_controller/railtie'
|
4
|
-
require 'action_view/railtie'
|
5
|
-
require 'vite_rails'
|
6
|
-
|
7
|
-
module TestDummyApp
|
8
|
-
class Application < Rails::Application
|
9
|
-
config.secret_key_base = 'abcdef'
|
10
|
-
config.eager_load = true
|
11
|
-
end
|
12
|
-
end
|