Skip to content

Commit

Permalink
Upgrade to Rails 6.1/Shakapacker
Browse files Browse the repository at this point in the history
Turn experimental dependencies into defaults.

REDMINE-19438
  • Loading branch information
tf committed Nov 6, 2023
1 parent f08a9ff commit 1196166
Show file tree
Hide file tree
Showing 21 changed files with 92 additions and 337 deletions.
37 changes: 0 additions & 37 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,72 +13,35 @@ jobs:
fail-fast: false
matrix:
include:
- engine-name: pageflow
ruby-version: 2.6
engine-directory: .
rspec-command: bin/rspec --tag ~js
install-audiowaveform: true

- engine-name: pageflow
ruby-version: 3.2
rails-version: "~> 6.1"
engine-directory: .
rspec-command: bin/rspec --tag ~js
install-audiowaveform: true

- engine-name: pageflow
ruby-version: 2.6
engine-directory: .
rspec-command: bin/rspec-with-retry --tag js

- engine-name: pageflow
ruby-version: 3.2
rails-version: "~> 6.1"
engine-directory: .
rspec-command: bin/rspec-with-retry --tag js

- engine-name: pageflow_paged
ruby-version: 2.6
engine-directory: entry_types/paged
plugin-name: pageflow_paged
rspec-command: bin/rspec

- engine-name: pageflow_paged
ruby-version: 3.2
rails-version: "~> 6.1"
engine-directory: entry_types/paged
plugin-name: pageflow_paged
rspec-command: bin/rspec

- engine-name: pageflow_scrolled
ruby-version: 2.6
engine-directory: entry_types/scrolled
plugin-name: pageflow_scrolled
rspec-command: bin/rspec --tag ~js

- engine-name: pageflow_scrolled
ruby-version: 3.2
rails-version: "~> 6.1"
engine-directory: entry_types/scrolled
plugin-name: pageflow_scrolled
rspec-command: bin/rspec --tag ~js

- engine-name: pageflow_scrolled
ruby-version: 2.6
engine-directory: entry_types/scrolled
plugin-name: pageflow_scrolled
rspec-command: bin/rspec-with-retry-on-timeout --tag js

- engine-name: pageflow_scrolled
ruby-version: 3.2
rails-version: "~> 6.1"
engine-directory: entry_types/scrolled
plugin-name: pageflow_scrolled
rspec-command: bin/rspec-with-retry-on-timeout --tag js

env:
PAGEFLOW_RAILS_VERSION: ${{ matrix.rails-version }}

services:
mysql:
image: mysql:5.7
Expand Down
18 changes: 5 additions & 13 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,11 @@ end
# Required for XML serialization in Active Admin
gem 'activemodel-serializers-xml'

if Pageflow::RailsVersion.experimental?
# Make shakapacker available in specs. Host applications that want to
# use shakapacker need to add it to their Gemfile themselves. Requiring
# shakapacker in an engine file (like we normally do) would force all
# host application to install shakapacker.
gem 'shakapacker', '~> 7.0'
else
# Make webpacker available in specs. Host applications that want to
# use webpacker need to add it to their Gemfile themselves. Requiring
# webpacker in an engine file (like we normally do) would force all
# host application to install webpacker.
gem 'webpacker', '~> 4.2'
end
# Make shakapacker available in specs. Host applications that want to
# use shakapacker need to add it to their Gemfile themselves. Requiring
# shakapacker in an engine file (like we normally do) would force all
# host application to install shakapacker.
gem 'shakapacker', '~> 7.0'

# Make tests fail on JS errors
gem 'capybara-chromedriver-logger', git: 'https://github.com/codevise/capybara-chromedriver-logger', branch: 'fix-selenium-4-deprecation', require: false
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@ Pageflow assumes the following choice of libraries:

Pageflow runs in environments with:

* Ruby >= 2.1 (see `.travis.yml` for supported versions)
* Node >= 10.18
* Rails 4.2
* Ruby >= 3.2
* Node >= 14
* Rails 6.1
* Redis server (for Resque)
* A database server supported by Active Record (tested with MySQL)
* ImageMagick
* [libvips](https://github.com/libvips/ruby-vips)
* [Audio Waveform Image Generator](https://github.com/bbc/audiowaveform#installation)

Accounts of the following cloud services have to be registered:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,7 @@ def respond_to_missing?(name, _include_private = false)
# This is also the reason we can not use SimpleDelegator here
# and also delegate_missing in Rails 5 would not work.
def method_missing(method, *args, **kwargs, &block)
# Required for Ruby 2.6. Remove together with
# Pageflow::RailsVersion.experimental? conditionals.
if kwargs.present?
@context.public_send(method, *args, **kwargs, &block)
else
@context.public_send(method, *args, &block)
end
@context.public_send(method, *args, **kwargs, &block)
end
# rubocop:enable Style/MethodMissing
end
Expand Down
5 changes: 0 additions & 5 deletions bin/rspec-with-experimental-rails

This file was deleted.

18 changes: 7 additions & 11 deletions entry_types/paged/lib/pageflow_paged/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,15 @@ module PageflowPaged
class Engine < ::Rails::Engine
isolate_namespace PageflowPaged

if Pageflow::RailsVersion.experimental?
lib = root.join('lib')
lib = root.join('lib')

config.autoload_paths << lib
config.eager_load_paths << lib
config.autoload_paths << lib
config.eager_load_paths << lib

initializer 'pageflow_paged.autoloading' do
Rails.autoloaders.main.ignore(
lib.join('tasks')
)
end
else
config.paths.add('lib', eager_load: true)
initializer 'pageflow_paged.autoloading' do
Rails.autoloaders.main.ignore(
lib.join('tasks')
)
end

config.i18n.load_path += Dir[config.root.join('config', 'locales', '**', '*.yml').to_s]
Expand Down
43 changes: 12 additions & 31 deletions entry_types/scrolled/app/helpers/pageflow_scrolled/packs_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,24 @@ module PageflowScrolled
# @api private
module PacksHelper
def scrolled_frontend_javascript_packs_tag(entry, options)
if defined?(Shakapacker)
javascript_pack_tag(
*scrolled_frontend_packs(entry, **options),
defer: false
)
else
javascript_packs_with_chunks_tag(
*scrolled_frontend_packs(entry, **options)
)
end
javascript_pack_tag(
*scrolled_frontend_packs(entry, **options),
defer: false
)
end

def scrolled_frontend_stylesheet_packs_tag(entry, options)
if defined?(Shakapacker)
stylesheet_pack_tag(
*scrolled_frontend_packs(entry, **options),
media: 'all'
)
else
stylesheet_packs_with_chunks_tag(
*scrolled_frontend_packs(entry, **options),
media: 'all'
)
end
stylesheet_pack_tag(
*scrolled_frontend_packs(entry, **options),
media: 'all'
)
end

def scrolled_editor_javascript_packs_tag(entry)
if defined?(Shakapacker)
javascript_pack_tag(
*scrolled_editor_packs(entry),
defer: false
)
else
javascript_packs_with_chunks_tag(
*scrolled_editor_packs(entry)
)
end
javascript_pack_tag(
*scrolled_editor_packs(entry),
defer: false
)
end

def scrolled_frontend_packs(entry, widget_scope:)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ def scrolled_theme_asset_path(theme,
theme_file_role: nil,
theme_file_style: :resized,
relative_url: false)
prefix = defined?(Shakapacker) ? 'static' : 'media'

path =
theme.files.dig(theme_file_role, theme_file_style) ||
asset_pack_path("#{prefix}/pageflow-scrolled/themes/#{theme.name}/#{path}")
asset_pack_path("static/pageflow-scrolled/themes/#{theme.name}/#{path}")

if relative_url
URI.parse(path).path
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
<%= stylesheet_link_tag 'pageflow_paged/editor', media: 'all' %>

<% if defined?(Shakapacker) %>
<%= stylesheet_pack_tag 'pageflow-scrolled-frontend' %>
<% else %>
<%= stylesheet_packs_with_chunks_tag 'pageflow-scrolled-frontend' %>
<% end %>
<%= stylesheet_pack_tag 'pageflow-scrolled-frontend' %>

<%= scrolled_theme_properties_style_tag(entry.theme) %>
<%= scrolled_theme_stylesheet_pack_tags(entry.theme) %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,14 @@ def theme_plugin
end

def install_packages
if defined?(Shakapacker)
run 'yarn add css-loader style-loader' \
' mini-css-extract-plugin css-minimizer-webpack-plugin' \
' postcss postcss-preset-env postcss-loader' \
' postcss-import postcss-url postcss-flexbugs-fixes' \
' @fontsource/source-sans-pro'
else
run 'yarn add postcss-url@^8.0.0 @fontsource/source-sans-pro'
end
run 'yarn add css-loader style-loader' \
' mini-css-extract-plugin css-minimizer-webpack-plugin' \
' postcss postcss-preset-env postcss-loader' \
' postcss-import postcss-url postcss-flexbugs-fixes' \
' @fontsource/source-sans-pro'
end

def webpack_config
return unless defined?(Shakapacker)

gsub_file(
'config/webpack/webpack.config.js',
"const { generateWebpackConfig } = require('shakapacker')",
Expand Down Expand Up @@ -92,65 +86,23 @@ def webpack_config
)
end

def webpack_environment
return if defined?(Shakapacker)

inject_into_file('config/webpack/environment.js',
before: "module.exports = environment\n") do
"environment.config.merge(require('pageflow/config/webpack'))\n" \
"environment.config.merge(require('pageflow-scrolled/config/webpack'))\n\n" \
"// Allow loading only chunks of used widgets. runtimeChunk 'single'\n" \
"// ensures that modules are only evaluated once which is important\n" \
"// for modules with side effects.\n" \
"environment.splitChunks((config) =>\n" \
" Object.assign({}, config, { optimization: { runtimeChunk: 'single' }})\n" \
")\n\n" \
"// Opt into future default behavior of Webpacker [1] to work around\n" \
"// problems with Video.js DASH service worker.\n" \
"//\n" \
"// [1] https://github.com/rails/webpacker/pull/2624\n" \
"environment.loaders.delete('nodeModules')\n\n"
end
end

def webpacker_yml
return if defined?(Shakapacker)

gsub_file('config/webpacker.yml',
'extract_css: false',
'extract_css: true')

inject_into_file('config/webpacker.yml',
after: "- .woff2\n") do
" - .mp3\n - .webmanifest\n - .xml\n"
end
end

def postcss_config
if defined?(Shakapacker)
create_file 'postcss.config.js', <<~JS
module.exports = {
plugins: [
require('postcss-import'),
// Make relative urls in fontsource packages work
require('postcss-url')({url: 'rebase'}),
require('postcss-flexbugs-fixes'),
require('postcss-preset-env')({
autoprefixer: {
flexbox: 'no-2009'
},
stage: 3
})
]
}
JS
else
inject_into_file('postcss.config.js',
after: "require('postcss-import'),\n") do
" // Make relative urls in fontsource packages work\n" \
" require('postcss-url')({url: 'rebase'}),\n"
end
end
create_file 'postcss.config.js', <<~JS
module.exports = {
plugins: [
require('postcss-import'),
// Make relative urls in fontsource packages work
require('postcss-url')({url: 'rebase'}),
require('postcss-flexbugs-fixes'),
require('postcss-preset-env')({
autoprefixer: {
flexbox: 'no-2009'
},
stage: 3
})
]
}
JS
end

def editor_pack
Expand Down
20 changes: 8 additions & 12 deletions entry_types/scrolled/lib/pageflow_scrolled/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,16 @@ module PageflowScrolled
class Engine < ::Rails::Engine
isolate_namespace PageflowScrolled

if Pageflow::RailsVersion.experimental?
lib = root.join('lib')
lib = root.join('lib')

config.autoload_paths << lib
config.eager_load_paths << lib
config.autoload_paths << lib
config.eager_load_paths << lib

initializer 'pageflow_scrolled.autoloading' do
Rails.autoloaders.main.ignore(
lib.join('generators'),
lib.join('tasks')
)
end
else
config.paths.add('lib', eager_load: true)
initializer 'pageflow_scrolled.autoloading' do
Rails.autoloaders.main.ignore(
lib.join('generators'),
lib.join('tasks')
)
end

config.i18n.load_path += Dir[config.root.join('config', 'locales', '**', '*.yml').to_s]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace :pageflow_scrolled do
desc 'Generate dummy app for current Rails version.'
task :dummy do
require 'pageflow/support'
ENV['PAGEFLOW_INSTALL_WEBPACKER'] = 'true'
ENV['PAGEFLOW_INSTALL_SHAKAPACKER'] = 'true'
Pageflow::Dummy.setup
end
end
Loading

0 comments on commit 1196166

Please sign in to comment.