From 5c8bb625926f2ab1788a3e3a22aeafd7104984cb Mon Sep 17 00:00:00 2001 From: Maximo Mussini Date: Sat, 20 Mar 2021 13:11:26 -0300 Subject: [PATCH] fix: Simplify installation of build dependencies by using package manager flags --- vite_rails/lib/tasks/vite.rake | 13 ------------- vite_rails_legacy/lib/tasks/vite.rake | 16 ---------------- vite_ruby/lib/tasks/vite.rake | 6 ++++++ 3 files changed, 6 insertions(+), 29 deletions(-) diff --git a/vite_rails/lib/tasks/vite.rake b/vite_rails/lib/tasks/vite.rake index 7b25b326..0541ccfa 100644 --- a/vite_rails/lib/tasks/vite.rake +++ b/vite_rails/lib/tasks/vite.rake @@ -2,16 +2,3 @@ require 'vite_ruby' ViteRuby.install_tasks - -namespace :vite_rails do - desc 'Fixes Rails management of node dev dependencies (build dependencies)' - task :set_node_env do - ENV['NODE_ENV'] = 'development' - end -end - -# Set NODE_ENV before installation, so that Rails installs JS build dependencies -# on servers that precompile assets. -['yarn:install', 'webpacker:yarn_install'].each do |name| - Rake::Task[name].enhance([:'vite_rails:set_node_env']) if Rake::Task.task_defined?(name) -end diff --git a/vite_rails_legacy/lib/tasks/vite.rake b/vite_rails_legacy/lib/tasks/vite.rake index f5b88c74..0541ccfa 100644 --- a/vite_rails_legacy/lib/tasks/vite.rake +++ b/vite_rails_legacy/lib/tasks/vite.rake @@ -1,20 +1,4 @@ # frozen_string_literal: true -# Set NODE_ENV before installation, so that Rails installs JS build dependencies -# on servers that precompile assets. -installation_tasks = ['yarn:install', 'webpacker:yarn_install'].select { |name| Rake::Task.task_defined?(name) }.each do |name| - Rake::Task[name].enhance([:'vite_rails:set_node_env']) -end - -# Ensure dependencies are installed in older versions of Rails -Rake::Task['assets:precompile']&.enhance([:'vite:install_dependencies']) if installation_tasks.none? - require 'vite_ruby' ViteRuby.install_tasks - -namespace :vite_rails do - desc 'Fixes Rails management of node dev dependencies (build dependencies)' - task :set_node_env do - ENV['NODE_ENV'] = 'development' - end -end diff --git a/vite_ruby/lib/tasks/vite.rake b/vite_ruby/lib/tasks/vite.rake index e2eb1c2d..659261fc 100644 --- a/vite_ruby/lib/tasks/vite.rake +++ b/vite_ruby/lib/tasks/vite.rake @@ -48,3 +48,9 @@ if Rake::Task.task_defined?('assets:precompile') else Rake::Task.define_task('assets:precompile' => ['vite:install_dependencies', 'vite:build']) end + +# Any prerequisite task that installs packages should also install build dependencies. +if ARGV.include?('assets:precompile') + ENV['NPM_CONFIG_PRODUCTION'] = 'false' + ENV['YARN_PRODUCTION'] = 'false' +end