From f234d38cc1e3756ff2d2fc5b71609670621a9f00 Mon Sep 17 00:00:00 2001 From: Justin Littman Date: Mon, 27 Nov 2023 13:18:31 -0500 Subject: [PATCH] Switch to importmap and propshaft. closes #2288 --- Capfile | 3 +-- Gemfile | 2 ++ Gemfile.lock | 11 +++++++++++ app/javascript/application.js | 2 ++ app/views/layouts/application.html.erb | 4 +--- bin/importmap | 4 ++++ config/deploy.rb | 8 +++++++- config/importmap.rb | 6 ++++++ vendor/javascript/.keep | 0 9 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 app/javascript/application.js create mode 100755 bin/importmap create mode 100644 config/importmap.rb create mode 100644 vendor/javascript/.keep diff --git a/Capfile b/Capfile index 5f32dac19..6a5128fc0 100644 --- a/Capfile +++ b/Capfile @@ -8,9 +8,8 @@ require "capistrano/scm/git" install_plugin Capistrano::SCM::Git require "capistrano/bundler" -# require "capistrano/rails/assets" -require "capistrano/rails/migrations" require "capistrano/passenger" +require "capistrano/rails" require "capistrano/honeybadger" require "dlss/capistrano" require 'whenever/capistrano' diff --git a/Gemfile b/Gemfile index a9534def9..03c83773c 100644 --- a/Gemfile +++ b/Gemfile @@ -6,12 +6,14 @@ gem 'committee' # Validates HTTP requests/responses per OpenAPI specification gem 'connection_pool' # Used for redis gem 'config' # Settings to manage configs on different instances gem 'honeybadger' # for error reporting / tracking / notifications +gem "importmap-rails", "~> 1.2" gem 'jbuilder' # Build JSON APIs with ease. gem 'jwt' # for gating programmatic access to the application gem 'lograge' gem 'okcomputer' # ReST endpoint with upness status gem 'pg' # postgres database gem 'postgresql_cursor' # for paging over large result sets efficiently +gem 'propshaft', '~> 0.8.0' # asset pipeline # pry is useful for debugging, even in prod gem 'pry-byebug' # call 'binding.pry' anywhere in the code to stop execution and get a pry-byebug console gem 'pry' # make it possible to use pry for IRB diff --git a/Gemfile.lock b/Gemfile.lock index 6263b1bd7..25afce0ce 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -223,6 +223,10 @@ GEM honeybadger (5.3.0) i18n (1.14.1) concurrent-ruby (~> 1.0) + importmap-rails (1.2.3) + actionpack (>= 6.0.0) + activesupport (>= 6.0.0) + railties (>= 6.0.0) io-console (0.6.0) irb (1.9.1) rdoc @@ -289,6 +293,11 @@ GEM pg (1.5.4) postgresql_cursor (0.6.8) activerecord (>= 6.0) + propshaft (0.8.0) + actionpack (>= 7.0.0) + activesupport (>= 7.0.0) + rack + railties (>= 7.0.0) pry (0.14.2) coderay (~> 1.1) method_source (~> 1.0) @@ -469,6 +478,7 @@ DEPENDENCIES druid-tools factory_bot_rails honeybadger + importmap-rails (~> 1.2) jbuilder jwt listen (~> 3.7) @@ -477,6 +487,7 @@ DEPENDENCIES okcomputer pg postgresql_cursor + propshaft (~> 0.8.0) pry pry-byebug puma diff --git a/app/javascript/application.js b/app/javascript/application.js new file mode 100644 index 000000000..e524d1661 --- /dev/null +++ b/app/javascript/application.js @@ -0,0 +1,2 @@ +// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails +import "@hotwired/turbo-rails" diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 470819344..db070bf2a 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -8,9 +8,7 @@ SUL - Preservation Catalog - + <%= javascript_importmap_tags %> diff --git a/bin/importmap b/bin/importmap new file mode 100755 index 000000000..36502ab16 --- /dev/null +++ b/bin/importmap @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby + +require_relative "../config/application" +require "importmap/commands" diff --git a/config/deploy.rb b/config/deploy.rb index 9d30a1858..b8997b52e 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -20,7 +20,7 @@ append :linked_files, 'config/database.yml' # Default value for linked_dirs is [] -append :linked_dirs, 'log', 'config/settings', 'tmp/pids' +append :linked_dirs, 'log', 'config/settings', 'tmp/pids', 'vendor/bundle' set :honeybadger_env, fetch(:stage) @@ -52,3 +52,9 @@ set :sidekiq_systemd_role, :worker set :sidekiq_systemd_use_hooks, true + +# configure capistrano-rails to work with propshaft instead of sprockets +# (we don't have public/assets/.sprockets-manifest* or public/assets/manifest*.*) +set :assets_manifests, lambda { + [release_path.join('public', fetch(:assets_prefix), '.manifest.json')] +} diff --git a/config/importmap.rb b/config/importmap.rb new file mode 100644 index 000000000..804103623 --- /dev/null +++ b/config/importmap.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +# Pin npm packages by running ./bin/importmap + +pin 'application', preload: true +pin '@hotwired/turbo-rails', to: 'turbo.min.js', preload: true diff --git a/vendor/javascript/.keep b/vendor/javascript/.keep new file mode 100644 index 000000000..e69de29bb