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

Don't install solidus_auth_devise if it's already in the Gemfile #4748

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
80 changes: 44 additions & 36 deletions core/lib/generators/solidus/install/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,29 +126,19 @@ def configure_application
end
end

def plugin_install_preparation
@plugins_to_be_installed = []
@plugin_generators_to_run = []
end

def install_auth_plugin
with_authentication = options[:with_authentication]
with_authentication.nil? and with_authentication = (options[:auto_accept] || !no?("
def select_auth_plugin
@with_authentication = options[:with_authentication]
@with_authentication.nil? and @with_authentication = (options[:auto_accept] || !no?("
Solidus has a default authentication extension that uses Devise.
You can find more info at https://github.com/solidusio/solidus_auth_devise.

Regardless of what you answer here, it'll be installed if you choose
solidus_starter_frontend as your storefront in a later step.

Would you like to install it? (Y/n)"))

if with_authentication
@plugins_to_be_installed << 'solidus_auth_devise'
@plugin_generators_to_run << 'solidus:auth:install'
end
end

def install_payment_method
def select_payment_method
say_status :warning, set_color(
"Selecting a payment along with `solidus_starter_frontend` might require manual integration.",
:yellow
Expand All @@ -160,12 +150,7 @@ def install_payment_method
You can select a payment method to be included in the installation process.
Please select a payment method name:", limited_to: PAYMENT_METHODS.keys, default: PAYMENT_METHODS.keys.first)

gem_name = PAYMENT_METHODS.fetch(name)

if gem_name
@plugins_to_be_installed << gem_name
@plugin_generators_to_run << "#{gem_name}:install"
end
@payment_method_gem_name = PAYMENT_METHODS.fetch(name)
end

def include_seed_data
Expand All @@ -187,34 +172,37 @@ def create_database
end

def install_frontend
bundler_context = BundlerContext.new

if options[:frontend] == 'none'
support_solidus_frontend_extraction(bundler_context)
support_solidus_frontend_extraction
else
frontend = detect_frontend_to_install(bundler_context)
frontend = detect_frontend_to_install

support_solidus_frontend_extraction(bundler_context) unless frontend == LEGACY_FRONTEND
support_solidus_frontend_extraction unless frontend == LEGACY_FRONTEND

say_status :installing, frontend

InstallFrontend
.new(bundler_context: bundler_context, generator_context: self)
.call(frontend)

# The DEFAULT_FRONTEND installation makes changes to the
# bundle without updating the bundler context. As such, we need to
# reset the bundler context to get the latest dependencies from the
# context.
reset_bundler_context if frontend == DEFAULT_FRONTEND
waiting-for-dev marked this conversation as resolved.
Show resolved Hide resolved
end
end

def run_bundle_install_if_needed_by_plugins
@plugins_to_be_installed.each do |plugin_name|
gem plugin_name
end
def install_authentication_plugin
return unless @with_authentication

BundlerContext.bundle_cleanly { run "bundle install" } if @plugins_to_be_installed.any?
run "spring stop" if defined?(Spring)
install_plugin(plugin_name: 'solidus_auth_devise', plugin_generator_name: 'solidus:auth:install')
end

@plugin_generators_to_run.each do |plugin_generator_name|
generate "#{plugin_generator_name} --skip_migrations=true"
end
def install_payment_method_plugin
return unless @payment_method_gem_name

install_plugin(plugin_name: @payment_method_gem_name, plugin_generator_name: "#{@payment_method_gem_name}:install")
waiting-for-dev marked this conversation as resolved.
Show resolved Hide resolved
end

def run_migrations
Expand Down Expand Up @@ -285,7 +273,7 @@ def complete

private

def detect_frontend_to_install(bundler_context)
def detect_frontend_to_install
ENV['FRONTEND'] ||
options[:frontend] ||
(bundler_context.component_in_gemfile?(:frontend) && LEGACY_FRONTEND) ||
Expand All @@ -299,12 +287,32 @@ def detect_frontend_to_install(bundler_context)
MSG
end

def support_solidus_frontend_extraction(bundler_context)
def support_solidus_frontend_extraction
say_status "break down", "solidus"

SupportSolidusFrontendExtraction.
new(bundler_context: bundler_context).
call
end

def install_plugin(plugin_name:, plugin_generator_name:)
if bundler_context.dependencies[plugin_name]
say_status :skipping, "#{plugin_name} is already in the gemfile"
return
end

gem plugin_name
run_bundle
run "spring stop" if defined?(Spring)
generate "#{plugin_generator_name} --skip_migrations=true"
end

def bundler_context
@bundler_context ||= BundlerContext.new
end

def reset_bundler_context
@bundler_context = nil
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def self.bundle_cleanly(&block)
end

def initialize
@dependencies = Bundler.locked_gems.dependencies
@dependencies = uncached_dependencies
@injector = InjectorWithPathSupport
end

Expand Down Expand Up @@ -92,6 +92,14 @@ def dependency_for_component(component)
def solidus_dependency
@dependencies['solidus']
end

# We want to get the locked gems from `Bundler.definition.locked_gems`
# instead of `Bundler.locked_gems` so that the locked gems won't be
# memoized. See
# https://rubydoc.info/gems/bundler/2.3.22/Bundler.locked_gems.
def uncached_dependencies
Bundler.definition.locked_gems.dependencies
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,11 @@ def call(frontend)

private

def bundle_command(command)
@generator_context.say_status :run, "bundle #{command}"
bundle_path = Gem.bin_path("bundler", "bundle")

BundlerContext.bundle_cleanly do
system(
Gem.ruby,
bundle_path,
*command.shellsplit,
)
end
end

def install_solidus_frontend
unless @bundler_context.component_in_gemfile?(:frontend)
bundle_command 'add solidus_frontend'
# `Rails::Generator::AppBase#bundle_command` is protected so have to `send` it.
# See https://api.rubyonrails.org/v3.2.16/classes/Rails/Generators/AppBase.html#method-i-run_bundle
@generator_context.send :bundle_command, 'add solidus_frontend'
waiting-for-dev marked this conversation as resolved.
Show resolved Hide resolved
end

# Solidus bolt will be handled in the installer as a payment method.
Expand Down