From 9a1d75ad7cf7f730afd47214f5cb9b42518db440 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1ximo=20Mussini?= Date: Sun, 24 Jan 2021 16:36:13 -0300 Subject: [PATCH] Fix bug in assetHost which defaulted to null and update after changes to base in beta.38 (#7) Closes #6 --- docs/config/index.md | 2 +- examples/blog/Gemfile | 2 +- examples/blog/Gemfile.lock | 16 ++++++++----- .../app/frontend/entrypoints/application.js | 2 +- examples/blog/config/initializers/assets.rb | 2 +- examples/blog/package.json | 13 +++++----- examples/blog/vite.config.ts | 2 +- examples/blog/yarn.lock | 24 +++++++++---------- lib/install/config/vite.config.ts | 2 +- lib/install/template.rb | 4 ++-- lib/tasks/vite/build.rake | 12 +++++++++- lib/tasks/vite/install_dependencies.rake | 12 +++------- lib/vite_rails.rb | 20 ++++++++-------- lib/vite_rails/config.rb | 9 ++----- lib/vite_rails/helper.rb | 8 ++++--- lib/vite_rails/manifest.rb | 16 ++++++------- package.json | 3 ++- package/README.md | 3 --- .../app/frontend/components/HelloWorld.vue | 2 +- package/example/package.json | 2 +- package/example/vite.config.ts | 2 +- package/package.json | 4 ++-- package/pnpm-lock.yaml | 20 ++++++++++------ package/src/config.ts | 4 ++-- package/src/index.ts | 2 +- test/config_test.rb | 2 +- test/dev_server_proxy_test.rb | 1 + test/engine_rake_tasks_test.rb | 5 ++-- test/helper_test.rb | 2 +- test/mounted_app/test/dummy/package.json | 8 +++---- test/mounted_app/test/dummy/yarn.lock | 12 +++++----- test/rake_tasks_test.rb | 4 ++-- 32 files changed, 116 insertions(+), 106 deletions(-) diff --git a/docs/config/index.md b/docs/config/index.md index f8460f82..ac17b172 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -33,7 +33,7 @@ export default defineConfig({ RubyPlugin(), ], optimizeDeps: { - exclude: [/webpack/, /vite-plugin-ruby/], + exclude: [/webpack/], // In case webpacker is installed (these deps won't be imported) }, }) ``` diff --git a/examples/blog/Gemfile b/examples/blog/Gemfile index 21311b07..fc98f028 100644 --- a/examples/blog/Gemfile +++ b/examples/blog/Gemfile @@ -23,7 +23,7 @@ gem 'jbuilder', '~> 2.7' # Use Active Model has_secure_password # gem 'bcrypt', '~> 3.1.7' -gem 'vite_rails', '1.0.10' # path: '../..' +gem 'vite_rails', path: '../..'#, '1.0.10' # Use Active Storage variant # gem 'image_processing', '~> 1.2' diff --git a/examples/blog/Gemfile.lock b/examples/blog/Gemfile.lock index b79b75f8..9fa7736a 100644 --- a/examples/blog/Gemfile.lock +++ b/examples/blog/Gemfile.lock @@ -1,3 +1,12 @@ +PATH + remote: ../.. + specs: + vite_rails (1.0.10) + activesupport (>= 5.1) + rack-proxy (>= 0.6.1) + railties (>= 5.1) + zeitwerk + GEM remote: https://rubygems.org/ specs: @@ -207,11 +216,6 @@ GEM turbolinks-source (5.2.0) tzinfo (2.0.4) concurrent-ruby (~> 1.0) - vite_rails (1.0.10) - activesupport (>= 5.1) - rack-proxy (>= 0.6.1) - railties (>= 5.1) - zeitwerk web-console (4.1.0) actionview (>= 6.0.0) activemodel (>= 6.0.0) @@ -252,7 +256,7 @@ DEPENDENCIES spring-watcher-listen (~> 2.0.0) turbolinks (~> 5) tzinfo-data - vite_rails (= 1.0.10) + vite_rails! web-console (>= 3.3.0) webdrivers webpacker (~> 4.0) diff --git a/examples/blog/app/frontend/entrypoints/application.js b/examples/blog/app/frontend/entrypoints/application.js index 605e7507..1333128a 100644 --- a/examples/blog/app/frontend/entrypoints/application.js +++ b/examples/blog/app/frontend/entrypoints/application.js @@ -2,7 +2,7 @@ import '@rails/ujs' import Turbolinks from 'turbolinks' -import ActiveStorage from '@rails/activestorage' +import * as ActiveStorage from '@rails/activestorage' // Import all channels. import.meta.globEager('../channels/**/*_channel.js') diff --git a/examples/blog/config/initializers/assets.rb b/examples/blog/config/initializers/assets.rb index a9b0d0f1..362416f4 100644 --- a/examples/blog/config/initializers/assets.rb +++ b/examples/blog/config/initializers/assets.rb @@ -8,7 +8,7 @@ # Add additional assets to the asset load path. # Rails.application.config.assets.paths << Emoji.images_path # Add Yarn node_modules folder to the asset load path. -Rails.application.config.assets.paths << Rails.root.join('node_modules') +# Rails.application.config.assets.paths << Rails.root.join('node_modules') # Precompile additional assets. # application.js, application.css, and all non-JS/CSS in the app/assets diff --git a/examples/blog/package.json b/examples/blog/package.json index 651f8db8..b9b02bdf 100644 --- a/examples/blog/package.json +++ b/examples/blog/package.json @@ -1,19 +1,20 @@ { "name": "blog", "private": true, + "license": "MIT", "dependencies": { "@rails/actioncable": "^6.0.0", "@rails/activestorage": "^6.0.0", "@rails/ujs": "^6.0.0", "@rails/webpacker": "4.3.0", - "tailwindcss": "^2.0.2", - "turbolinks": "^5.2.0", - "vite": "^2.0.0-beta.34", - "vite-plugin-ruby": "^1.0.4" + "turbolinks": "^5.2.0" }, "version": "0.1.0", "devDependencies": { - "webpack-dev-server": "^3.11.2", - "postcss": "8.2.4" + "vite-plugin-ruby": "file:../../package", + "postcss": "8.2.4", + "vite": "^2.0.0-beta.46", + "tailwindcss": "^2.0.2", + "webpack-dev-server": "^3.11.2" } } diff --git a/examples/blog/vite.config.ts b/examples/blog/vite.config.ts index 7fcc3bee..b9832a66 100644 --- a/examples/blog/vite.config.ts +++ b/examples/blog/vite.config.ts @@ -6,6 +6,6 @@ export default defineConfig({ RubyPlugin(), ], optimizeDeps: { - exclude: [/webpack/, /vite-plugin-ruby/], + exclude: [/webpack/], // In case webpacker is installed (these deps won't be imported) }, }) diff --git a/examples/blog/yarn.lock b/examples/blog/yarn.lock index 07bfe4e1..dfe05e93 100644 --- a/examples/blog/yarn.lock +++ b/examples/blog/yarn.lock @@ -2848,10 +2848,10 @@ es-to-primitive@^1.2.1: is-date-object "^1.0.1" is-symbol "^1.0.2" -esbuild@^0.8.26: - version "0.8.33" - resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.8.33.tgz#4e24ab4e780b08ff5527171bf5a684594c8b56e9" - integrity sha512-2ms/P6Y9zJfopR9dKo2vHzhXKfGSNlquVVoVOF8YnhjuzZVrvManMVBPadBsR/t7jzIkRnwqvxrs7d4f3C3eyg== +esbuild@^0.8.34: + version "0.8.34" + resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.8.34.tgz#16b4ac58f74c821d2c5a8c2f0585ca96a38ab4e6" + integrity sha512-tnr0V1ooakYr1aRLXQLzCn2GVG1kBTW3FWpRyC+NgrR3ntsouVpJOlTOV0BS4YLATx3/c+x3h/uBq9lWJlUAtQ== escalade@^3.1.1: version "3.1.1" @@ -7647,19 +7647,17 @@ verror@1.10.0: core-util-is "1.0.2" extsprintf "^1.2.0" -vite-plugin-ruby@^1.0.4: - version "1.0.4" - resolved "https://registry.yarnpkg.com/vite-plugin-ruby/-/vite-plugin-ruby-1.0.4.tgz#0f4a263fd79a082a84917a54b0881f02a3bbfa61" - integrity sha512-WJE+c2TGLwcbSHzkqcwCmPcHxasUnXmx5Bi1HPO89Yo+Mggi8t/fO/WIPUF7NxSlp9q2lq5/L3Vnkt3R/tolPg== +"vite-plugin-ruby@file:../../package": + version "1.0.5" dependencies: fast-glob "^3.2.4" -vite@^2.0.0-beta.34: - version "2.0.0-beta.34" - resolved "https://registry.yarnpkg.com/vite/-/vite-2.0.0-beta.34.tgz#8db57443789b1bb0eac624cc596f3aeb7fde9eea" - integrity sha512-D4/2WBf219mZBgDRiKfMwK/07UGiP+d56W2a2SEqf21iMOfM3yNBf3cfTY7qrHoi28EUo8l1LVwkSFPNbFlV2w== +vite@^2.0.0-beta.46: + version "2.0.0-beta.46" + resolved "https://registry.yarnpkg.com/vite/-/vite-2.0.0-beta.46.tgz#9c0d35019c350fbebd17f84c4e7243fffccd1819" + integrity sha512-RiiJdjiFDaM9youfcTFnCztstwBXHHSdsSATZVD5A4QSb39KJRTpSKoveFo0PT7VJM5HjOP7QC/sVOqX011F6Q== dependencies: - esbuild "^0.8.26" + esbuild "^0.8.34" postcss "^8.2.1" resolve "^1.19.0" rollup "^2.35.1" diff --git a/lib/install/config/vite.config.ts b/lib/install/config/vite.config.ts index 7fcc3bee..b9832a66 100644 --- a/lib/install/config/vite.config.ts +++ b/lib/install/config/vite.config.ts @@ -6,6 +6,6 @@ export default defineConfig({ RubyPlugin(), ], optimizeDeps: { - exclude: [/webpack/, /vite-plugin-ruby/], + exclude: [/webpack/], // In case webpacker is installed (these deps won't be imported) }, }) diff --git a/lib/install/template.rb b/lib/install/template.rb index f22c9e06..6fa76c6b 100644 --- a/lib/install/template.rb +++ b/lib/install/template.rb @@ -33,8 +33,8 @@ vite_version = package_json.match(/"vite": "(.*)"/)[1] plugin_version = package_json.match(/"vite-plugin-ruby": "(.*)"/)[1] - say 'Installing vite as direct dependencies' - run "yarn add vite@#{ vite_version } vite-plugin-ruby@#{ plugin_version }" + say 'Installing vite as build dependencies' + run "yarn add -D vite@#{ vite_version } vite-plugin-ruby@#{ plugin_version }" end say 'Vite ⚡️ Rails successfully installed! 🎉', :green diff --git a/lib/tasks/vite/build.rake b/lib/tasks/vite/build.rake index 420da9fa..11197f19 100644 --- a/lib/tasks/vite/build.rake +++ b/lib/tasks/vite/build.rake @@ -3,14 +3,24 @@ $stdout.sync = true def enhance_assets_precompile + # Before installing + ['yarn:install', 'webpacker:yarn_install'].each do |name| + Rake::Task[name].enhance([:'vite:set_node_env']) if Rake::Task.task_defined?(name) + end + + # After precompiling Rake::Task['assets:precompile'].enhance do |task| prefix = task.name.split(/#|assets:precompile/).first - Rake::Task["#{ prefix }vite:build"].invoke end end namespace :vite do + desc 'Fixes Rails management of node dev dependencies (build dependencies)' + task :set_node_env do + ENV['NODE_ENV'] = 'development' + end + desc 'Compile JavaScript packs using vite for production with digests' task build: [:'vite:verify_install', :environment] do ViteRails.build_from_rake diff --git a/lib/tasks/vite/install_dependencies.rake b/lib/tasks/vite/install_dependencies.rake index f117f90d..a4720487 100644 --- a/lib/tasks/vite/install_dependencies.rake +++ b/lib/tasks/vite/install_dependencies.rake @@ -1,19 +1,13 @@ # frozen_string_literal: true namespace :vite do - desc 'Support for older Rails versions. Install all JavaScript dependencies as specified via Yarn' + desc 'Install all JavaScript dependencies as specified via Yarn' task :install_dependencies do valid_node_envs = %w[test development production] node_env = ENV.fetch('NODE_ENV') { valid_node_envs.include?(Rails.env) ? Rails.env : 'production' } Dir.chdir(Rails.root) do - install_command = if Rails.root.join('yarn.lock').exist? - v1 = `yarn --version`.start_with?('1') - "yarn install #{ v1 ? '--no-progress --frozen-lockfile' : '--immutable' }" - elsif Rails.root.join('pnpm-lock.yaml').exist? - 'pnpm install' - else - 'npm ci' - end + v1 = `yarn --version`.start_with?('1') + install_command = "yarn install #{ v1 ? '--no-progress --frozen-lockfile' : '--immutable' } --production=false" system({ 'NODE_ENV' => node_env }, install_command) end end diff --git a/lib/vite_rails.rb b/lib/vite_rails.rb index 71d40f45..acb62e8e 100644 --- a/lib/vite_rails.rb +++ b/lib/vite_rails.rb @@ -14,7 +14,7 @@ class ViteRails ENV_PREFIX = 'VITE_RUBY' class << self - delegate :config, :builder, :manifest, :commands, :dev_server, :dev_server_running?, to: :instance + delegate :config, :builder, :manifest, :commands, :dev_server, :dev_server_running?, :run_proxy?, to: :instance delegate :mode, to: :config delegate :bootstrap, :clean, :clean_from_rake, :clobber, :build, :build_from_rake, to: :commands @@ -29,14 +29,6 @@ def run(args) ViteRails::Runner.new(args).run end - # Public: The proxy for assets should only run in development mode. - def run_proxy? - config.mode == 'development' - rescue StandardError => error - logger.error("Failed to check mode for Vite: #{ error.message }") - false - end - # Internal: Allows to obtain any env variables for configuration options. def load_env_variables ENV.select { |key, _| key.start_with?(ENV_PREFIX) } @@ -53,7 +45,15 @@ def load_env_variables # Public: Returns true if the Vite development server is running. def dev_server_running? - ViteRails.run_proxy? && dev_server.running? + run_proxy? && dev_server.running? + end + + # Public: The proxy for assets should only run in development mode. + def run_proxy? + config.mode == 'development' + rescue StandardError => error + ViteRails.logger.error("Failed to check mode for Vite: #{ error.message }") + false end # Public: Current instance configuration for Vite. diff --git a/lib/vite_rails/config.rb b/lib/vite_rails/config.rb index 7a6ce5d4..dbf1d84b 100644 --- a/lib/vite_rails/config.rb +++ b/lib/vite_rails/config.rb @@ -55,7 +55,7 @@ def to_env def coerce_values(config) config['mode'] = config['mode'].to_s config['port'] = config['port'].to_i - coerce_paths(config, 'root', 'public_output_dir') + config['root'] = Pathname.new(config['root']) config['build_cache_dir'] = config['root'].join(config['build_cache_dir']) coerce_booleans(config, 'auto_build', 'hide_build_console_output', 'https') end @@ -65,14 +65,9 @@ def coerce_booleans(config, *names) names.each { |name| config[name] = [true, 'true'].include?(config[name]) } end - # Internal: Converts configuration options to pathname. - def coerce_paths(config, *names) - names.each { |name| config[name] = Pathname.new(config[name]) unless config[name].nil? } - end - class << self # Public: Returns the project configuration for Vite. - def resolve_config(attrs = {}) + def resolve_config(**attrs) config = attrs.transform_keys(&:to_s).reverse_merge(config_defaults) file_path = File.join(config['root'], config['config_path']) file_config = config_from_file(file_path, mode: config['mode']) diff --git a/lib/vite_rails/helper.rb b/lib/vite_rails/helper.rb index efd4fe64..558f9fde 100644 --- a/lib/vite_rails/helper.rb +++ b/lib/vite_rails/helper.rb @@ -11,7 +11,9 @@ def current_vite_instance # Public: Renders a script tag for vite/client to enable HMR in development. def vite_client_tag - content_tag('script', '', src: '/@vite/client', type: 'module') if ViteRails.dev_server_running? + return unless current_vite_instance.dev_server_running? + + content_tag('script', '', src: current_vite_instance.manifest.prefix_vite_asset('@vite/client'), type: 'module') end # Public: Resolves the path for the specified Vite asset. @@ -33,12 +35,12 @@ def vite_javascript_tag(*names, js_entries = names.map { |name| current_vite_instance.manifest.lookup!(name, type: asset_type) } js_tags = javascript_include_tag(*js_entries.map { |entry| entry['file'] }, crossorigin: crossorigin, type: type, **options) - unless skip_preload_tags || ViteRails.dev_server_running? + unless skip_preload_tags || current_vite_instance.dev_server_running? preload_paths = js_entries.flat_map { |entry| entry['imports'] }.compact.uniq preload_tags = preload_paths.map { |path| preload_link_tag(path, crossorigin: crossorigin) } end - unless skip_style_tags || ViteRails.dev_server_running? + unless skip_style_tags || current_vite_instance.dev_server_running? style_paths = names.map { |name| current_vite_instance.manifest.lookup(name.delete_suffix('.js'), type: :stylesheet)&.fetch('file') }.compact diff --git a/lib/vite_rails/manifest.rb b/lib/vite_rails/manifest.rb index 68d97bdb..1bb41dc3 100644 --- a/lib/vite_rails/manifest.rb +++ b/lib/vite_rails/manifest.rb @@ -42,6 +42,11 @@ def refresh @manifest = load_manifest end + # Public: Scopes an asset to the output folder in public, as a path. + def prefix_vite_asset(path) + File.join("/#{ config.public_output_dir }", path) + end + private delegate :config, :builder, :dev_server_running?, to: :@vite_rails @@ -55,7 +60,7 @@ def should_build? # Internal: Finds the specified entry in the manifest. def find_manifest_entry(name) if dev_server_running? - { 'file' => "/#{ config.public_output_dir.join(name.to_s) }" } + { 'file' => prefix_vite_asset(name.to_s) } else manifest[name.to_s] end @@ -80,8 +85,8 @@ def manifest def load_manifest if config.manifest_path.exist? JSON.parse(config.manifest_path.read).each do |_, entry| - entry['file'] = within_public_output_dir(entry['file']) - entry['imports'] = entry['imports']&.map { |path| within_public_output_dir(path) } + entry['file'] = prefix_vite_asset(entry['file']) + entry['imports'] = entry['imports']&.map { |path| prefix_vite_asset(path) } end else {} @@ -96,11 +101,6 @@ def with_file_extension(name, entry_type) extension ? "#{ name }.#{ extension }" : name end - # Internal: Scopes the paths in the manifest to the output folder in public. - def within_public_output_dir(path) - "/#{ config.public_output_dir.join(path) }" - end - # Internal: Allows to receive :javascript and :stylesheet as :type in helpers. def extension_for_type(entry_type) case entry_type diff --git a/package.json b/package.json index 928d244b..9b1baee9 100644 --- a/package.json +++ b/package.json @@ -6,11 +6,12 @@ "docs:build": "npm -C docs run docs:build", "docs:search": "npm -C docs run docs:search", "docs:lint": "npm -C docs run lint", + "build": "rm -rf package/dist && npm -C package run prerelease", "lint": "npm -C package run lint", "test": "npm -C package run test" }, "dependencies": { - "vite": "^2.0.0-beta.34", + "vite": "^2.0.0-beta.46", "vite-plugin-ruby": "^1.0.4" } } diff --git a/package/README.md b/package/README.md index a4f582bd..e55a8b6b 100644 --- a/package/README.md +++ b/package/README.md @@ -39,9 +39,6 @@ export default { Vue(), ViteRuby(), ], - optimizeDeps: { - exclude: [/vite-plugin-ruby/], - }, }; ``` diff --git a/package/example/app/frontend/components/HelloWorld.vue b/package/example/app/frontend/components/HelloWorld.vue index f5e9769a..4da6778f 100644 --- a/package/example/app/frontend/components/HelloWorld.vue +++ b/package/example/app/frontend/components/HelloWorld.vue @@ -53,4 +53,4 @@ a {

Edit components/HelloWorld.vue to test hot module replacement.

- \ No newline at end of file + diff --git a/package/example/package.json b/package/example/package.json index 15118c8c..ee47c142 100644 --- a/package/example/package.json +++ b/package/example/package.json @@ -12,7 +12,7 @@ "cross-env": "^7.0.3", "typescript": "^4.1.3", "vue": "^3.0.0", - "vite": "^2.0.0-beta.30", + "vite": "^2.0.0-beta.46", "vite-plugin-ruby": "workspace:*" } } diff --git a/package/example/vite.config.ts b/package/example/vite.config.ts index 9a463188..84a8ffa6 100644 --- a/package/example/vite.config.ts +++ b/package/example/vite.config.ts @@ -9,7 +9,7 @@ const config: UserConfig = { ViteRuby(), ], optimizeDeps: { - exclude: [/webpack/, /vite-plugin-ruby/], + exclude: [/webpack/], // In case webpacker is installed (these deps won't be imported) }, } diff --git a/package/package.json b/package/package.json index f6bfcbd6..b63d5bf2 100644 --- a/package/package.json +++ b/package/package.json @@ -1,7 +1,7 @@ { "name": "vite-plugin-ruby", "description": "Convention over configuration for using Vite in Ruby apps", - "version": "1.0.4", + "version": "1.0.5", "main": "dist/index.js", "module": "dist/index.mjs", "types": "dist/index.d.ts", @@ -42,7 +42,7 @@ "standard-version": "^9.1.0", "tsup": "^3.11.0", "typescript": "^4.1.3", - "vite": "^2.0.0-beta.30" + "vite": "^2.0.0-beta.46" }, "jest": { "testRegex": "(/__tests__/.*|(\\.|/))\\.jsx?$", diff --git a/package/pnpm-lock.yaml b/package/pnpm-lock.yaml index 1de13b25..00224d8e 100644 --- a/package/pnpm-lock.yaml +++ b/package/pnpm-lock.yaml @@ -14,7 +14,7 @@ importers: standard-version: 9.1.0 tsup: 3.11.0_typescript@4.1.3 typescript: 4.1.3 - vite: 2.0.0-beta.31 + vite: 2.0.0-beta.46 specifiers: '@antfu/eslint-config': ^0.4.3 '@types/debug': ^4.1.5 @@ -28,14 +28,14 @@ importers: standard-version: ^9.1.0 tsup: ^3.11.0 typescript: ^4.1.3 - vite: ^2.0.0-beta.30 + vite: ^2.0.0-beta.46 example: devDependencies: '@vitejs/plugin-vue': 1.0.6_@vue+compiler-sfc@3.0.5 '@vue/compiler-sfc': 3.0.5_vue@3.0.5 cross-env: 7.0.3 typescript: 4.1.3 - vite: 2.0.0-beta.31 + vite: 2.0.0-beta.46 vite-plugin-ruby: 'link:..' vue: 3.0.5 specifiers: @@ -43,7 +43,7 @@ importers: '@vue/compiler-sfc': ^3.0.5 cross-env: ^7.0.3 typescript: ^4.1.3 - vite: ^2.0.0-beta.30 + vite: ^2.0.0-beta.46 vite-plugin-ruby: 'workspace:*' vue: ^3.0.0 lockfileVersion: 5.2 @@ -2276,6 +2276,12 @@ packages: requiresBuild: true resolution: integrity: sha512-2ms/P6Y9zJfopR9dKo2vHzhXKfGSNlquVVoVOF8YnhjuzZVrvManMVBPadBsR/t7jzIkRnwqvxrs7d4f3C3eyg== + /esbuild/0.8.34: + dev: true + hasBin: true + requiresBuild: true + resolution: + integrity: sha512-tnr0V1ooakYr1aRLXQLzCn2GVG1kBTW3FWpRyC+NgrR3ntsouVpJOlTOV0BS4YLATx3/c+x3h/uBq9lWJlUAtQ== /escape-string-regexp/1.0.5: dev: true engines: @@ -6716,9 +6722,9 @@ packages: '0': node >=0.6.0 resolution: integrity: sha1-OhBcoXBTr1XW4nDB+CiGguGNpAA= - /vite/2.0.0-beta.31: + /vite/2.0.0-beta.46: dependencies: - esbuild: 0.8.33 + esbuild: 0.8.34 postcss: 8.2.4 resolve: 1.19.0 rollup: 2.36.2 @@ -6729,7 +6735,7 @@ packages: optionalDependencies: fsevents: 2.1.3 resolution: - integrity: sha512-tHBgSsSp0+dbz8tas6zOj2KbJSKOme62jXN13rk8BZdJEum5FDnwon9+7oas4db3NnVBLnciWa1r8QUNoOZjrA== + integrity: sha512-RiiJdjiFDaM9youfcTFnCztstwBXHHSdsSATZVD5A4QSb39KJRTpSKoveFo0PT7VJM5HjOP7QC/sVOqX011F6Q== /vue-eslint-parser/7.3.0_eslint@7.18.0: dependencies: debug: 4.3.1 diff --git a/package/src/config.ts b/package/src/config.ts index 102c475d..6ebd7b1d 100644 --- a/package/src/config.ts +++ b/package/src/config.ts @@ -54,9 +54,9 @@ function coerceConfigurationValues(config: UnifiedConfig, projectRoot: string): config.outDir = relative(config.root!, buildOutputDir) // Vite expects it to be relative // Add the asset host to enable usage of a CDN. - const { assetHost = '' } = config + const assetHost = config.assetHost || '' const assetHostWithProtocol = assetHost && !assetHost.startsWith('http') ? `//${assetHost}` : assetHost - config.base = `${assetHostWithProtocol}/${config.publicOutputDir!}` + config.base = `${assetHostWithProtocol}/${config.publicOutputDir!}/` return config } diff --git a/package/src/index.ts b/package/src/index.ts index 50a545d0..6fdfad0b 100644 --- a/package/src/index.ts +++ b/package/src/index.ts @@ -20,7 +20,6 @@ function config(config: UserConfig): UserConfig { const build = { assetsDir, - base, emptyOutDir: false, outDir, manifest: true, @@ -32,6 +31,7 @@ function config(config: UserConfig): UserConfig { alias: { '~/': `${resolve(join(projectRoot, sourceCodeDir!))}/`, }, + base, root, server, build, diff --git a/test/config_test.rb b/test/config_test.rb index ed751e00..be669189 100644 --- a/test/config_test.rb +++ b/test/config_test.rb @@ -120,7 +120,7 @@ def test_environment_vars assert_equal 'config/vite_additional_paths.json', @config.config_path assert_pathname 'tmp/vitebuild', @config.build_cache_dir assert_equal 'pb', @config.public_dir - assert_equal Pathname.new('ft'), @config.public_output_dir + assert_equal 'ft', @config.public_output_dir assert_pathname 'pb/ft', @config.build_output_dir assert_equal 'as', @config.assets_dir assert_equal 'app', @config.source_code_dir diff --git a/test/dev_server_proxy_test.rb b/test/dev_server_proxy_test.rb index e9564c7f..1dac61c9 100644 --- a/test/dev_server_proxy_test.rb +++ b/test/dev_server_proxy_test.rb @@ -11,6 +11,7 @@ def app [200, { 'Content-Type' => 'application/json' }, env.to_json] }) # Avoid actually using the proxy. + Rack::Proxy.remove_method(:perform_request) Rack::Proxy.define_method(:perform_request) { |env| capture_app.call(env) } ViteRails::DevServerProxy.new(capture_app) diff --git a/test/engine_rake_tasks_test.rb b/test/engine_rake_tasks_test.rb index ad634f65..b3797aee 100644 --- a/test/engine_rake_tasks_test.rb +++ b/test/engine_rake_tasks_test.rb @@ -38,13 +38,13 @@ def test_rake_tasks within_mounted_app { `bundle exec rake app:vite:clobber` } refute app_public_dir.exist? rescue Minitest::Assertion => error - raise error unless Rails.gem_version >= Gem::Version.new('6.1.0') + raise error, [error.message, @command_results.join("\n\n")].join("\n") end private def within_mounted_app - Dir.chdir(mounted_app_path) { yield } + Dir.chdir(mounted_app_path) { yield }.tap { |result| @command_results << result } end def mounted_app_path @@ -76,5 +76,6 @@ def remove_vite_files vite_config_ts_path.delete if vite_config_ts_path.exist? app_frontend_dir.rmtree if app_frontend_dir.exist? app_public_dir.rmtree if app_public_dir.exist? + @command_results = [] end end diff --git a/test/helper_test.rb b/test/helper_test.rb index 3cf55c34..80d9adff 100644 --- a/test/helper_test.rb +++ b/test/helper_test.rb @@ -22,7 +22,7 @@ def base_url def test_vite_client_tag assert_nil vite_client_tag with_dev_server_running { - assert_equal '', vite_client_tag + assert_equal '', vite_client_tag } end diff --git a/test/mounted_app/test/dummy/package.json b/test/mounted_app/test/dummy/package.json index 480b987c..9d6fe33d 100644 --- a/test/mounted_app/test/dummy/package.json +++ b/test/mounted_app/test/dummy/package.json @@ -1,8 +1,8 @@ { "private": true, - "dependencies": { - "vite": "^2.0.0-beta.34", + "license": "MIT", + "devDependencies": { + "vite": "^2.0.0-beta.46", "vite-plugin-ruby": "^1.0.4" - }, - "license": "MIT" + } } diff --git a/test/mounted_app/test/dummy/yarn.lock b/test/mounted_app/test/dummy/yarn.lock index 06ce3a60..5cbcc827 100644 --- a/test/mounted_app/test/dummy/yarn.lock +++ b/test/mounted_app/test/dummy/yarn.lock @@ -35,7 +35,7 @@ colorette@^1.2.1: resolved "https://registry.yarnpkg.com/colorette/-/colorette-1.2.1.tgz#4d0b921325c14faf92633086a536db6e89564b1b" integrity sha512-puCDz0CzydiSYOrnXpz/PKd69zRrribezjtE9yd4zvytoRc8+RY/KJPvtPFKZS3E3wP6neGyMe0vOTlHO5L3Pw== -esbuild@^0.8.26: +esbuild@^0.8.34: version "0.8.34" resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.8.34.tgz#16b4ac58f74c821d2c5a8c2f0585ca96a38ab4e6" integrity sha512-tnr0V1ooakYr1aRLXQLzCn2GVG1kBTW3FWpRyC+NgrR3ntsouVpJOlTOV0BS4YLATx3/c+x3h/uBq9lWJlUAtQ== @@ -195,12 +195,12 @@ vite-plugin-ruby@^1.0.4: dependencies: fast-glob "^3.2.4" -vite@^2.0.0-beta.34: - version "2.0.0-beta.36" - resolved "https://registry.yarnpkg.com/vite/-/vite-2.0.0-beta.36.tgz#ccecac854ded0b7c0fe14c52c0460e1c23a9c70b" - integrity sha512-+Q/Twq1/tpNQIZl0HSFTqiEuP7lXj+6H/f9q63+s5I2K/sqgSUajL3PL7W9uUUIv9dYpJ1eLqkO42ppH9w9Ldw== +vite@^2.0.0-beta.46: + version "2.0.0-beta.46" + resolved "https://registry.yarnpkg.com/vite/-/vite-2.0.0-beta.46.tgz#9c0d35019c350fbebd17f84c4e7243fffccd1819" + integrity sha512-RiiJdjiFDaM9youfcTFnCztstwBXHHSdsSATZVD5A4QSb39KJRTpSKoveFo0PT7VJM5HjOP7QC/sVOqX011F6Q== dependencies: - esbuild "^0.8.26" + esbuild "^0.8.34" postcss "^8.2.1" resolve "^1.19.0" rollup "^2.35.1" diff --git a/test/rake_tasks_test.rb b/test/rake_tasks_test.rb index b275608c..47644853 100644 --- a/test/rake_tasks_test.rb +++ b/test/rake_tasks_test.rb @@ -38,8 +38,8 @@ def test_rake_vite_install_dependencies_in_production_environment end end - refute_includes installed_node_module_names, 'right-pad', - 'Expected only production dependencies to be installed' + assert_includes installed_node_module_names, 'right-pad', + 'Expected development dependencies to be installed as well' end private