vite_rails 1.0.0
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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +3 -0
- data/CONTRIBUTING.md +34 -0
- data/LICENSE.txt +21 -0
- data/README.md +64 -0
- data/lib/install/binstubs.rb +6 -0
- data/lib/install/template.rb +62 -0
- data/lib/vite_rails.rb +91 -0
- data/lib/vite_rails/builder.rb +113 -0
- data/lib/vite_rails/commands.rb +68 -0
- data/lib/vite_rails/config.rb +106 -0
- data/lib/vite_rails/dev_server.rb +23 -0
- data/lib/vite_rails/dev_server_proxy.rb +47 -0
- data/lib/vite_rails/engine.rb +40 -0
- data/lib/vite_rails/helper.rb +41 -0
- data/lib/vite_rails/manifest.rb +134 -0
- data/lib/vite_rails/runner.rb +56 -0
- data/lib/vite_rails/version.rb +5 -0
- data/package.json +28 -0
- data/package/default.vite.json +15 -0
- data/test/builder_test.rb +72 -0
- data/test/command_test.rb +35 -0
- data/test/configuration_test.rb +80 -0
- data/test/dev_server_runner_test.rb +83 -0
- data/test/dev_server_test.rb +39 -0
- data/test/engine_rake_tasks_test.rb +42 -0
- data/test/helper_test.rb +138 -0
- data/test/manifest_test.rb +75 -0
- data/test/mode_test.rb +21 -0
- data/test/mounted_app/Rakefile +6 -0
- data/test/mounted_app/test/dummy/Rakefile +5 -0
- data/test/mounted_app/test/dummy/bin/rails +5 -0
- data/test/mounted_app/test/dummy/bin/rake +5 -0
- data/test/mounted_app/test/dummy/config.ru +7 -0
- data/test/mounted_app/test/dummy/config/application.rb +12 -0
- data/test/mounted_app/test/dummy/config/environment.rb +5 -0
- data/test/mounted_app/test/dummy/config/vite.json +20 -0
- data/test/mounted_app/test/dummy/package.json +7 -0
- data/test/rake_tasks_test.rb +74 -0
- data/test/test_app/Rakefile +5 -0
- data/test/test_app/app/javascript/entrypoints/application.js +10 -0
- data/test/test_app/app/javascript/entrypoints/multi_entry.css +4 -0
- data/test/test_app/app/javascript/entrypoints/multi_entry.js +4 -0
- data/test/test_app/bin/vite +17 -0
- data/test/test_app/config.ru +7 -0
- data/test/test_app/config/application.rb +13 -0
- data/test/test_app/config/environment.rb +6 -0
- data/test/test_app/config/vite.json +20 -0
- data/test/test_app/config/vite_public_root.yml +20 -0
- data/test/test_app/package.json +13 -0
- data/test/test_app/public/vite/manifest.json +36 -0
- data/test/test_app/some.config.js +0 -0
- data/test/test_app/yarn.lock +11 -0
- data/test/test_helper.rb +34 -0
- data/test/vite_runner_test.rb +59 -0
- data/test/webpacker_test.rb +15 -0
- metadata +234 -0
@@ -0,0 +1,75 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class ManifestTest < Minitest::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 "ViteRails 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 "ViteRails can't find #{ asset_file }.js in #{ manifest_path }", error.message
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_lookup_success!
|
27
|
+
assert_equal ViteRails.manifest.lookup!('bootstrap.js'), '/packs/bootstrap-300631c4f0e0f9c865bc.js'
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_lookup_nil
|
31
|
+
assert_nil ViteRails.manifest.lookup('foo.js')
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_lookup_chunks_nil
|
35
|
+
assert_nil ViteRails.manifest.lookup_pack_with_chunks('foo.js')
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_lookup_success
|
39
|
+
assert_equal ViteRails.manifest.lookup('bootstrap.js'), '/packs/bootstrap-300631c4f0e0f9c865bc.js'
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_lookup_entrypoint_exception!
|
43
|
+
asset_file = 'calendar'
|
44
|
+
|
45
|
+
error = assert_raises_manifest_missing_entry_error do
|
46
|
+
ViteRails.manifest.lookup_pack_with_chunks!(asset_file, type: :javascript)
|
47
|
+
end
|
48
|
+
|
49
|
+
assert_match "ViteRails can't find #{ asset_file }.js in #{ manifest_path }", error.message
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_lookup_entrypoint
|
53
|
+
application_entrypoints = [
|
54
|
+
'/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js',
|
55
|
+
'/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js',
|
56
|
+
'/packs/application-k344a6d59eef8632c9d1.js',
|
57
|
+
]
|
58
|
+
|
59
|
+
assert_equal ViteRails.manifest.lookup_pack_with_chunks!('application', type: :javascript), application_entrypoints
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def assert_raises_manifest_missing_entry_error(&block)
|
65
|
+
error = nil
|
66
|
+
ViteRails.config.stub :compile?, false do
|
67
|
+
error = assert_raises ViteRails::Manifest::MissingEntryError, &block
|
68
|
+
end
|
69
|
+
error
|
70
|
+
end
|
71
|
+
|
72
|
+
def manifest_path
|
73
|
+
File.expand_path File.join(File.dirname(__FILE__), 'test_app/public/packs', 'manifest.json').to_s
|
74
|
+
end
|
75
|
+
end
|
data/test/mode_test.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class ModeTest < ViteRails::Test
|
6
|
+
def test_current
|
7
|
+
assert_equal ViteRails.config.mode, Rails.env
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_custom_without_config
|
11
|
+
with_rails_env('foo') do
|
12
|
+
assert_equal ViteRails.config.mode, 'production'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_custom_with_config
|
17
|
+
with_rails_env('staging') do
|
18
|
+
assert_equal ViteRails.config.mode, 'staging'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,12 @@
|
|
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
|
@@ -0,0 +1,20 @@
|
|
1
|
+
{
|
2
|
+
"development": {
|
3
|
+
"autoBuild": true,
|
4
|
+
"port": "3535",
|
5
|
+
"https": true,
|
6
|
+
"publicOutputDir": "vite-development"
|
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
|
+
}
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class RakeTasksTest < Minitest::Test
|
6
|
+
def test_rake_tasks
|
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'
|
12
|
+
assert_includes output, 'vite:clean'
|
13
|
+
assert_includes output, 'vite:clobber'
|
14
|
+
assert_includes output, 'vite:compile'
|
15
|
+
assert_includes output, 'vite:install'
|
16
|
+
assert_includes output, 'vite:verify_install'
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_rake_task_vite_check_binstubs
|
20
|
+
output = Dir.chdir(test_app_path) { `rake vite:check_binstubs 2>&1` }
|
21
|
+
refute_includes output, 'vite binstub not found.'
|
22
|
+
end
|
23
|
+
|
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
|
+
def test_rake_vite_install_dependencies_in_non_production_environments
|
36
|
+
assert_includes test_app_dev_dependencies, 'right-pad'
|
37
|
+
|
38
|
+
ViteRails.with_node_env('test') do
|
39
|
+
Dir.chdir(test_app_path) do
|
40
|
+
`bundle exec rake vite:install_dependencies`
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
assert_includes installed_node_module_names, 'right-pad',
|
45
|
+
'Expected dev dependencies to be installed'
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_rake_vite_install_dependencies_in_production_environment
|
49
|
+
ViteRails.with_node_env('production') do
|
50
|
+
Dir.chdir(test_app_path) do
|
51
|
+
`bundle exec rake vite:install_dependencies`
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
refute_includes installed_node_module_names, 'right-pad',
|
56
|
+
'Expected only production dependencies to be installed'
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def test_app_path
|
62
|
+
File.expand_path('test_app', __dir__)
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_app_dev_dependencies
|
66
|
+
package_json = File.expand_path('package.json', test_app_path)
|
67
|
+
JSON.parse(File.read(package_json))['devDependencies']
|
68
|
+
end
|
69
|
+
|
70
|
+
def installed_node_module_names
|
71
|
+
node_modules_path = File.expand_path('node_modules', test_app_path)
|
72
|
+
Dir.chdir(node_modules_path) { Dir.glob('*') }
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,10 @@
|
|
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')
|
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
ENV['RAILS_ENV'] ||= ENV['RACK_ENV'] || 'development'
|
5
|
+
ENV['NODE_ENV'] ||= ENV['RAILS_ENV'] == 'development' ? 'development' : 'production'
|
6
|
+
|
7
|
+
require 'pathname'
|
8
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', Pathname.new(__FILE__).realpath)
|
9
|
+
|
10
|
+
require 'bundler/setup'
|
11
|
+
|
12
|
+
require 'vite_rails'
|
13
|
+
|
14
|
+
APP_ROOT = File.expand_path('..', __dir__)
|
15
|
+
Dir.chdir(APP_ROOT) do
|
16
|
+
ViteRails.run(ARGV)
|
17
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'action_controller/railtie'
|
4
|
+
require 'action_view/railtie'
|
5
|
+
require 'vite_rails'
|
6
|
+
|
7
|
+
module TestApp
|
8
|
+
class Application < ::Rails::Application
|
9
|
+
config.secret_key_base = 'abcdef'
|
10
|
+
config.eager_load = true
|
11
|
+
config.active_support.test_order = :sorted
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
{
|
2
|
+
"development": {
|
3
|
+
"autoBuild": true,
|
4
|
+
"port": "3535",
|
5
|
+
"https": true,
|
6
|
+
"publicOutputDir": "vite-development"
|
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
|
+
}
|
@@ -0,0 +1,20 @@
|
|
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
|
+
}
|
@@ -0,0 +1,36 @@
|
|
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
|
+
}
|
File without changes
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
2
|
+
# yarn lockfile v1
|
3
|
+
|
4
|
+
|
5
|
+
left-pad@^1.2.0:
|
6
|
+
version "1.2.0"
|
7
|
+
resolved "https://registry.yarnpkg.com/left-pad/-/left-pad-1.2.0.tgz#d30a73c6b8201d8f7d8e7956ba9616087a68e0ee"
|
8
|
+
|
9
|
+
right-pad@^1.0.1:
|
10
|
+
version "1.0.1"
|
11
|
+
resolved "https://registry.yarnpkg.com/right-pad/-/right-pad-1.0.1.tgz#8ca08c2cbb5b55e74dafa96bf7fd1a27d568c8d0"
|