From 3fae5a027f8095913203a02034ad92428c9c503b Mon Sep 17 00:00:00 2001 From: Martin Gruner Date: Mon, 12 Jul 2021 11:46:57 +0200 Subject: [PATCH] Maintenance: Load asset processing gems only at build time. --- Gemfile | 29 ++++++++++--------- .../application_controller/handles_errors.rb | 2 +- config/application.rb | 8 +++++ 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/Gemfile b/Gemfile index f765211f5..36d64d439 100644 --- a/Gemfile +++ b/Gemfile @@ -47,24 +47,27 @@ gem 'rszr', '0.5.2' # performance - Memcached gem 'dalli', require: false -# asset handling - coffee-script -gem 'coffee-rails' -gem 'coffee-script-source' +# Only load gems for asset compilation if they are needed to avoid +# having unneeded runtime dependencies like NodeJS. +group :assets do + # asset handling - javascript execution for e.g. linux + gem 'execjs', require: false -# asset handling - frontend templating -gem 'eco' + # asset handling - coffee-script + gem 'coffee-rails', require: false -# asset handling - SASS -gem 'sassc-rails' + # asset handling - frontend templating + gem 'eco', require: false -# asset handling - pipeline -gem 'sprockets', '~> 3.7.2' -gem 'uglifier' + # asset handling - SASS + gem 'sassc-rails', require: false -gem 'autoprefixer-rails' + # asset handling - pipeline + gem 'sprockets', '~> 3.7.2', require: false + gem 'uglifier', require: false -# asset handling - javascript execution for e.g. linux -gem 'execjs' + gem 'autoprefixer-rails', require: false +end # Don't use mini_racer any more for asset compilation. # Instead, use an external node.js binary. diff --git a/app/controllers/application_controller/handles_errors.rb b/app/controllers/application_controller/handles_errors.rb index 46929ce95..4ec11225a 100644 --- a/app/controllers/application_controller/handles_errors.rb +++ b/app/controllers/application_controller/handles_errors.rb @@ -5,7 +5,7 @@ module ApplicationController::HandlesErrors included do rescue_from StandardError, with: :internal_server_error - rescue_from ExecJS::RuntimeError, with: :internal_server_error + rescue_from 'ExecJS::RuntimeError', with: :internal_server_error rescue_from ActiveRecord::RecordNotFound, with: :not_found rescue_from ActiveRecord::StatementInvalid, with: :unprocessable_entity rescue_from ActiveRecord::RecordInvalid, with: :unprocessable_entity diff --git a/config/application.rb b/config/application.rb index b0f182327..d763fbcd7 100644 --- a/config/application.rb +++ b/config/application.rb @@ -12,6 +12,14 @@ Bundler.setup # you've limited to :test, :development, or :production. Bundler.require(*Rails.groups) +# Only load gems for asset compilation if they are needed to avoid +# having unneeded runtime dependencies like NodeJS. +if ARGV.include?('assets:precompile') || Rails.groups.exclude?('production') + Bundler.load.current_dependencies.select do |dep| + require dep.name if dep.groups.include?(:assets) + end +end + module Zammad class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version.