Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-enable flickwerk-style patches #94

Merged
merged 4 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion lib/solidus_support/engine_extensions.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require "active_support/deprecation"
require "flickwerk"

module SolidusSupport
module EngineExtensions
Expand All @@ -9,6 +10,7 @@ module EngineExtensions

def self.included(engine)
engine.extend ClassMethods
engine.include Flickwerk

engine.class_eval do
solidus_decorators_root.glob('*') do |decorators_folder|
Expand Down Expand Up @@ -102,7 +104,7 @@ def enable_solidus_engine_support(engine)
# by those gems, we work around those gems by adding our paths before
# `initialize_cache`, which is the Rails initializer called before
# `set_load_path`.
initializer "#{name}_#{engine}_paths", before: :initialize_cache do
initializer "#{engine_name}_#{engine}_paths", before: :initialize_cache do
if SolidusSupport.send(:"#{engine}_available?")
paths['app/controllers'] << "lib/controllers/#{engine}"
paths['app/views'] << "lib/views/#{engine}"
Expand All @@ -111,9 +113,11 @@ def enable_solidus_engine_support(engine)

if SolidusSupport.send(:"#{engine}_available?")
decorators_path = root.join("lib/decorators/#{engine}")
patches_path = root.join("lib/patches/#{engine}")
controllers_path = root.join("lib/controllers/#{engine}")
components_path = root.join("lib/components/#{engine}")
config.autoload_paths += decorators_path.glob('*')
config.autoload_paths += patches_path.glob("*")
config.autoload_paths << controllers_path if controllers_path.exist?
config.autoload_paths << components_path if components_path.exist?

Expand All @@ -124,6 +128,30 @@ def enable_solidus_engine_support(engine)
end
end
end

initializer "#{engine_name}_#{engine}_patch_paths", before: "flickwerk.add_paths" do
patch_paths = root.join("lib/patches/#{engine}").glob("*")
Flickwerk.patch_paths += patch_paths
end

initializer "#{engine_name}_#{engine}_user_patches", before: "flickwerk.find_patches" do
app.reloader.to_prepare do
Flickwerk.aliases["Spree.user_class"] = Spree.user_class_name
end
end

initializer "eager_load_#{engine_name}_#{engine}_patches", after: "flickwerk.find_patches" do |app|
# Solidus versions < 4.5 `require` some of their application code.
# This leads to hard-to-debug problems with Flickwerk patches.
# What this does is eager-load all the patches in a `to_prepare`
# hook by constantizing them.
# You can override this behavior by setting the environment variable `SOLIDUS_LAZY_LOAD_PATCHES`.
if Spree.solidus_gem_version < Gem::Version.new("4.5.0.a") && !ENV["SOLIDUS_LAZY_LOAD_PATCHES"]
app.reloader.to_prepare do
Flickwerk.patches.each_value { _1.each(&:constantize) }
end
end
end
end
end
end
Expand Down
3 changes: 3 additions & 0 deletions solidus_support.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ Gem::Specification.new do |spec|
spec.executables = files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.add_dependency 'flickwerk', '~> 0.3.4'
spec.add_dependency 'solidus_core', '~> 4.1'

spec.add_development_dependency 'rails'
spec.add_development_dependency 'bundler'
spec.add_development_dependency 'rake'
Expand Down